是什么区别action和actionListener,什么时候应该使用action与actionListener?
我想知道Expression Languages(EL)之间的细节差异.有JSP EL,JSF EL和Unified EL.
我想知道EL背后的历史以及Java EE应用程序中使用的最新EL.它是最新版本中所有视图技术的EL通用吗?
我如何在JSF 2.0中使用EL中的参数/变量/参数调用直接方法或方法?
例如,在EL中获取列表大小:
<h:outputText value="#{bean.list.size()}" />
Run Code Online (Sandbox Code Playgroud)
或者使用参数调用action方法:
<h:commandButton value="edit" action="#{bean.edit(item)}" />
Run Code Online (Sandbox Code Playgroud)
这在我的环境中似乎不起作用.它似乎不喜欢括号.
javax.el.ELException:错误解析:#{bean.list.size()}
com.sun.el.parser.ParseException:遇到"("
是否可以使用单个命令组件调用多个侦听器方法?例如,
视图范围的bean:
@ManagedBean
@ViewScoped
public final class ViewScopedBean implements Serializable
{
@ManagedProperty(value = "#{sessionScopedBean}")
private SessionScopedBean sessionScopedBean; //Getter/Setter.
private static final long serialVersionUID = 1L;
public ViewScopedBean() {}
public void action()
{
//Do something.
sessionScopedBean.action();
}
}
Run Code Online (Sandbox Code Playgroud)
会话范围的bean:
@ManagedBean
@SessionScoped
public final class SessionScopedBean implements Serializable
{
private static final long serialVersionUID = 1L;
public SessionScopedBean () {}
public void action() {
//Do something.
}
}
Run Code Online (Sandbox Code Playgroud)
一个命令按钮,如下所示,
<h:commandButton value="Action" actionListener="#{viewScopedBean.action}"/>
Run Code Online (Sandbox Code Playgroud)
调用该方法action(),ViewScopedBean然后通过注入该bean的实例来调用该action()方法SessionScopedBean.
是否有可能在XHTML上做同样的事情,以便可以消除只是为了调用方法而注入bean的需要?
我想在进一步处理之前使用多个动作侦听器来设置两个支持bean的状态
第一种方式:
<p:commandButton process="@this" >
<f:attribute name="key" value="#{node.getIdTestGroup()}" />
<f:actionListener binding="#{testController.nodeListener}" />
<f:actionListener binding="#{testDeviceGroupController.prepareCreate}" />
</p:commandButton>
Run Code Online (Sandbox Code Playgroud)
它给出了一个例外:
警告:/ testGroup/List.xhtml @ 26,88 binding ="#{testController.nodeListener()}":找不到方法nodeListener javax.el.ELException:/testGroup/List.xhtml @ 26,88 binding ="#{ testController.nodeListener()}":找不到方法nodeListener
第二种方式:
<p:commandButton process="@this" >
<f:attribute name="key" value="#{node.getIdTestGroup()}" />
<f:actionListener binding="#{testController.nodeListener(event)}" />
<f:actionListener binding="#{testDeviceGroupController.prepareCreate(event)}" />
</p:commandButton>
Run Code Online (Sandbox Code Playgroud)
nodeListener和prepareCreate方法的事件为null
怎么做对吗?