【问题标题】:JSF2 How to update different components from different pagesJSF2 如何从不同的页面更新不同的组件
【发布时间】:2014-03-20 07:44:30
【问题描述】:

让我们从我的问题开始:

我有两个页面:主要页面和职业页面。

两者都有相同的模板:<ui:composition template="/common/decorators/template.xhtml">

模板.xhtml

.
.
.   
<app:metaHeader />
</h:head>
<h:body>
<app:status/>
<ui:debug hotkey="d" rendered="#{initParam['facelets.DEVELOPMENT']}" />
<div id="geral">
    <div id="header">
        <app:header />
    </div>
    <p:messages id="messages" showDetail="false" autoUpdate="true" closable="true" />   

    <ui:insert name="body" />
</div>
</h:body>
</html>

&lt;app:header /&gt; 是:

<?xml version="1.0" encoding="ISO-8859-1"?>
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:t="http://myfaces.apache.org/tomahawk"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:acegijsf="http://sourceforge.net/projects/jsf-comp/acegijsf"
xmlns:app="http://cni.org.br/tags"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:p="http://primefaces.org/ui" xml:lang="pt" lang="pt">
<div id="header">

    <div class="content">
        <h:form>
            <div>
                <p:outputPanel>
                    <label>You are in:</label>
                    <h:selectOneMenu id="cities" value="#{bean.selectedCity}"
                        converter="omnifaces.SelectItemsConverter">
                        <f:selectItems id="selectedCity" value="#{bean.cityList}"
                            var="city" itemLabel="#{city.name}" itemValue="#{city}" />
                        <p:ajax event="change" listener="#{bean.citySession}"
                            update="?????????" />
                    </h:selectOneMenu>
                </p:outputPanel>
            </div>

        </h:form>
    </div>
</div>

所以,当我在标题处选择一个城市时,我需要更新整个 main.xhtml 页面,但只需要更新professional.xhtml 中的几个组件。

我尝试过使用

&lt;p:ajax event="change" listener="#{bean.citySession}" upate=":componentsIwant" /&gt;

&lt;p:ajax event="change" listener="#{bean.citySession}" upate=":professionForm:componentsIwant" /&gt;

&lt;p:ajax event="change" listener="#{bean.citySession}" upate=":general:professionForm:componentsIwant" /&gt;

但是main.xhtml(我选择要详细说明的专业的页面)上不存在componentsIwant,所以我得到了:

找不到从“j_id18836674_3d6516fd:cities”引用的表达式“:componentsIwant”的组件。

有什么办法可以解决吗?

附:我不能更改模板,因为这是公司的标准。

【问题讨论】:

    标签: java jsf primefaces include


    【解决方案1】:

    我看到了两种解决问题的方法:

    1. 表达语言

      &lt;p:ajax /&gt;update 属性中使用 EL,例如:

      update="#{someBean.someCondition ? ':formId:componentId' : ''}"
      

      update="#{someBean.componentId}"
      
    2. &lt;ui:param /&gt;

      通过参数传递组件id:

      <ui:composition template="/template.xhtml">
          <ui:param name="componentId" value=":formId:componentId" />
          ...
      </ui:composition>
      

      并将其用作:

      update="#{componentId}"
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-31
      • 1970-01-01
      • 2017-05-17
      相关资源
      最近更新 更多