0
votes

I have 2 dialogs on a xhtml page:

<p:dialog width="400" id="dialog1" header="Download" widgetVar="dialog1">
    <h:outputText value="Field1"/>
    <h:inputText  value="#{backingBean.field1}"/>
    <br/>
    <h:outputText value="Field2"/>
    <h:inputText value="#{backingBean.field2}"/>
    <br/>
    <p:commandButton value="Download" ajax="false" onsuccess="PF('diaglog1').hide();">
        <p:fileDownload value="#{backingBean.file}"/>
    </p:commandButton>
</p:dialog>
<p:dialog width="400" id="dialog2" header="Send" widgetVar="dialog2">
    <h:outputText value="Field1"/>
    <p:inputText  value="#{backingBean.field1}"/>
    <br/>
    <h:outputText value="Field2"/>
    <h:inputText value="#{backingBean.field2}">
        <p:ajax update="somePanel"/>
    </h:inputText>
    <br/>
    <h:outputText value="Recipient"/>
    <h:panelGroup id="somePanel">
        <p:selectOneMenu style="width: 100%;" var="recipient">
            <f:selectItems value="#{backingBean.someList}"/>
        </p:selectOneMenu>
    </h:panelGroup>
    <br/>
    <p:commandButton value="Send" actionListener="#{backingBean.sendSomething}"     onsuccess="PF('dialog2').hide();">
        <f:attribute name="item" value="#{recipient}"/>
    </p:commandButton>
</p:dialog>

They have different functionality but are on the same page and using the same backing bean. Only one dialog can appear at a time. The problem is when I input some value into the first dialog and press 'Download', it will update the field1 and field2 of the backing bean to the value that I want, but after that the second dialog also updates it to its value, which causes the first one to download the wrong file. If I remove the second dialog, the first will behave correctly.

How do I stop the second dialog from updating the values?

1
It's recommended to take a step back and learn basic HTML before diving into JSF. - BalusC

1 Answers

2
votes

I guess you are keeping both dialogs in one single h:form component.
Then obviously submit in one dialog will submit fields in both dialogs coz, they are in same form.

  • Don't keep p:dialog inside a h:form, instead use h:form inside dialog.
  • You can use multiple h:form s in a page there is no harm in that, but should not use one h:form in another.
  • Decide how many forms you can use, based on your design and functionality, In your case you can use 2 h:forms each one inside both dialogs.