尝试嵌套JSF表达式字符串 [英] Trying to nest JSF expression strings
问题描述
我想知道是否可以通过问题
I'd like to know whether it is possible to adapt the ExtendedBeanELResolver from the question nesting-jsf-expression-strings as well to handle this nested EL expression:
#{controllerBean.getBean('userProfileBean', component).street}*
其中 controllerBean.getBean 返回bean userProfileBean 。我将使用 ExtenedBeanELResolver 以下异常:
whereby controllerBean.getBean returns the bean userProfileBean. I'll get with the ExtenedBeanELResolver following exception:
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
如果我插入其他括号,它可以工作,但看起来比现在更丑:
If I insert additional brackets it works, but looks even more ugly than now:
#{(controllerBean.getBean('userProfileBean', component)).street}*
是否可以不用其他括号?
Is it possible to do without the additional brackets?
在CycDemo回答后更新1:
奇怪的问题。
如果我把
Strange problem. If i put the
<h:inputText value="#{beanOne.getBean('data').title}" />
内部页面呈现的表单,但仅在我提交表单之前。之后,将显示相同的错误。
inside a form the page renders, but only until i submit the form. After that the same error will be shown.
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,但无法正确评估它。
the page won't even render in the beginning. I think the problem is that the JSF is trying to call the setter when the form is submitted but can't evaluate it correctly.
有什么想法吗?
更新2
显然JSF试图调用 getGetBean() ,因为它正在 BeanOne 上寻找属性(我在Eclipse中有一个断点),这是错误的:
Appearently JSF is trying to call getGetBean() because it is looking for a property on BeanOne (I had a breakpoint there in eclipse) which is wrong:
@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;
}
}
推荐答案
确定
#{(controllerBean.getBean('userProfileBean', component)).street}
change to
#{controllerBean.getBean('userProfileBean', component).street}
当我测试时,它在JSF 2.0中有效。
It is work in JSF 2.0 when I test.
使用 jboss-el
。下载jar文件此处
Use jboss-el
. Download jar file here
BeanOne.java
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
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());
}
}
Date.java
Date.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
pageOne.xtml
<h:form>
<h:inputText value="#{BeanOne.getBean('Test').input}"/><br/>
<h:commandButton value="Show" action="#{BeanOne.show}"/>
</h:form>
在web.xml中添加以下配置
add the following configuration in web.xml
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>org.jboss.el.ExpressionFactoryImpl</param-value>
</context-param>
这篇关于尝试嵌套JSF表达式字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!