Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Get video path

AD-Engineer
Level 4
Level 4

Hi,

I am trying to create a Video Component, that will look like Image component(just drag and drop the asset).

This is how I build the dialog:

<video
                                                jcr:primaryType="nt:unstructured"
                                                sling:resourceType="cq/gui/components/authoring/dialog/fileupload"
                                                autoStart="{Boolean}false"
                                                class="cq-droptarget"
                                                fieldLabel="Image asset"
                                                fileNameParameter="./fileName"
                                                fileReferenceParameter="./fileReference"
                                                mimeTypes="[video/quicktime]"
                                                multiple="{Boolean}false"
                                                name="./video"
                                                title="Upload Image Asset"
                                                uploadUrl="${suffix.path}"
                                                useHTML5="{Boolean}true"/>

But, I can not return the path from the java model.

1 Accepted Solution
lukaszm
Correct answer by
Level 7
Level 7

@AD-EngineerCan you try this:

Remove ValueMapValue annotation and add below method

@PostConstruct
protected void initModel() {
   video = componentResource.getValueMap().get("fileReference", String.class);
}

View solution in original post

11 Replies
Kiran_Vedantam
Community Advisor
Community Advisor

Hi @AD-Engineer 

 

Can you try the dailog field as a path field rather than the fileupload?

 

Thanks,
Kiran Vedantam

bangar50
Level 7
Level 7

Hi @AD-Engineer ,

           You need to used filereference in sling model to access the path of video.

 

Regards,

Sanjay

AD-Engineer
Level 4
Level 4

@bangar50 yes but how?

this is my method:

 public String getVideo() {
        return video;
    }

It is not returning anything

lukaszm
Level 7
Level 7

Hi @AD-Engineer, could you please share part of code responsible for video variable initialization,. How video value is set in you sling model?

lukaszm
Level 7
Level 7

@AD-Engineer 

Ok, so assuming that video variable represents path to asset, I would suggest to do following change in your code

    @ValueMapValue(name = "fileReference")
    private String video;

Current behavior is correct because video is not representing any specific property in the repository it's defining node name.

AD-Engineer
Level 4
Level 4

@lukaszm thanks!

Tried it, but still not working. It does not return anything.

AD-Engineer
Level 4
Level 4

@lukaszm 

@Model(
        adaptables = {SlingHttpServletRequest.class},
        adapters = {VideoComp.class},
        resourceType = {ResourceType.Constants.VIDEO_COMP},
        defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL
)

@Slf4j
public class VideoCompImpl implements VideoComp {

    @Inject
    Resource componentResource;
    
    @OSGiService
    private ModelFactory modelFactory;

    @Self
    private SlingHttpServletRequest request;

    @ValueMapValue(name = "fileReference") 
    private String video;


    @Override
    public boolean isEmpty() {
        return false;
    }


    @Override
    public String getVideo() {
        return video;
    }


    
}
lukaszm
Correct answer by
Level 7
Level 7

@AD-EngineerCan you try this:

Remove ValueMapValue annotation and add below method

@PostConstruct
protected void initModel() {
   video = componentResource.getValueMap().get("fileReference", String.class);
}

View solution in original post