[英]JSF2 How to update different components from different pages
讓我們從我的問題開始:
我有兩頁:專業和專業。
兩者都有相同的模板: <ui:composition template="/common/decorators/template.xhtml">
template.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>
<app:header />
是:
<?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中的幾個組件。
我嘗試使用
<p:ajax event="change" listener="#{bean.citySession}" upate=":componentsIwant" />
<p:ajax event="change" listener="#{bean.citySession}" upate=":professionForm:componentsIwant" />
<p:ajax event="change" listener="#{bean.citySession}" upate=":general:professionForm:componentsIwant" />
但是componentIwant在main.xhtml(我選擇要詳細介紹的職業的頁面)上不存在,所以我得到了:
找不到從“ j_id18836674_3d6516fd:cities”引用的表達式為“:componentsIwant”的組件。
有一種方法可以解決?
ps我不能更改模板,因為這是公司的標准。
我看到兩種解決問題的方法:
表達語言
在您的<p:ajax />
update屬性中使用EL,例如:
update="#{someBean.someCondition ? ':formId:componentId' : ''}"
要么
update="#{someBean.componentId}"
<ui:param />
通過參數傳遞組件ID:
<ui:composition template="/template.xhtml"> <ui:param name="componentId" value=":formId:componentId" /> ... </ui:composition>
並將其用作:
update="#{componentId}"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.