triplus
triplus

Reputation: 91

JSF How to pass the value of a CommandButton in bean

I would like to know if I can get the value of the commandButton to the Bean? Bean Name is "fileDownloadView". But the value is always null. The value in the bean should be stored in the cbtValue. Thanks in advance.

Example code:

    <ui:repeat value="#{data.linkListen}" var="linkListe" varStatus="status">
                <h:commandButton value="#{linkListe.name}" ajax="false" actionListener="#{fileDownloadView.prepare()}">
                   <p:fileDownload value="#{fileDownloadView.filedownload}"/>
                </h:commandButton>
    </ui:repeat>

I tried to use:

Bean:

private String cbtValue

public void prepare() throws Exception{
    flpath = path + cbtValue;
    File file = new File(flpath );
    InputStream input = new FileInputStream(file);
    String mimeType = Files.probeContentType(Paths.get(flpath ));
    setFiledownload(new DefaultStreamedContent(input, mimeType, file.getName()));
}

//getter, setter Methods

Upvotes: 0

Views: 29

Answers (0)

Related Questions