我有一个关于将ActionListener委托给复合组件(jsf)的具体问题。我创建了一个复合组件来显示(浏览)和编辑任何个人用户数据(属性为" user ")。
<body>
<co:interface>
<co:attribute name="editAction" required="false" targets="edit" method-signature="java.lang.String f()"/>
<co:attribute name="saveAction" required="false" targets="save" method-signature="java.lang.String f()"/>
<co:attribute name="cancelAction" required="false" targets="cancel" method-signature="java.lang.String f()"/>
<co:attribute name="isBrowseModus" required="true"/>
<co:attribute name="user" required="true"/>
<co:attribute name="isDeveloper" required="true"/>
<co:actionSource name="edit"/>
<co:actionSource name="save"/>
<co:actionSource name="cancel"/>
</co:interface>
............
<p:inplace id="inpLand" editor="true"
toggleable="#{not cc.attrs.isBrowseModus}"
style="#{cc.attrs.isBrowseModus ? 'color: black' : 'color: blue'}">
<p:inputText value="#{cc.attrs.user.land}" label="text"/>
</p:inplace>
...........
<c:if test="#{cc.attrs.isBrowseModus}">
<h:commandButton id="edit" value="Edit"/>
</c:if>
........实际上,这个复合组件是通过调用myData.xhtml的视图调用的。
<ui:define name="center">
<h3>MyData Developer </h3>
<h4>Welcomne</h4>
<h:form id="dataForm">
<mc:UserData user="#{dataBean.user}" isDeveloper="#{dataBean.developer}" isBrowseModus="#{dataBean.browseModus}" cancelAction="#{dataBean.cancel}"
saveAction="#{dataBean.save}" editAction="#{dataBean.edit}">
<f:actionListener for="edit" binding="#{dataBean.editActionListener}"/>
</mc:UserData>
</h:form>
</ui:define>
</ui:composition>在复合组件中有一个(id = actionListener ),交付的myData(参见f:actionListener在myData中)应该绑定到这个commandButton (id =commandButton)。这是我在阅读不同论坛的讨论和几份文件后的理解。
不幸的是,在单击Edit之后,editActionListener方法没有被触发,我不知道为什么。当然,这个editActionListener方法存在于managedBean "dataBean“(myData.java)中:
public void editActionListener(ActionEvent ae) {
browseModus = false;
FacesContext.getCurrentInstance().renderResponse();
} 我的目标是:在这个复合组件中,用户可以通过单击“编辑”按钮来更改任何用户数据。我更喜欢使用PRIMEFACES的内置标签。单击“编辑”按钮后,所有可更改的字段都应以蓝色显示。
我的问题:
任何帮助都会很感激的。在此之前,非常感谢您。你好,博多
发布于 2013-02-25 17:18:24
根据标签文档,<f:actionListener binding>必须引用实现ActionListener接口的具体实例,而不是方法表达式。
总之,您的问题可以通过通过getter提供ActionListener接口的具体实现来解决,而getter反过来又调用所需的动作侦听器方法。
private ActionListener editActionListener = new ActionListener() {
@Override
public void processAction(ActionEvent event) throws AbortProcessingException {
DataBean.this.editActionListener(event);
}
};
public ActionListener getEditActionListener() {
return editActionListener;
}
public void editActionListener(ActionEvent event) {
browseModus = false;
FacesContext.getCurrentInstance().renderResponse();
}然而,这是笨拙的,这表明您在寻找可能是错误的解决方案。一个更简单的方法是使用<cc:attribute targets="edit">。
<cc:interface>
...
<cc:attribute name="actionListener" targets="edit" />
</cc:interface>它被用作
<mc:UserData ... actionListener="#{dataBean.editActionListener}" />https://stackoverflow.com/questions/15068602
复制相似问题