tags:

views:

24

answers:

1

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?

+3  A: 

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>
Arthur Ronald F D Garcia
got it. thank you.
bungrudi