簡體   English   中英

JSF 2-跨系統事件傳遞參數

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM