Reusing layout in multiple beans

How can I call / access a managed bean resource when the bean name is known but not yet built?

For instance:

<p:selectOneMenu value="#{eval.evaluateAsBean(bean).text}" >
    <f:selectItems value="#{eval.evaluateAsBean(bean).values}" var="val"
        itemLabel="#{val}" itemValue="#{val}" />
</p:selectOneMenu> 

If there is a managed bean called testBean, and in my view the bean has a value "testBean", I want the text or values ​​testBean property to be called.

EDIT1

Context

An object consists of a list of properties (values). One property is modified using a special JSF editor, depending on its type.

The list of editors is determined by the type of object and displayed in the form using tags custom:include. This custom tag is used to dynamically enable editors <custom:include src="#{editor.component}">. The component property indicates the location of the JSF editor.

( ) (dynamicDropdown.xhtml). bean. facelet beans bean dynamicDropdown.xhtml bean.

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;
    }

    ...

}
+3
3

servlet-api 2.5

2.5 EL 2.1. EL 2.1. EL 2.2, Servlet 3.0.

Servlet 3.0 (Tomcat 7, Glassfish 3, JBoss AS 6 ..), EL 2.1. JBoss EL - EL 2.1 , , EL 2.2. , jboss-el.jar webapp /WEB-INF/lib web.xml, , :

<context-param>     
    <param-name>com.sun.faces.expressionFactory</param-name>
    <param-value>org.jboss.el.ExpressionFactoryImpl</param-value>   
</context-param>
+1

bean JSF, , bean= "# {testBean}" , = "# {cc.attrs.bean.test }"

+1

, <h:outputText value="#{bean.text}"/> , bean @ManagedBean.

+1

All Articles