【问题标题】:Ajax, conditional rendering and backing beansAjax、条件渲染和支持 bean
【发布时间】:2011-07-25 15:33:33
【问题描述】:

I am trying to display a page where the user, by the appropriate selection using a radio button, sees either a textbox or a combo box.这相对容易,我通过以下代码设法做到了:

<h:selectOneRadio id="selection" value="#{inputMethod.choice}">
  <f:selectItem itemValue="#{inputMethod.TEXT}" itemLabel="textbox"/>
  <f:selectItem itemValue="#{inputMethod.COMBO}" itemLabel="combobox" />
  <f:ajax event="click" execute="@this" render="@form" />
 </h:selectOneRadio>
<h:panelGroup id="Textbox" rendered="#{inputMethod.choice==inputMethod.TEXT}">
  <h:outputLabel>Textbox:</h:outputLabel>
  <h:inputText value="#{myBean.somevalue}" />
</h:panelGroup>
<h:panelGroup id="Combobox" rendered="#{inputMethod.choice==inputMethod.COMBO}"> 
  <h:outputLabel Combobox:/>
  <h:selectManyListbox id="CommunityListbox" value="#{myBean.choices}">
    <f:selectItems value="#{myBean.selections}" var="u" itemValue="#{u.id}" itemLabel="#{u.name}"/>
   </h:selectManyListbox>
 </h:panelGroup>

我遇到的问题是组合框的设置器从未被调用。 事实上,setter 只为默认渲染的组件调用(在这种情况下,只要inputMethod.choice==inputMethod.TEXT)。如果我删除条件渲染,所有设置器都会按预期调用。

任何想法或答案将不胜感激!

PS:我正在使用 jsf2.0、Glassfish 3.1、Netbeans 7.0(以防万一这很重要)

【问题讨论】:

    标签: ajax jsf-2


    【解决方案1】:

    您需要确保#{inputMethod.choice} 在处理表单提交的请求期间的评估结果与在显示表单的请求期间的评估结果完全相同。最简单的方法是将 bean 放入视图范围或将初始化逻辑移动到请求范围 bean 的 (post) 构造函数中。

    【讨论】:

      猜你喜欢
      • 2018-04-04
      • 1970-01-01
      • 1970-01-01
      • 2015-10-06
      • 2011-01-20
      • 1970-01-01
      • 1970-01-01
      • 2013-09-16
      • 2014-01-17
      相关资源
      最近更新 更多