简体   繁体   English

在表单外渲染组件

[英]Render component outside the form

Requirement is to render a component outside the form after an ajax call. 要求是在ajax调用之后在表单外部呈现组件。 I have tried with the following code but the text was not being rendered. 我尝试使用以下代码,但未呈现文本。

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

I assume that you've changed the default naming container separator character from : to _ , otherwise you should have used :panel1 instead of _panel1 ) 我假设您已将默认命名容器分隔符从:更改为_ ,否则应使用:panel1而不是_panel1

You're trying to ajax-render a component which is by itself conditionally rendered by the server side. 您正在尝试Ajax渲染组件,该组件本身是由服务器端有条件地渲染的。 This will not work when the component is not rendered in first place. 如果不首先呈现组件,则此功能将不起作用。 JS won't be able to locate the desired HTML element to update after the ajax response arrives. ajax响应到达后,JS将无法找到要更新的HTML元素。 You need to wrap it in another component which is always rendered to the HTML output and set the rendered condition on the wrapped component. 您需要将其包装在始终呈现到HTML输出的另一个组件中,并在被包装的组件上设置rendered条件。

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

See also: 也可以看看:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM