What is the 'official' SEAM way of listening to JSF-SEAM phases?

烈酒焚心 提交于 2020-01-01 16:26:37

问题


A simple question on the title.

My case is that I want to listen to "before RENDER_RESPONSE" phase, and alter some components internal state.

Is PhaseListener the "right way" to do this in SEAM applications?


回答1:


If you want alter JSF component internal state, rely on JSF phase listener. Seam way of declaring JSF phase listener is shown bellow

@Name("applicationPhaseListener")
@Scope(ScopeType.APPLICATION)
public class ApplicationPhaseListener {

    /**
      * Called TRANSPARENTLY by Seam
      */
    @Observer("org.jboss.seam.beforePhase")
    public void beforePhase(PhaseEvent event) {


    }

    /**
      * Called TRANSPARENTLY by Seam
      */
    @Observer("org.jboss.seam.afterPhase")
    public void afterPhase(PhaseEvent event) {

    }



}

But if you want to alter Seam contextual component state, use

@Name("applicationPhaseListener")
public class ApplicationPhaseListener {

    @Observer("applicationListener")
    public void applicationListener() {

    }

}

You can

Call your event programatically

Events.instance().raiseEvent("applicationListener");

By using @RaiseEvent annotation which is placed aboved some action method

@RaiseEvent("applicationListener")
public void doSomething() {

}

pages.xml

<page id="<PAGE_ID_GOES_HERE>">
    <raise-event type="applicationListener"/>
</page>


来源:https://stackoverflow.com/questions/3809225/what-is-the-official-seam-way-of-listening-to-jsf-seam-phases

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!