a4j:ajax不会渲染h:panelgrid [英] a4j:ajax won't render h:panelgrid

查看:66
本文介绍了a4j:ajax不会渲染h:panelgrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是代码:

<h:panelGrid columns="3" style="margin-left: auto; margin-right:auto;">
    <f:facet name="header">
        <rich:column colspan="2">
            <h:outputText value="Ingrese datos del padre" />
        </rich:column>
    </f:facet>

    <label for="padreRut">RUT</label>
    <h:inputText id="padreRut" value="#{IngresoAlumno.padre.per_Rut}">
        <a4j:ajax event="keyup" render="formPadre" immediate="true" />
        <f:validateLongRange minimum="0" />
    </h:inputText>
    <rich:message for="padreRut" ajaxRendered="true" />
</h:panelGrid>

<h:panelGrid id="formPadre" columns="3" style="margin-left: auto; margin-right:auto;" rendered="#{IngresoAlumno.padre.per_Rut gt 0}">
//...From here on there are form elements

问题是当我触发事件时,第二个panelGrid不会渲染.我在这里做错什么了吗?谢谢你.

The problem is that when I trigger the event, the second panelGrid won't render. Am I doing something wrong here? Thank you beforehand.

推荐答案

ajax魔术是由运行在客户端并在HTML DOM树上运行的JavaScript代码执行的.通过指定render="someId",您基本上是在告诉JavaScript将给定ID的JSF组件的HTML表示形式替换为检索到的ajax响应中的新HTML表示形式.

The ajax magic is executed by JavaScript code which runs in the client side and works on the HTML DOM tree. With specifying render="someId", you're basically telling JavaScript to replace the HTML representation of the JSF component with the given ID with the new HTML representation in the retrieved ajax response.

但是,如果最初由JSF呈现具有给定ID的JSF组件的HTML表示 not ,则JavaScript无法在HTML DOM树中找到任何要替换的内容.

However, if the HTML representation of the JSF component with the given ID is not rendered by JSF in first place, then JavaScript can't find anything in the HTML DOM tree to replace.

这就是您的情况.您应该改为指定始终呈现的JSF组件的ID,以便JavaScript可以找到它,并在必要时在HTML DOM树中对其进行更新.您可以为此使用<h:panelGroup>.

This is what is happening in your case. You should instead specify the ID of a JSF component which is always rendered, so that JavaScript can find it and update it in the HTML DOM tree whenever necessary. You could use a <h:panelGroup> for this.

<a4j:ajax ... render="formPadre" />
...
<h:panelGroup id="formPadre">
    <h:panelGrid ... rendered="#{IngresoAlumno.padre.per_Rut gt 0}">
        ...

另请参见:

  • JSF 2.0中的通信-内容的Ajax呈现是有条件地呈现的
  • See also:

    • Communication in JSF 2.0 - Ajax rendering of content which is by itself conditionally rendered
    • 这篇关于a4j:ajax不会渲染h:panelgrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆