为什么我要巢渲染的成分="#{有些}"在另一个组件时,我想AJAX的更新呢? [英] Why do I need to nest a component with rendered="#{some}" in another component when I want to ajax-update it?

查看:120
本文介绍了为什么我要巢渲染的成分="#{有些}"在另一个组件时,我想AJAX的更新呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我发现接近这几个答案,我发现,足以解决这个问题,我有。但即便如此,我很好奇,了解解决这个运作。让我来说明一个例子:

So I've found a few answers close to this, and I've found enough to fix the problem I had. But even so, I'm curious as to understand the workings around this. Let me illustrate with an example :

我有一个facelet中 .xhtml 页,看起来像这样(shortned)。

I have a facelet .xhtml page that looks like this (shortned).

<h:form id="resultForm">

    <h:panelGroup class="search_form" layout="block">
        <h:inputText id="lastname" value="#{search.lastname}"/>
        <h:commandButton action="#{search.find}" value="Find">
            <f:ajax execute="lastname" render="resultDisplay"/>
        </h:commandButton>
    </h:panelGroup>

    <h:dataTable value="#{search.searchResults}" var="results" id="resultDisplay"
            rendered="#{!empty search.searchResults}">  
        <h:column>
            #{results.field}
        </h:column>
    </h:dataTable>

</h:form>

现在,为了breivity的,我不会发布的所有支持bean code,但我有一些这样的:

Now, for the sake of breivity, I will not post all the backing bean code, but I have something of this sort :

public void find() {
    searchResults = setResults(true);
}

其中,的SearchResult 的ArrayList&LT;对象&GT; 。搜索后,不为空 - 在多个试验检查(可以为空,但不是在测试我做的)

Where searchResults is an ArrayList<Objects>. After a search, it is not null - checked in multiple tests (can be null, but not in the testing I am doing).

现在。这是行不通的。

但是,如果我窝在的dataTable 在另一个,比方说 panelGroup中,它会奏效。

But if I nest the dataTable inside another, let's say panelGroup, it will work.

<h:panelGroup id="resultDisplay">
    <h:dataTable value="#{search.searchResults}" var="results"
        rendered="#{!empty search.searchResults}">  
        <h:column>
            #{results.field}
        </h:column>
    </h:dataTable>
</h:panelGroup>

现在,这种改变让一切工作正常。我会好起来的这个...但我想我正在寻求一点点的理解也是如此。任何了解,为什么我要窝这些组件?我确实失去了一些东西!

Now, this changes allows everything to work fine. I'd be okay with this... but I guess I am seeking a bit of understanding as well. Any insight as to why I have to nest these components? I am surely missing something!

推荐答案

阿贾克斯更新是通过JavaScript语言的客户端执行。所有这一切的JavaScript访问是HTML DOM树。如果JSF没有提供任何组件的HTML输出,那么就没有什么可以被JavaScript后,阿贾克斯更新来获得HTML DOM树。其ID JavaScript不能得到所需的元素。

Ajax updating is performed by JavaScript language in the client side. All which JavaScript has access to is the HTML DOM tree. If JSF does not render any component to the HTML output, then there's nothing in the HTML DOM tree which can be obtained by JavaScript upon Ajax update. JavaScript cannot get the desired element by its ID.

这将只有当您缠绕有条件JSF渲染的成分在其他成分,是的总是的呈现为HTML输出,从而总是的present的工作HTML DOM树,因此总是的被JavaScript获得。参考该封装组件,而不是在AJAX渲染/更新。

It will only work if you wrap the conditionally JSF-rendered component in another component which is always rendered to the HTML output and thus always present in the HTML DOM tree and thus always obtainable by JavaScript. Reference that wrapper component instead during ajax render/update.

  • <一个href="http://balusc.blogspot.com/2011/09/communication-in-jsf-20.html#AjaxRenderingOfContentWhichIsByItselfConditionallyRendered">Communication在JSF2 - 内容的Ajax渲染这是由自身条件呈现

这篇关于为什么我要巢渲染的成分=&QUOT;#{有些}&QUOT;在另一个组件时,我想AJAX的更新呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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