简体   繁体   中英

Primefaces: InputText fields VALUES not updating after FileUpload

[SHORT VERSION EXPLANATION] : I'm having problems updating some inputText values after a file upload. It's not working if ANY other inputText element has been filled before the upload.

[LONG VERSION] : I need help understanding the reason why after uploading a file that changes the inputText fields values (in the managedBean), the inputText fields don't assume their new values after their element has been updated.

The page is made of a Form, containing 2 fragments:

  • The 1st one, has 3 inputText fields - inputText_A , inputText_B and inputText_C ;
  • The 2nd one contains only a FileUpload element. The uploaded file, contains the values used to fill the inputText fields mentioned above;

What I found:

  1. FileUpload successfully changes updates the managedbeans variables values (category.setName() and category.setValue() is triggered after uploading the file).
  2. IF I upload the file BEFORE I type anything in inputText_A, everything works as expected - the inputText_B and inputText_C values are updated
  3. IF I type anything in inputText_A and then upload the file, then the inputText_B and inputText_C values are not updated.
  4. In any of those cases the update="fileUploadField inputTextFields" is working (getters are called and the fields are disabled after the file has been uploaded)

NOTE: The inputText_B and _C need to be inputTexts, because the user should be allowed to input the info manually in case he doesn't have the necessary file.

fields.xhtml

<p:fieldset id="inputTextFields" toggleable="true" toggleSpeed="150"
        <p:inputText id="inputText_A"
            value="#{uploaded.category.serial}"
            disabled="#{details.disabled()}"
            required="true"
            requiredMessage="#{msg['uploaded.category.serial.empty']}"
            onblur="deactivateCategoryListOrButton(); setChanged()">
        </p:inputText>

        <p:inputTextarea id="inputText_B"
            value="#{uploaded.category.name}"
            disabled="#{details.disabled()}"
            required="true"
            requiredMessage="#{msg['uploaded.category.name.empty']}"
            autoResize="false" rows="4"
            valueChangeListener="#{uploaded.fieldListener}"
            onblur="deactivateCategoryListOrButton(); setChanged()">
        </p:inputTextarea>

        <p:inputTextarea id="inputText_C"
            value="#{uploaded.category.value}"
            disabled="#{details.disabled()}"
            required="true"
            requiredMessage="#{msg['uploaded.category.name.empty']}"
            valueChangeListener="#{uploaded.fieldListener}"
            onblur="deactivateCategoryListOrButton(); setChanged()">
        </p:inputText>
</p:fieldset>

uploader.xhtml

<p:fieldset id="fileUploadField" toggleable="true" toggleSpeed="150"
    <h:panelGroup>
        <p:fileUpload id="#{details.fileUploadCompIdRule}"
            fileUploadListener="#{details.handleFileUpload}"
            mode="advanced" allowTypes="/(\.|\/)(xml)$/"
            label="#{msg['uploaded.category.button.browse']}"
            multiple="false" auto="true"
            update="fileUploadField inputTextFields"
            disabled="#{details.categoryActive()}"
            oncomplete="deactivateCategoryListOrButton(); setChanged()" />
    </h:panelGroup>
</p:fieldset>

Thanks in advance! RMG

UPDATE:

The problem persists but I've created in the form , after the fragment , 2 inputHidden fields with same value="#{uploaded.category.Name}" . The inputHidden values are updated with the values of the uploaded file (as it was supposed to happen in the inputText fields too).

Any idea why that's working in the inputHidden but not in the inputText fields?

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM