Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing input text value with file upload in primefaces

I have the requirement that I have to pass the value of inputText to backing bean which will contain the version of the file along with the file upload. I have been trying to achieve it using remote command but not working.

Below is my code:

 <h:form enctype="multipart/form-data" id="uploadForm">
                        <p:growl id="messages" showDetail="true" />
                        <p:outputLabel for="vers" value="File Version:" />
                        <p:inputText id="vers" name="vers"
                            value="#{remoteDeployment.uploadedVersion}" placeholder="1.x.x.x"
                            maxlength="17" required="true"
                            requiredMessage="Version is required." />
                        <p:separator />
                        <p:fileUpload onstart="submitVersion()"
                            fileUploadListener="#{remoteDeployment.upload}" update="messages" >
                            <f:attribute name="terminalSettings" value="#{as}" />
                        </p:fileUpload>


                        <p:remoteCommand name="submitVersion" process="@this vers" />

                    </h:form>

String in backing bean for input text :

@ViewScoped
    private String uploadedVersion;
    public String getUploadedVersion() {
        return uploadedVersion;
    }

    public void setUploadedVersion(String uploadedVersion) {
        this.uploade

please help and also let me know if there is any other way of doing it.

Thanks

like image 854
Talib Avatar asked Nov 07 '22 06:11

Talib


1 Answers

This worked for me.

<h:form enctype="multipart/form-data" id="uploadForm">
    <p:growl id="messages" showDetail="true"/>
    <p:outputLabel for="vers" value="File Version:"/>
    <p:inputText id="vers" name="vers"
                 value="#{remoteDeployment.uploadedVersion}" placeholder="1.x.x.x"
                 maxlength="17" required="true"
                 requiredMessage="Version is required."/>
    <p:separator/>
    <p:fileUpload fileUploadListener="#{remoteDeployment.upload}" update="messages">
        <f:attribute name="terminalSettings" value="#{as}" oncomplete="$('#uploadForm').submit()"/>
    </p:fileUpload>

</h:form>
like image 174
Sajith Herath Avatar answered Nov 15 '22 09:11

Sajith Herath