【问题标题】:Render component outside the form在表单外渲染组件
【发布时间】:2012-02-01 13:25:29
【问题描述】:

要求是在 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>

第二个文件:

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

【问题讨论】:

    标签: ajax jsf-2


    【解决方案1】:

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

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

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

    另见:

    【讨论】:

    • 感谢您的快速回复。它按预期工作。
    猜你喜欢
    • 1970-01-01
    • 2011-01-20
    • 1970-01-01
    • 2015-03-10
    • 2019-01-31
    • 2012-12-14
    • 1970-01-01
    • 2020-11-24
    • 1970-01-01
    相关资源
    最近更新 更多