是否有可能更新非JSF组件(纯HTML)与JSF AJAX? [英] Is it possible to update non-JSF components (plain HTML) with JSF ajax?

查看:169
本文介绍了是否有可能更新非JSF组件(纯HTML)与JSF AJAX?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以更新部分我的网页是不是JSF组件?

例如,我可以更新一个普通的HTML < D​​IV> 或者我需要来包装,在一个JSF组件

解决方案
  

是否可以更新部分我的网页是不是JSF组件?

没有。要被更新的组分必须是可用的由<一href="http://docs.oracle.com/javaee/7/api/javax/faces/component/UIComponentBase.html#findComponent-java.lang.String-"相对=nofollow> UIViewRoot#findComponent() ,使JSF可以找到他们,引用连接$ C $()的调用就可以了,捕捉生成的HTML输出,并传回它在Ajax响应,使JavaScript可以用它更新HTML DOM树。纯HTML元素不会再presented为实 UIComponent 情况下,在JSF组件树,所以JSF已经无法找到他们排在首位。


  

例如,我可以更新一个普通的HTML &LT; D​​IV&GT; 或者我需要来包装,在一个JSF组件

您需要把它包像℃的JSF组件; H:panelGroup中&GT; 。但是,您可以只使用&LT; H:panelGroup中布局=块&GT; 来重新present一个真正的&LT; D​​IV&GT; 在JSF中。这样,您就不需要换行&LT; D​​IV&GT; 在另一个JSF组件

还有然而一个角落的情况下,以防复合材料部件中的。您可以使用下面的方法有哪些的一个HTML元素是的更新阿贾克斯。

 &LT; CC:实施&GT;
    &所述;跨度的id =#{cc.clientId}&GT;
        ...
    &LT; / SPAN&GT;
&LT; / CC:实施&GT;
 

这是这种方法的工作原理的解释是,因为即使复合组件相同的没有的渲染自己的HTML输出,它的本身可通过 UIViewRoot#findComponent()

参见:

  • <一个href="http://stackoverflow.com/questions/8634156/how-to-find-out-client-id-of-component-for-ajax-update-render-cannot-find-compo">How找出成分为Ajax更新客户端ID /渲染?无法找到EX pression&QUOT组成部分;富&QUOT;酒吧&QUOT;从&QUOT引用
  • <一个href="http://stackoverflow.com/questions/9010734/why-do-i-need-to-nest-a-component-with-rendered-some-in-another-component-w">Why我需要巢渲染的成分=&QUOT;#{有些}&QUOT;在另一个组件时,我想AJAX的更新呢?
  • <一个href="http://stackoverflow.com/questions/18379689/rerendering-composite-component-by-ajax/">Rerendering阿贾克斯
  • 复合组件

Is it possible to update parts of my page that are not JSF components?

For example, can I update a plain HTML <div> or do I need to wrap that in a JSF component?

解决方案

Is it possible to update parts of my page that are not JSF components?

No. The to-be-updated component has to be available by UIViewRoot#findComponent(), so that JSF can find them, invoke encodeAll() on it, capture the generated HTML output and pass back it in the ajax response so that JavaScript can update the HTML DOM tree with it. Plain HTML elements are not represented as real UIComponent instances in the JSF component tree, so JSF already cannot locate them in first place.


For example, can I update a plain HTML <div> or do I need to wrap that in a JSF component?

You need to wrap it in a JSF component like <h:panelGroup>. You can however just use <h:panelGroup layout="block"> to represent a real <div> in JSF. This way you don't need to wrap the <div> in another JSF component.

There's however one corner case in case of composite components. You can use the following approach to have a HTML element which is updateable by ajax.

<cc:implementation>
    <span id="#{cc.clientId}">
        ...
    </span>
</cc:implementation>

The explanation that this approach works is because even though the composite component does not render itself to the HTML output, it is by itself available by UIViewRoot#findComponent().

See also:

这篇关于是否有可能更新非JSF组件(纯HTML)与JSF AJAX?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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