不推荐使用richfaces javax.faces.el.MethodBinding替换使用 [英] Deprecated richfaces javax.faces.el.MethodBinding replacement use
问题描述
我发现这段代码的工作原理是我可以通过编程方式创建一个richfaces下拉菜单。但有些代码已被弃用。谁能告诉我要放入什么而不是弃用的电话?
I found this piece of code works in that i can programmatically creates a richfaces dropdown menu. But some of the code is deprecated. Can anyone tell me what to put in instead of the deprecated calls?
谢谢
public HtmlDropDownMenu getMyMenu()
{
HtmlDropDownMenu menu = new HtmlDropDownMenu();
menu.setValue( "Node Select" );
HtmlMenuItem menuItem = new HtmlMenuItem();
// TODO programmatically pass from getNodes into a String[] rather than an ArrayList of SelectItems
String subOption = "myBox";
menuItem.setValue( subOption );
Application app = FacesContext.getCurrentInstance().getApplication();
javax.faces.el.MethodBinding mb = app.createMethodBinding( "#{PrismBacking.onItemClick}", new Class[] { ActionEvent.class } );
menuItem.setActionListener( mb );
menu.getChildren().add( menuItem );
return( menu );
}
public void onItemClick( ActionEvent event )
{
Object obj = event.getSource();
if( obj instanceof HtmlMenuItem )
{
HtmlMenuItem item = (HtmlMenuItem)obj;
if( item != null )
{
lastItem = item.getValue().toString();
}
}
}
不推荐的代码行是:
javax.faces.el.MethodBinding mb = app.createMethodBinding( "#{PrismBacking.onItemClick}", new Class[] { ActionEvent.class } );
menuItem.setActionListener( mb );
推荐答案
javadocs明确说明:
The javadocs state it clearly:
Application.createMethodBinding
已弃用。这已被替换为调用getExpressionFactory()然后 ExpressionFactory.createMethodExpression(javax.el.ELContext,java.lang.String,java.lang.Class,java.lang.Class [])。
Deprecated. This has been replaced by calling getExpressionFactory() then ExpressionFactory.createMethodExpression(javax.el.ELContext, java.lang.String, java.lang.Class, java.lang.Class[]).
以下是如何使用它:
MethodExpression methodExpression =
application.getExpressionFactory().createMethodExpression(
FacesContext.getCurrentInstance().getELContext(),
"#{PrismBacking.onItemClick}",
null,
new Class[] { ActionEvent.class });
menuItem.setActionExpression(methodExpression);
这篇关于不推荐使用richfaces javax.faces.el.MethodBinding替换使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!