在表单外部渲染组件

时间:2012-02-01 13:25:29

标签: ajax jsf-2

要求是在ajax调用之后在表单外部呈现组件。我尝试使用以下代码,但文本未呈现。

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ads="http://java.sun.com/jsf/composite/components">
   <ui:include src="secondfile"/>
   <h:panelGroup id="panel1" rendered="#{bean.access}">
      Some text
    </h:panelGroup>
</ui:composition>

Secondfile:

   <ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ads="http://java.sun.com/jsf/composite/components">
         <f:ajax render="@form _panel1">
    <h:selectOneRadio id="access" value="#{beanTO.access}">
       <f:selectItem itemValue="true" itemLabel="yes"/>
           <f:selectItem itemValue="true" itemLabel="yes"/> 
        </h:selectOneRadio>
        </f:ajax>
    </ui:composition>

1 个答案:

答案 0 :(得分:1)

我假设您已将默认命名容器分隔符从:更改为_,否则您应该使用:panel1而不是_panel1

您正在尝试ajax渲染一个组件,该组件本身由服务器端有条件地呈现。当组件未首先呈现时,这将不起作用。在ajax响应到达后,JS将无法找到要更新的所需HTML元素。您需要将其包装在另一个始终呈现给HTML输出的组件中,并在包装​​组件上设置rendered条件。

<h:panelGroup id="panel1">
    <h:panelGroup rendered="#{bean.access}">
        Some text
    </h:panelGroup>
</h:panelGroup>

另见: