小城,风带香

好好学习,天天向上

jsf ajax(a4j)刷新页面或是提交不刷新组件

春天的熊:

页面的技术使用的是jsf,页面组成:左侧一个折叠菜单,右侧一个列表。

要求:点击菜单,右侧列表局部刷新。

 右侧菜单是静态页面标签+js写的。点击的时候,调用一个隐藏的<h:commandButton></h:commandButton>,button里面写上<a4j:support></a4j:support>,如下:

     <h:commandButtonvalue="" id="techlistRefresh" style="display:none;">
                <a4j:support action="#{techShowManageBean.findTechListByCateId}" event="onclick" immediate="false" reRender="tech_list_tb, tech_list_blank, tech_list_html" oncomplete="referscroll();" >
                </a4j:support>
            </h:commandButton>
调用该button的js代码:document.getElementById("form:techlistRefresh").click();

这样调用,页面刷新,但是这样刷新的是整个页面,你在页面onload的时候加个alert()就知道了,这样就不是我要的效果了。原因就是,该button产生的还是一个form的input的提交。

我把button改成了outputtext,如下:

       <h:outputText value="" id="techlistRefresh" style="display:none;">
                <a4j:support action="#{techShowManageBean.findTechListByCateId}" event="onclick" immediate="false" reRender="tech_list_tb, tech_list_blank, tech_list_html" oncomplete="referscroll();" >
                </a4j:support>
            </h:outputText>
该异步调用可以被触发,既我后台的techShowManageBean.findTechListByCateId已经成功调用,并且已经重新set了我要的组件。但是页面没有刷新城最新的数据。

 <a4j:support >已经 reRender="tech_list_tb, tech_list_blank, tech_list_html" 了我要的组件的ID,还是没有效果,修改如下,添加

<a4j:outputPanel id="test" layout="block" ajaxRendered="true">********</<a4j:outputPanel >

用这个标签把要刷新的元素包裹起来,形成一个作用域,有人叫他围堵。这个标签的参数如下:
            

styleClass

和HTML的class属性一样.

title

该组件产生的标记元素的提示文字(当鼠标移动到该组件上面出现的提示文字)

lang

产生该组件标记所使用的语言

layout

HTML layout用于产生 markup. 可能的取值是:   "block" 产生一个 HTML <div> 元素, "inline" 产生一个 HTML   <span> 元素, 和   "none"不产生 HTML 元素. 对于none 当子元素的rendered属性被设置为false时 这里有个小例外 ,这是创建一个具有相同id的空 <span> 元素 作为子元素,用来当作一个用于后序处理的占位符 

keepTransient

指定所有子组件为non-transient的标记.如果为true,所有的子组件将被设置为non-transient,并且在以保存的组件树中(keep in saved   components tree). For output in self-renderer region all content ( By   default, all content in <f:verbatim> tags and non-jsf elements in   facelets, marked as transient - since, self-rendered ajax regions don't plain   output for ajax processing ).

ajaxRendered

Defines, whether the content of this   component must be (or not) included in AJAX response created by parent AJAX Container,   even if it is not forced by reRender list of ajax action. Ignored if   component marked to output by Ajax action. default false

style

HTML: 应用在该组件上的CSS.

rendered

如果为false,该组件将不会被显示.

binding

组件绑定.

dir

文本方向.

id

每个组件都应该有个唯一的id. 如果没有指定的话,将会自动产生.

        


 这样再去尝试一下,嘿嘿,OK.

评论

热度(1)