2012-10-17 16 views
1

我想知道是否可以從問題nesting-jsf-expression-strings適應ExtendedBeanELResolver以及處理這種嵌套EL表達式:試圖巢JSF表達串

#{controllerBean.getBean('userProfileBean', component).street}* 

由此controllerBean.getBean返回bean userProfileBean。我會與ExtenedBeanELResolver以下異常得到:

SCHWERWIEGEND: javax.el.PropertyNotFoundException: /WEB-INF/templates/modification/userProfile.xhtml @35,196 value="#{controllerBean.getBean('userProfileBean', component).street}": Property 'getBean' not found on type com.something.ControllerBean 

如果我插入它的工作原理附加括號,但看起來更加難看比現在:

#{(controllerBean.getBean('userProfileBean', component)).street}* 

是否有可能沒有額外的做括號?

Update 1之後,CycDemo的回答是:

奇怪的問題。 如果我把

<h:inputText value="#{beanOne.getBean('data').title}" /> 

表單頁面呈現,但直到我提交表單。之後,將顯示相同的錯誤。

WARNUNG: /WEB-INF/templates/home.xhtml @61,66 value="#{beanOne.getBean('data').title}": Property 'getBean' not found on type com.something.BeanOne 

如果我將其更改爲

<p:inputText value="#{beanOne.getBean('data').title}" /> 

頁甚至不會呈現在開始。 我認爲問題在於JSF在提交表單時嘗試調用setter,但無法正確評估它。

任何想法?

更新2

Appearently JSF試圖調用getGetBean(),因爲它是在尋找財產 BeanOne(我曾在日食一個斷點),這是錯誤的:

@ManagedBean 
@ViewScoped 
public class BeanOne { 

    private Object bean = new String("something"); 

    public Object getBean(String name) { 
    FacesContext context = FacesContext.getCurrentInstance(); 
    return context.getApplication().evaluateExpressionGet(context, 
     "#{" + name + "}", 
     Object.class); 
    } 

    public Object getGetBean() { 
    return bean; // <-- will be called by JSF 
    } 

    public void setGetBean(Object bean) { 
    this.bean = bean; 
    } 

} 
+0

再次獲得該錯誤下面的配置?提交你的事業; – CycDemo

回答

1

確保

#{(controllerBean.getBean('userProfileBean', component)).street} 
    change to 
    #{controllerBean.getBean('userProfileBean', component).street} 

當我測試時,它在JSF 2.0中工作。

使用jboss-el。下載jar文件here

BeanOne.java import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped;

@ManagedBean(name="BeanOne") 
@RequestScoped 
public class BeanOne { 
    private Data data; 

    public Data getBean(String title) { 
     data = new Data(title); 
     return data; 
    } 
    public void show() { 
     System.out.println("User Input ==>" + data.getInput()); 
    } 
} 

日期。java的

public class Data { 
    private String title; 
    private String input; 

    public Data(String title) { 
     this.title = title; 
    } 

    public String getInput() { 
     return input; 
    } 

    public void setInput(String input) { 
     this.input = input; 
    } 

    public String getTitle() { 
     return title; 
    } 

    public void setTitle(String title) { 
     this.title = title; 
    } 
} 

pageOne.xtml

<h:form> 
    <h:inputText value="#{BeanOne.getBean('Test').input}"/><br/> 
    <h:commandButton value="Show" action="#{BeanOne.show}"/> 
</h:form> 

添加在web.xml

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

我已更新該問題。 – Manuel

+0

@曼紐爾,請檢查我的回答我再次更新您的新問題。 – CycDemo

+0

試着讓你的* Data *類成爲一個託管bean,並像它對待你的* BeanOne *那樣獲取它。你應該像我一樣得到同樣的錯誤。 – Manuel