hellzone
hellzone

Reputation: 5236

How to process primefaces dialog

I have a primefaces dialog and what I want to do is process inputtext before commandbutton action starts. Inside myController.sendToPostBox method, myController.rejectionReason string returns null. Here is my view code.When I remove process attribute, commandbutton doesn't works.

<h:form>
....
<p:dialog id="myPanel"
                  widgetVar="myPanelId"
                  resizable="true"
                  appendToBody="true"
                  draggable="true"
                  height="200"
                  width="300">
            <p:panelGrid id="myPanelGridId" style="width: 250px;" styleClass="panelGridWithoutBorder">
                <p:row>
                    <p:column colspan="2">
                        <p:inputTextarea style="width: 250px;" value="#{myController.rejectionReason}"/>
                    </p:column>
                </p:row>
                <p:row>
                    <p:column>
                        <p:commandButton value="Save"
                                         oncomplete="if (!args.validationFailed) myPanel.hide();"
                                         process="myPanelId"
                                         action="#{myController.sendToPostBox()}"/>
                    </p:column>
                    <p:column>
                        <p:commandButton value="Close" />
                    </p:column>
                </p:row>
            </p:panelGrid>
        </p:dialog>
</h:form>

Upvotes: 0

Views: 2791

Answers (2)

Laura Liparulo
Laura Liparulo

Reputation: 2897

You need something like this:

<h:form id="formDialog">
  <p:commandButton id="basic" value="Basic Dialog" onclick="PF('dlg1').show();"   type="button" />  
</h:form>

<p:dialog id="basicDialog" header="Basic Dialog" widgetVar="dlg1">  

    <h:form id="formUser">

            <h:panelGrid id="grid" columns="2">


                <h:outputLabel value="Username:" />
                <p:inputText id="user" value="#{user.name}" />


                <h:outputLabel value="Password:" />
                <p:inputText id="password"  value="#{user.password}" />



                <h:commandButton value="Login" id="btn" process="@formUser" actionListener="#{user.login}"   />

          </h:panelGrid>

     </h:form>

</p:dialog>  

"login" in the actionListener tag is a method in the User(bean) class, that needs the @ManagedBean annotations.

Upvotes: 0

Daniel
Daniel

Reputation: 37051

Just place the <h:form> inside the dialog (instead dialog inside the <h:form>)

Explanation:

When you use appendToBody="true" you dialog is being transferred outside of the form that wraps it to the body of the generated html , and since there is no form inside the dialog you can't really submit it.

Also take a look at this thread: Proper Construct for Primefaces Dialog

Upvotes: 2

Related Questions