1
votes

My xhtml page have ui:repeat from which I need to open dialog box that will send the message to the user on which the button clicked. For this I've tried below two approach:

1.) Move the p:dialog into the separate h:form like below:

<p:dialog id="dialog" showHeader="true" header="Write your message" closable="true" widgetVar="dlg" resizable="false" draggable="true" modal="true" styleClass="job_model_popup" height="300">  
                    <h:form id="dialogForm">
                        <p:panel id="messageFormPanel">   
                            <br />
                            <h:inputTextarea label="Message" styleClass="input_text_field" value="#{MyBean.messageBody}" rows="10" required="true" />
                            <br />
                            <br />
                            <p:commandButton  actionListener="#{MyBean.myMethod}" value="Send" styleClass="btn" update=":parentForm:growl" oncomplete="handleRequest(xhr, status, args);">
                                <f:param name="_param1" value="#{list['param1Id']}" />
                                <f:param name="_param2" value="#{list['param2Id']}" />                                                                                            
                            </p:commandButton> 
                        </p:panel>
                    </h:form>
                </p:dialog>  

I am invoking this dialog box with below button that is in ui:repeat:

<h:form id="parentForm">
                    <ui:repeat id="dataList" var="list" varStatus="status" value="#{MyBean.dataList}">

                        <p:commandLink value="Send Msg" oncomplete="dlg.show();" update=":dialogForm">
                            <f:param value="#{list}" name="list" />
                        </p:commandLink >

                    </ui:repeat>
                </h:form>

The problem with this approach is that the p:commandButton not firing inside the dialog box. Also the strange thing is that this code was working 2 days back and without any change it stopped working automatically :).

2.) p:dialog is in same form as ui:repeat :-

<h:form id="parentForm">
                    <ui:repeat id="dataList" var="list" varStatus="status" value="#{MyBean.dataList}">

                        <p:commandLink value="Send Msg" oncomplete="dlg.show();" update=":parentForm:messageFormPanel">
                            <f:param value="#{list}" name="list" />
                        </p:commandLink >

                    </ui:repeat>

                    <p:dialog id="dialog" showHeader="true" header="Write your message" closable="true" widgetVar="dlg" resizable="false" draggable="true" modal="true" styleClass="job_model_popup" height="300">                          
                        <p:panel id="messageFormPanel">   
                            <br />
                            <h:inputTextarea label="Message" styleClass="input_text_field" value="#{MyBean.messageBody}" rows="10" required="true" />
                            <br />
                            <br />
                            <p:commandButton  actionListener="#{MyBean.myMethod}" value="Send" styleClass="btn" update=":parentForm:growl" oncomplete="handleRequest(xhr, status, args);">
                                <f:param name="_param1" value="#{list['param1Id']}" />
                                <f:param name="_param2" value="#{list['param2Id']}" />                                                                                            
                            </p:commandButton> 
                        </p:panel>                       
                    </p:dialog> 
                </h:form>

The problem with this approach is that the p:commandButton is now working but it is not updated with data of row from which the commandLink button clicked. So p:commandButton of p:dialog always have the parameter value from the first row of the dataList.

Please suggest..

1
Additional info: MyBean is ViewScoped my method declartion is like : public void myMethod(ActionEvent event) { } - Sundeep Malik

1 Answers

0
votes

Try another approch (it worked for me)

<h:form id="dialogForm">    
<p:dialog id="dialog" showHeader="true" header="Write your message" closable="true" widgetVar="dlg" resizable="false" draggable="true" modal="true" styleClass="job_model_popup" height="300">  

                    <p:panel id="messageFormPanel">   
                        <br />
                        <h:inputTextarea label="Message" styleClass="input_text_field" value="#{MyBean.messageBody}" rows="10" required="true" />
                        <br />
                        <br />
                        <p:commandButton  actionListener="#{MyBean.myMethod}" value="Send" styleClass="btn" update=":parentForm:growl" oncomplete="handleRequest(xhr, status, args);">
                            <f:param name="_param1" value="#{list['param1Id']}" />
                            <f:param name="_param2" value="#{list['param2Id']}" />                                                                                            
                        </p:commandButton> 
                    </p:panel>

</p:dialog>  
</h:form>