JSF 2 - 从复合组件调用带有对象参数的侦听器
JSF 2 - calling a listener with object parameter from composite component
我有以下问题:
我这样定义了自己的自定义组件:
<composite:interface componentType="myComponent">
<composite:attribute name="listener" method-signature="void action(java.lang.Object)"/>
...
more attributues
</composite:interface>
现在,在我看来,我尝试传递一个带有特定手机对象的侦听器,该对象通过 ui:param 标记传递给视图:
<ui:include src="page.xhtml" >
<ui:param name="currentCellphone" value="#{cellphone}" />
</ui:include>
然后,在 page.xhtml 视图中,我尝试这样做:
<my:myComponent ... listener = "#{backbeanController.backbeanMethod(currentCellphone)}">
现在,如果 backbean 方法希望获得手机对象作为参数,当它到达函数时,参数为 null。 但是!,如果它被排除在外例如获取字符串,我向它发送一个字符串而不是 myCellphone 对象,效果很好。
我无法将 myCellphone 参数正确传递给 backbean。有任何想法吗?非常感谢。
您不能将复杂的对象作为参数传递,您可以只传递一个字符串,比如对象的 "Id"。然后你必须重建对象,但你可以像本例中那样使用会话映射:
Map<String, Object> sessionMap = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
sessionMap.put("controller", controller);
并称之为
Map<String, Object> sessionMap = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
MyController controller = (MyController) sessionMap.get("controller");
您可以在 Primefaces forum alse see Other link
中阅读完整示例
希望对您有所帮助。
我有以下问题: 我这样定义了自己的自定义组件:
<composite:interface componentType="myComponent">
<composite:attribute name="listener" method-signature="void action(java.lang.Object)"/>
...
more attributues
</composite:interface>
现在,在我看来,我尝试传递一个带有特定手机对象的侦听器,该对象通过 ui:param 标记传递给视图:
<ui:include src="page.xhtml" >
<ui:param name="currentCellphone" value="#{cellphone}" />
</ui:include>
然后,在 page.xhtml 视图中,我尝试这样做:
<my:myComponent ... listener = "#{backbeanController.backbeanMethod(currentCellphone)}">
现在,如果 backbean 方法希望获得手机对象作为参数,当它到达函数时,参数为 null。 但是!,如果它被排除在外例如获取字符串,我向它发送一个字符串而不是 myCellphone 对象,效果很好。
我无法将 myCellphone 参数正确传递给 backbean。有任何想法吗?非常感谢。
您不能将复杂的对象作为参数传递,您可以只传递一个字符串,比如对象的 "Id"。然后你必须重建对象,但你可以像本例中那样使用会话映射:
Map<String, Object> sessionMap = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
sessionMap.put("controller", controller);
并称之为
Map<String, Object> sessionMap = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
MyController controller = (MyController) sessionMap.get("controller");
您可以在 Primefaces forum alse see Other link
中阅读完整示例希望对您有所帮助。