Passing input text value with file upload in primefaces

好久不见. 提交于 2019-12-13 13:13:04

问题


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


回答1:


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>


来源:https://stackoverflow.com/questions/50504313/passing-input-text-value-with-file-upload-in-primefaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!