Talib
Talib

Reputation: 1164

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

Upvotes: 5

Views: 2033

Answers (2)

You can solve your problem easily Is's sufficient to put <p:ajax /> between textinput tags

    <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:ajax />
    </p:inputtext>
                    <p:separator />
                    <p:fileUpload onstart="submitVersion()"
                        fileUploadListener="#{remoteDeployment.upload}" update="messages" >          
                    </p:fileUpload>
                </h:form>    

Upvotes: 0

Sajith Herath
Sajith Herath

Reputation: 1052

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>

Upvotes: 1

Related Questions