JSF 2 - 在系统事件中传递参数

时间:2010-08-24 15:57:38

标签: jsf jsf-2

我有一个复合组件,我传入一个任意定义的属性:

<x:mycomp x="..."/>

x在cc的接口定义中被定义为。在mycomp的实现中,我有一个事件监听器:

<composite:implementation>
    <f:event type="preRenderComponent" listener="#{mycontroller.init}" />
</composite:implementation>

现在我想在后端使用这个仲裁参数x做一些事情。如何通过系统事件传递它,就像使用f:attribute标记一样?或从事件中获取源组件并通过其内部拖网? (说到UIComponent中存储这些属性的位置 - 无论如何都找不到它们,而不是属性)。

如果不可能,这严重限制了系统事件的有用性。如果将组件放在ui:repeat内,则会多次触发侦听器,以便在事件触发期间遍历树。

我唯一能想到的就是将init直接编码到渲染中:

<composite:implementation>
    #{mycontroller.init(cc.attrs.x)} //returns empty string
    <!--f:event type="preRenderComponent" listener="#{mycontroller.init}" /-->
</composite:implementation>

但我认为那是一个预渲染系统事件。

1 个答案:

答案 0 :(得分:1)

也许答案有点晚了。

我做了一个概念证明,我认为你正在努力解决的问题。为了实现它,您必须在复合材料的使用页面中取出事件注册并进行操作。您的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"));
   }

}

我希望它会有用(几个月后)。