【问题标题】:p:commandButton not working inside p:dialogp:commandButton 在 p:dialog 中不起作用
【发布时间】:2013-06-28 20:51:30
【问题描述】:

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

1.) 将 p:dialog 移动到单独的 h:form 中,如下所示:

<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: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=":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:dialog 的 p:commandButton 始终具有 dataList 第一行的参数值。

请建议..

【问题讨论】:

  • 附加信息:MyBean 是 ViewScoped 我的方法声明如下:public void myMethod(ActionEvent event) { }

标签: java jsf-2 primefaces tomcat7


【解决方案1】:

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

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

【讨论】:

  • 感谢@jimha 的回复,我已经尝试过了(p:dialog inside h:form),但它也不起作用。奇怪的是,这种方法对我有用,而且它现在使用我的其他代码在生产服务器上工作,但现在在本地服务器上它自动停止工作。
  • 你需要添加我发布的代码,在委托人之外
    你在这样做吗? (因为嵌套表单会产生一些问题)
  • 是的,我没有嵌套表单。两个 h:form 都是页面上的单独表单。正如我之前所说,我也尝试过您的代码,但没有运气:(。无论如何谢谢..
猜你喜欢
  • 2013-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-17
相关资源
最近更新 更多