Bean名はわかっているが、まだ構築されていない場合、管理対象Beanのプロパティを呼び出す/アクセスするにはどうすればよいですか?
例えば:
<p:selectOneMenu value="#{eval.evaluateAsBean(bean).text}" >
<f:selectItems value="#{eval.evaluateAsBean(bean).values}" var="val"
itemLabel="#{val}" itemValue="#{val}" />
</p:selectOneMenu>
testBeanと呼ばれるマネージドBeanがあり、私のビューでBeanに"testBean"
値がある場合、testBeanのtextまたはvaluesプロパティを呼び出す必要があります。
編集1
コンテキスト
オブジェクトは、プロパティ(値)のリストで構成されます。1つのプロパティは、そのタイプに応じて、カスタムJSFエディターで変更されます。
エディターのリストは、オブジェクトのタイプから決定され、custom:include
タグを使用してフォームに表示されます。このカスタムタグは、エディターを動的に含めるために使用されます<custom:include src="#{editor.component}">
。コンポーネントプロパティは、JSFエディターの場所を指します。
私の例では、一部のエディター(選択ボックスとしてレンダリング)は同じfacelet(dynamicDropdown.xhtml)を使用します。すべてのエディターには、セッションスコープのマネージドBeanがあります。同じファセットを複数のBeanで再利用し、Beanパラメーターを使用してBeanの名前をdynamicDropdown.xhtmlに渡したい。
genericAccount.xhtml
<p:dataTable value="#{group.editors}" var="editor">
<p:column headerText="Key">
<h:outputText value="#{editor.name}" />
</p:column>
<p:column headerText="Value">
<h:panelGroup rendered="#{not editor.href}">
<h:outputText value="#{editor.component}" escape="false" />
</h:panelGroup>
<h:panelGroup rendered="#{editor.href}">
<custom:include src="#{editor.component}">
<ui:param name="bean" value="#{editor.bean}"/>
<custom:include>
</h:panelGroup>
</p:column>
</p:dataTable>
#{editor.component}
dynamicDropdown.xhtmlファイルを参照します。
dynamicDropdown.xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
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:p="http://primefaces.prime.com.tr/ui">
<p:selectOneMenu value="#{eval.evaluateAsBean(bean).text}" >
<f:selectItems value="#{eval.evaluateAsBean(bean).values}" var="val"
itemLabel="#{val}" itemValue="#{val}" />
</p:selectOneMenu>
</ui:composition>
eval
マネージドBeanです:
@ManagedBean(name = "eval")
@ApplicationScoped
public class ELEvaluator {
...
public Object evaluateAsBean(String el) {
FacesContext context = FacesContext.getCurrentInstance();
Object bean = context.getELContext()
.getELResolver().getValue(context.getELContext(), null, el);
return bean;
}
...
}