开发者

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

开发者 https://www.devze.com 2023-01-17 16:20 出处:网络
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.

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?


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消