【问题标题】:Update issue when select p:selectOneMenu from primefaces从 primefaces 中选择 p:selectOneMenu 时更新问题
【发布时间】:2015-05-16 17:43:02
【问题描述】:

我正在使用 primefaces 开发一个项目。

代码:

<p:panel id="accountPolicyRichPanel">
    <h:panelGrid id="outputPanelGrid">

         <h:outputText value=""...../>
         <p:inputText id="InputTextId"/>

        <p:selectOneMenu id="suspendTypeId" value="...">
             <f:selectItems value="#{AccountPolicy.suspendTypeItemList}"/>
             <p:ajax listener="#AccountPolicy.suspendTypeComboboxAction}"event="change" update="outputPanelGrid"/>
        </p:selectOneMenu>
   </panelGrid>

        <p:commandButton id="saveButtonId" value="..." action="..."
              update="accountPolicyRichPanel" />

</p:panel>

我的问题是,当我选择 &lt;p:selectOneMenu&gt; 时,我更新了 &lt;h:panelGrid id="outputPanelGrid"&gt;,而我之前在 &lt;p:inputText id="InputTextId"/&gt; 中输入的值被删除了。

如何更新&lt;h:panelGrid id="outputPanelGrid"&gt; 或&lt;p:panel&gt; 而不删除p:inputText 中先前输入的值。

【问题讨论】:

    标签: jsf primefaces


    【解决方案1】:

    您必须从更新中排除 &lt;p:inputText id="InputTextId"/&gt; 或添加此输入以执行,因为 Ajax 默认只处理当前组件,如 execute="@this"。

    例如执行: &lt;p:ajax process="outputPanelGrid" listener="#{AccountPolicy.suspendTypeComboboxAction}"event="change" update="outputPanelGrid"/&gt;

    【讨论】:

    • 你错了,PrimeFaces中的process属性默认是@Form,见stackoverflow.com/questions/25339056/…。 OP至少应该做的是使用value="#{bean.someField}"
    • 你是对的, 默认执行设置为@this。感谢指正
    【解决方案2】:

    您至少应该在 inputText 上放置一个value="#{bean.someField}"。如果不存在,您输入的值将在 ajax 提交和更新过程中丢失,因为它无法存储在服务器上。 这都是基本的 jsf,与 PF 无关。

    您也许可以优化表单提交(哪些字段已提交,哪些未提交,哪些已处理,哪些未处理)但那是:另一回事

    另请参阅

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-31
      • 1970-01-01
      • 2014-04-19
      • 2013-05-22
      • 2011-10-06
      相关资源
      最近更新 更多