p:commandButton在p:dialog中不起作用

时间:2013-07-01 16:37:22

标签: java jsf-2 primefaces tomcat7

我的xhtml页面有ui:repeat我需要打开一个对话框,该对话框会将消息发送给点击该按钮的用户。为此,我尝试了以下两种方法:

1。)将p:对话框移动到单独的h:表单中,如下所示:

<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>  

我正在使用以下按钮调用此对话框,该按钮位于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>

此方法的问题是 p:commandButton 未在对话框内触发。另外奇怪的是,这段代码在2天后工作,没有任何改变,它自动停止工作:)。

2。)p:对话框的形式与ui相同:重复: -

<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>

这种方法的问题是p:commandButton现在正在工作,但它没有使用commandLink按钮单击的行的数据进行更新。所以p:对话框的commandButton始终具有dataList第一行的参数值。

请建议..

1 个答案:

答案 0 :(得分:0)

尝试另一种方法(它对我有用)

<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>