[英]JSF 2 - passing parameters accross system events
我有一个复合组件,在其中传递了一个任意定义的属性:
<x:mycomp x="..."/>
x
在cc的接口定义中是这样定义的。 在mycomp
的实现内部,我有一个事件侦听器:
<composite:implementation>
<f:event type="preRenderComponent" listener="#{mycontroller.init}" />
</composite:implementation>
现在,我想在后端使用此任意参数x
。 如何在整个系统事件中传递它,例如使用f:attribute
标签? 还是从事件中获取源组件并通过其内部进行拖网? (说到底这些属性在UIComponent中的哪个位置存储-我找不到它们,无论如何也没有在属性中找到它们)。
如果不可能的话,这将严重限制系统事件的实用性。 如果将组件放在ui:repeat
,则会多次触发侦听器,因此在事件触发期间它会遍历整个树。
我唯一想到的就是将init直接编码到render中:
<composite:implementation>
#{mycontroller.init(cc.attrs.x)} //returns empty string
<!--f:event type="preRenderComponent" listener="#{mycontroller.init}" /-->
</composite:implementation>
但是我认为这就是预渲染系统事件的目的。
也许答案来晚了。
我证明了我认为是您要解决的问题的概念。 为了做到这一点,您必须在组合的使用页面中进行事件注册并进行注册。 您的init方法可以接收一个ComponentSystemEvent,它将为您提供复合组件,然后您可以从该组件的属性映射中访问“ x”属性。
使用页面中的代码是这样的:
<x:mycomp x="hola">
<f:event type="preRenderComponent" listener="#{bean.init}"/>
</x:mycomp>
和Java代码:
public class MyBean {
private String value;
public void init(ComponentSystemEvent e){
System.out.println("x: "+e.getComponent().getAttributes().get("x"));
}
}
我希望它会有用(几个月后)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.