您可以更新H:outputLabel从AP:阿贾克斯监听器? [英] Can you update an h:outputLabel from a p:ajax listener?

查看:151
本文介绍了您可以更新H:outputLabel从AP:阿贾克斯监听器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用AP:AJAX标签,然后在监听器,我设置了一个名为periodRendered的价值。然后我试图更新H:outputLabel标签通过从p更新:AJAX标签。它不更新ajaxily,我想这是因为primefaces AJAX标签不能更新标准JSF outputLabel标签。

是我的假设是正确的,是有,我应该使用,而不是h的更恰当的标签:outputLabel

 < H:outputLabel为=addProgramToVALUE =添加程序为/>
<电话号码:selectOneMenu用于值=#{ppBacker.grantProgram.grant_project_id}ID =addProgramTo大小=1的styleClass =listBoxMedium>
    <电话号码:AJAX程序=:addProgram:addProgramTo更新=:addProgram:periodGrid,:addProgram:periodLabel事件=变监听器=#{ppBacker.addProgramListener}/>
    < F:selectItems的值=#{ppBacker.grantProjectDropDownList}/>
< / P:selectOneMenu用于>

< H:outputLabel为=周期值=时代ID =periodLabel呈现=#{ppBacker.periodRendered}>
 

解决方案

您不能更新中未渲染的元素,渲染= FALSE 是一个JSF的方式来请从DOM树中的元素,

它不喜欢的CSS 显示:无可见性:隐藏< - 这两人将保持在元素DOM树,但隐藏的,而JSF 渲染= FALSE 甚至不会渲染(保持)在DOM树中的元素(你甚至不会看到它的查看源文件页)

所以,你如果你需要换行 outputLabel 用`panelGroup中'和更新包装的ID

 < H:panelGroup中的id =periodLabelWrapper>
    < H:outputLabel为=周期值=时代ID =periodLabel呈现=#{ppBacker.periodRendered}>
< /小时:panelGroup中>
 

和指包装(这始终处于DOM树)的ID在<电话号码:AJAX 更新属性,像这样的:

 <电话号码:AJAX程序=:addProgram:addProgramTo更新=:addProgram:periodGrid,:addProgram:periodLabelWrapper事件=变监听器=#{ppBacker。 addProgramListener}/>
 

另一种解决方案是更新这样整个表格<电话号码:AJAX更新=@形式...... 这样你就不需要在包装在 outputLabel

有关您的评论的问题

  

怎么做@form更新未渲染的元素,而是直接通过ID的不针对他们呢?

您不能定位在更新这是不是present页面(渲染= false)某个元素,其不存在

但是,当你使用更新=@表更新=someWrapperID的形式/包装再求值所有的内部元素,包括那些渲染=#{someBean.someCondition}和条件被重新评估,因此,如果它产生于的elemet将会显示...

I'm trying to use a p:ajax tag and then in that listener, i'm setting a value called "periodRendered". then i'm trying to update an h:outputLabel tag via an update from the p:ajax tag. It's not updating ajaxily and i'm thinking it's because a primefaces ajax tag can't update a standard jsf outputLabel tag.

Is my assumption correct and is there a more appropriate tag i should be using instead of h:outputLabel ?

<h:outputLabel for="addProgramTo" value="Add Program To" />
<p:selectOneMenu value="#{ppBacker.grantProgram.grant_project_id}" id="addProgramTo" size="1" styleClass="listBoxMedium">
    <p:ajax process=":addProgram:addProgramTo" update=":addProgram:periodGrid, :addProgram:periodLabel" event="change" listener="#{ppBacker.addProgramListener}" />
    <f:selectItems value="#{ppBacker.grantProjectDropDownList}" />
</p:selectOneMenu>            

<h:outputLabel for="period" value="Period" id="periodLabel" rendered="#{ppBacker.periodRendered}"> 

解决方案

You cannot update elements which are not rendered , rendered=false "is a JSF way to" to remove elements from the DOM Tree ,

its not like css display:none or visibility:hidden <- this two will keep the elements in the DOM tree but hidden , while the JSF rendered=false wont even render (keep) the element in the DOM tree (you wont even see it in the "view source" of the page)

So in you case you need to wrap the outputLabel with `panelGroup' and update the id of the wrapper

<h:panelGroup id="periodLabelWrapper">
    <h:outputLabel for="period" value="Period" id="periodLabel" rendered="#{ppBacker.periodRendered}">
</h:panelGroup>

and refer to the wrapper (which always be in the DOM tree) id in the <p:ajax update attribute, like this:

<p:ajax process=":addProgram:addProgramTo" update=":addProgram:periodGrid, :addProgram:periodLabelWrapper" event="change" listener="#{ppBacker.addProgramListener}" />

Another solution would be the update the entire form like this <p:ajax update="@form" ... that way you don't need the wrap the outputLabel

regarding your comment question

how does @form update the un-rendered elements, but targeting them directly through id's does not?

You can't target an element in update which is not present in the page (rendered=false) "its not there"

But when you use update="@form" or update="someWrapperID" the form/wrapper "re evaluates" all its inner elements , including the ones with rendered="#{someBean.someCondition}" and the condition gets "re evaluated" so if it result to true the elemet will be displayed...

这篇关于您可以更新H:outputLabel从AP:阿贾克斯监听器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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