如何使用primefaces的ajax刷新jstl测试? [英] how to refresh jstl test using ajax of primefaces?

查看:97
本文介绍了如何使用primefaces的ajax刷新jstl测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:当我单击按钮A时.我收到以下文本:you have choosed A.

for example: when I click on the button A. I get the following text : you have choosed A.

但是当我更改按钮时,尽管#{bean.str}的值更改了,但我还是得到了相同的文本

But when I change button, I get the same text, although the value of #{bean.str} changes

这是我的代码:

<p:selectOneButton id="selectId" value="#{bean.str}">
            <f:selectItem itemLabel="A" itemValue="1" />
            <f:selectItem itemLabel="B" itemValue="2" />
            <f:selectItem itemLabel="C" itemValue="3" />
            <f:ajax event="change" render="tabView" listener="#{bean.change}" />
</p:selectOneButton>

<c:if var="test" test="#{bean.str =='1'}">
        <h:outputText value="you have choosed A" />
</c:if>
<c:if test="#{beanApplication.perspective=='2'}">
        <h:outputText value="you have choosed B" />
</c:if>
<c:if test="#{beanApplication.perspective=='3'}">
        <h:outputText value="you have choosed C" />
</c:if>

当我单击按钮时,我正在寻找一种刷新JSTL <c:if>测试的方法.

I am looking for a way to refresh the JSTL <c:if> test when I click on the button.

推荐答案

JSTL在JSF视图构建期间运行,而不是在JSF视图渲染期间运行.但是,在此特定示例中,提交的值仅在视图构建时间之后设置为bean属性 .视图构建时间在JSF RESTORE_VIEW阶段运行,但是bean属性是在JSF UPDATE_MODEL_VALUES阶段设置的.

JSTL runs during JSF view build time, not during JSF view render time. However, the submitted value is in this particular example only set as bean property after view build time. The view build time runs during JSF RESTORE_VIEW phase, but the bean property is set during JSF UPDATE_MODEL_VALUES phase.

您需要在渲染期间评估条件.为此使用提供的JSF组件的rendered属性.

You need to evaluate the condition during render time instead. Use the therefor provided JSF component's rendered attribute.

<h:outputText value="you have chosen A" rendered="#{bean.str == '1'}" />
<h:outputText value="you have chosen B" rendered="#{bean.str == '2'}" />
<h:outputText value="you have chosen C" rendered="#{bean.str == '3'}" />

此外,您应该在PrimeFaces组件中使用<p:ajax>,而不是<f:ajax>.另外,还应确保在<f:ajax render>中引用为tabView的组件(以及等效的<p:ajax update>)涵盖上述三个组件.这是一个完整的启动示例:

Further, you should be using <p:ajax> in PrimeFaces components, not <f:ajax>. Also you should ensure that the component referenced as tabView in <f:ajax render> (and equivalently, the <p:ajax update>) covers the above three components. Here's a complete kickoff example:

<p:selectOneButton id="selectId" value="#{bean.str}">
    <f:selectItem itemLabel="A" itemValue="1" />
    <f:selectItem itemLabel="B" itemValue="2" />
    <f:selectItem itemLabel="C" itemValue="3" />
    <p:ajax listener="#{bean.change}" update="tabView" />
</p:selectOneButton>

<h:panelGroup id="tabView">
    <h:outputText value="you have chosen A" rendered="#{bean.str == '1'}" />
    <h:outputText value="you have chosen B" rendered="#{bean.str == '2'}" />
    <h:outputText value="you have chosen C" rendered="#{bean.str == '3'}" />
</h:panelGroup>

另请参见:

  • JSF2 Facelets中的JSTL ...有意义吗?
  • See also:

    • JSTL in JSF2 Facelets... makes sense?
    • 这篇关于如何使用primefaces的ajax刷新jstl测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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