例如,我有一个JSF页面:<h:form>
<h:inputText value="#{person.name}"/>
//...
<h:commandButton>
<f:actionListener type="PersonListener"/>
</h:commandButton>
</h:form>这里有个Bean,已经在config中注册了:public class Person{
//...
}现在使用一个ActionListener,那在这个类中如何获取Person的实例呢(使用myfaces)?public PersonListener implements ActionListener{
public void processAction(ActionEvent event){
//how could I get the person instance in the above jsf page?
}
}
<h:inputText value="#{person.name}"/>
//...
<h:commandButton>
<f:actionListener type="PersonListener"/>
</h:commandButton>
</h:form>这里有个Bean,已经在config中注册了:public class Person{
//...
}现在使用一个ActionListener,那在这个类中如何获取Person的实例呢(使用myfaces)?public PersonListener implements ActionListener{
public void processAction(ActionEvent event){
//how could I get the person instance in the above jsf page?
}
}
解决方案 »
- 请求莫名其妙的停了
- 求高手帮忙解决 弹窗问题。。(JS)。
- executeBatch()的返回值????
- jfreechart时序图怎么把日期倾斜?
- 网易、搜狐等大网站用什么操作系统作服务器呀?大家来讨论一下
- 一个奇怪的问题!两种结果集有什么不同?
- 很多书上都有说jsp:useBean的scope属性的application,是指任何使用相同的application,这个相同是什么意思?
- logic:iterate的实现问题
- 请问使用jdbc连接数据库sql server2000时,是否需要安装jdbc驱动,如果需要我应该怎么做?
- spring mvc 如何直接取得数组
- 有关搜索引擎技术原理和代码
- 大型网站一般用什么框架?
public void processAction(ActionEvent event){
FacesContext context = FacesContext.getCurrentInstance();
ValueBinding binding =
context.getApplication().createValueBinding("#{person}");
Person person = (Person) binding.getValue(context);
}
}
或者,直接用jsp标签..别把问题想复杂了.
我是个新手,对这个不太熟悉。那你认为该如何做才能降低耦合度呢?谢谢!
ELContext elContext = context.getELContext();
ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory();
ValueExpression ve = expressionFactory.createValueExpression(elContext, "#{ person}", Person.class);
Person p = (Person) ve.getValue(elContext);