Use of JSF Phase Listener?

There are many many examples of how to 'access' the six phases of the JSF Life Cycle.
I have a simple page that has two input text fields and one command button.
I would like to be able to access the contents of the text fields on the page in Phase 2 (APPLY REQUEST VALUES), or other phases. After quite a bit of time I am posting this in the hopes that someone could point me in the correct direction to do this or perhaps someone has a simple example.
Thanks - Casey

Code for phase listener, backing bean and output are at the bottom of this note.
The text field has a Id property of lname. I assume you are referring about using findComponent() against the backing bean that has a corresponding property (RichInputText) for the text field?
When I run the app I am getting a null for the objReference for the backing bean (line 16 in the output) - see output which then causes a NullPointerException.
Suggestions on how to get the reference to the backing bean, or the component that will contain the data for the input text field?
Thanks again - Casey
The code I am using in the Phase Listener class is:*
+public class MyPhaseListener implements PhaseListener {+
+public MyPhaseListener() {+
+}+
+public void beforePhase(PhaseEvent pe) {+
if (pe.getPhaseId() == PhaseId.RESTORE_VIEW)
System.out.println("Processing new  Request!");
System.out.println("before - " pe.getPhaseId().toString());+
+if (pe.getPhaseId().toString().equals("APPLY_REQUEST_VALUES 2")) {+
System.out.println("lkjhlkjhlkjhlkjh");
+}+
+if (pe.getPhaseId().toString().equals("APPLY_REQUEST_VALUES 2")) {+
FacesContext facesContext = FacesContext.getCurrentInstance();
ELContext elContext = facesContext.getELContext();
ExpressionFactory expressionFactory =
facesContext.getApplication().getExpressionFactory();
ValueExpression exp =
expressionFactory.createValueExpression(elContext,
+"#{BackingBean}",+
BackingBean.class);
BackingBean nameData = (BackingBean)exp.getValue(elContext);
System.out.println(nameData);
System.out.println(nameData.getLname().findComponent("lname"));
+}+
+}+
+public void afterPhase(PhaseEvent pe) {+
System.out.println("after - " pe.getPhaseId().toString());+
if (pe.getPhaseId() == PhaseId.RENDER_RESPONSE)
System.out.println("Done with Request!\n");
+}+
+public PhaseId getPhaseId() {+
return PhaseId.ANY_PHASE;
+}+
+}+
The code for the backing bean is:*
package view;
import oracle.adf.view.rich.component.rich.input.RichInputText;
+public class BackingBean {+
private RichInputText lname;
+public BackingBean() {+
+}+
+public void setLname(RichInputText lname) {+
System.out.println("In setLName");
this.lname = lname;
+}+
+public RichInputText getLname() {+
System.out.println("In getLName");
return lname;
+}+
+}+
Output from System.out.println statements:*
Processing new  Request!
before - RESTORE_VIEW 1
after - RESTORE_VIEW 1
before - RENDER_RESPONSE 6
In getLName
In setLName
after - RENDER_RESPONSE 6
Done with Request!
Processing new  Request!
before - RESTORE_VIEW 1
In setLName
after - RESTORE_VIEW 1
before - APPLY_REQUEST_VALUES 2
lkjhlkjhlkjhlkjh
null
after - APPLY_REQUEST_VALUES 2
+<Jul 13, 2009 8:27:14 AM CDT> <Error> <HTTP> <BEA-101017> <[weblogic.servlet.internal.WebAppServletContext@857c75 - appName: 'Application8', name: 'Application8-ViewController-context-root', context-path: '/Application8-ViewController-context-root', spec-version: '2.5', request: weblogic.servlet.internal.ServletRequestImpl@1c70722[+
+POST /Application8-ViewController-context-root/faces/untitled1.jspx?_adf.ctrl-state=793257214_3 HTTP/1.1+
+Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/x-shockwave-flash, */*+
+Referer: http://127.0.0.1:7101/Application8-ViewController-context-root/faces/untitled1.jspx?_adf.ctrl-state=793257214_3+
+Accept-Language: en-us,de;q=0.5+
+Content-Type: application/x-www-form-urlencoded+
+UA-CPU: x86+
+Accept-Encoding: gzip, deflate+
+User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; InfoPath.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648)+
+Content-Length: 269+
+Connection: Keep-Alive+
+Cache-Control: no-cache+
+Cookie: JSESSIONID=wBr1Kb2GrCDpnhkNNgQyTvJvSjlnWHyvnq9gNWT92kvsFYlGC1Jl!1059440035+
+]] Root cause of ServletException.+
java.lang.NullPointerException
+     at view.MyPhaseListener.beforePhase(MyPhaseListener.java:42)+
+     at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._executePhase(LifecycleImpl.java:228)+
+     at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:175)+
+     at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)+
+     at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)+
+     Truncated. see log file for complete stacktrace+

Similar Messages

  • ADF:How to use NavigationHandler in Phase-Listener with adfc-config.xml

    Hi,
    in our application a user should be navigated to the login-page, when he tries to navigate directly to a page where he has no right for or if the session is expired.
    Our navigation is complete in the adfc-config.xml. So I created a phase-listener, which is called by the adf-settings.xml.
    Inside the phase-listener I'm checking the rights. If the user doesn't have the needed rights, he should be linked to the login page. But how can I do that?
    Some days ago our navigation has been complete in the faces-config.xml. But now we moved the navigation to the adfc-config.xml, because we are sure that it's better. E.g. for using the dialog framework.
    In the face-config.xml we had also the call of the phase-listener. There we did the forwarding like this and it worked:
    FacesContext facesContext = FacesContext.getCurrentInstance();
    facesContext.getApplication().getNavigationHandler().handleNavigation(facesContext, null, "login_page");But now I think I have to use the ADFContext somehow, or?
    So how can I do that with the adfc-config.xml?
    Thanks a lot for your help,
    Bastian
    I'm using JDeveloper 11g Release 1 (11.1.1.3.0)

    Hello Frank,
    thanks for your answer, but it doesn't really help me, because I'm a newbie, sorry.
    Does your answer mean, that I should leave the call of the phase-listener in the faces-config and then I would also have access to the login-page, which is in the adfc-config?
    Or does it mean, that I call now my phase-listener by adf-settings but don't have to change the phase-listener itself and can still use my code (FacesContext...)? But that's not working. I get no error but he is also not redirecting.
    Maybe my problem starts on an earlier point.
    Is it better to create all pages in the adfc-config or faces-config? (Maybe you have a good reference for reading about such a basic discussion)
    I thought adfc-config would be the better one. But there I'm not able to redirect to another page (login) if somebody calls a special page without rights for example.
    So my second basic question would be about the relation of adfc-config, faces-config and ADFContext and FacesContext.
    Because I think it's not a short answer I hope you could give me also for this a reference so that I can read these basics myself.
    Thanks a lot for helping a newbie becoming better :-)
    Bastian

  • Phase Listener buries exceptions

    This is a JSF question sort of...
    Can anybody hazard a guess why my JSF Phase Listener does not show exceptions when one gets thrown in a method within this PhaseListener?
    I am using ADF/BC and JSF/ADF Faces within JDeveloper 10.1.3.4 and deploying to iAS 10.1.3.4.
    I have not tried the same thing in an ADFPhaseListener...chiefly because I wanted a beforePhase() and an afterPhase() method to override, and Source-->Override Methods did not show these methods as being overrideable...so I just used the normal JSF Phase Listener.
    My theory is that PhaseListener is perhaps accessed by many sessions?? So it has no way to know to where its stack traces should be directed. So I guess I should use logging with some sort of general catch clause for each method...any ideas will be entertained.
    Thanks in advance.

    Here's exactly what it says:
    The beforePhase() method is called before the standard processing for a particular phase is
    performed, while the afterPhase() method is called after the standard processing has been
    completed. The JSF implementation must guarantee that, if beforePhase() has been
    called on a particular instance, then afterPhase() will also be called, regardless of any
    Exceptions that may have been thrown during the actual execution of the lifecycle phase. For
    example, let’s say there are three PhaseListeners attached to the lifecycle: A, B, and C, in
    that order. A.beforePhase() is called, and executes successfully. B.beforePhase()
    is called and throws an exception. Any exceptions thrown during the beforePhase()
    listeners must be caught, logged, and swallowed. In this example, C.beforePhase()
    must not be called. Then the actual lifecycle phase executes. Any exceptions thrown during
    the execution of the actual phase must not be swallowed. When the lifecycle phase exits, due
    to an exeception or normal termination, the afterPhase() listeners must be called in
    reverse order from the beforePhase() listeners in the following manner.
    C.afterPhase() must not be called, since C.beforePhase() was not called.
    B.afterPhase() must not be called, since B.beforePhase() did not execute
    successfully. A.afterPhase() must be called. Any exceptions thrown during the afterPhase()
    listeners must be caught, logged, and swallowedJohn

  • Hi how to use phase listener in jsf

    hi
    i have a scenariao were the data have to fetched form database before the page gets loaded . so i came abt phase listeners . so can anybody give some example for phase listener.....
    thanks

    This is just basic Java knowledge, but anyway ..public class SomeClass {
        static {
            // static initialization block, this is executed only once per runtime, before the first instantiation.
            // Initialization block, this is executed before the constructor on every instantiation.
        public SomeClass() {
            // the constructor, this is executed on every instantiation.
    }

  • What are the steps to define a phase listener in JSF 1.1?

    Hello everyone...
    Implementing a page listener in JSF 1.2 (the one that comes with JDeveloper 11g) is very straight forward, you implement the methods getPhaseID, beforePhase,afterPhase, and then add the class into the JSF configuration file. It works like charm.
    However, doing the same thing with JDeveloper 10.1.3.4 (it comes with JSF 1.1) never works... so I was wondering... Am I missing something? What are the correct steps to do it?
    thanks in advance.

    Dear Mr. John...
    thanks for your kind reply... however, I already was able to implement the Phase Listener successfully in JDeveloper 11g with JSF 1.2 specs. And it works just fine...
    what am I asking is that I am doing exactly the same steps under JDeveloper 10.1.3.4 under JSF 1.1 specs, but it does not work at all... so what is the problem? any idea?
    best regards

  • How do I set a Phase Listener to only run for a specific page?

    How do I set a Phase Listener to only run for a specific page?
    I understand that a Phase Listener runs for ever page in the application, however I want a phase listener to only run for one page at the beginning of the application.
    I discovered I can't use a Filter, because the JSF Application instance always returns null.
    Thus, I thought a Phase Listener would be a good approach.
    Thoughts?
    Thanks,
    --Todd                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    I have moved forward with checking the requested URI...
    (shivers)
    Thanks,
    --Todd                                                                                                                                                                                   

  • Trouble with Phase Listener?

    I am having a problem getting my page beans' "init", "preprocess" and "prerender" methods to fire. My page beans are inherited from "com.sun.jsfcl.app.AbstractPageBean" which do have these methods defined. From what I've found, it appears that my problem is a lack of a "phase-listener" in my faces-config.xml file. How should this be configured? If I put in:
    <lifecycle>
    <phase-listener>com.sun.jsfcl.app.AbstractPageBean</phase-listener>
    </lifecycle>
    I get an error that the phase listener can't be instantiated (which makes sense, it is abstract). How do I configure my application so that the "init", "preprocess" and "prerender" methods fire?
    Thanks,
    Lonnie

    I have absolutely no idea what you're talking about. This is not JSF specific.
    Maybe you're using some additional JSF component library which offers this stuff. I guess that it is Woodstock again. In any way, you should consult the documentation which come along with the component library for answers on this kind of questions.

  • Obtaining the current JSF Phase

    Hi all,
    One of the ways to obtain the current JSF phase is by implementing a phase listener. However, I would like to know if there are any simpler ways to obtain the current JSF phase that my code is executing in. For example, I would like to know what phases my getters for my beans is executed in. So, every time when my getters for my beans are executed, I would like to know what phase it gets executed in.
    Thanks,
    Mun Wai

    I am using phasetracker to trace it also.I want to know whether it is it render response phase. I know FacesContext.getCurrentInstance().getRenderResponse() work for normal jsf component but it will not work for qiupukit datatable. FacesContext.getCurrentInstance().getRenderResponse() will not return true in the following phase. Why?
    [ INFO] 27-11-07 16:20:21 : BEFORE RENDER_RESPONSE(6) (http-80-Processor23)
    I want the 'get' method of datatable being called in response phase to reduce the number of calling because i put the query in 'get' method there. Actually i still straggling with the best practice to code the datatable...

  • JSF Phase listeners

    What is a phase listener? Will every request goes through these phase listeners?

    With a PhaseListener you can hook on one or more phases of the JSF lifecycle. Useful if you want to do some handlings before or after a certain phase. Only a request which is been passed through the FacesServlet will go through the PhaseListener.
    You can see them like as a javax.servlet.Filter specific for JSF.

  • How to get the current JSF phase in backing bean?

    How to get the current JSF phase in backing bean?
    Edited by: jimmy6 on Nov 27, 2007 7:27 AM

    I am using phasetracker to trace it also.I want to know whether it is it render response phase. I know FacesContext.getCurrentInstance().getRenderResponse() work for normal jsf component but it will not work for qiupukit datatable. FacesContext.getCurrentInstance().getRenderResponse() will not return true in the following phase. Why?
    [ INFO] 27-11-07 16:20:21 : BEFORE RENDER_RESPONSE(6) (http-80-Processor23)
    I want the 'get' method of datatable being called in response phase to reduce the number of calling because i put the query in 'get' method there. Actually i still straggling with the best practice to code the datatable...

  • Phase Listener in Subsystem deployed as BTF in Master - jdev 11.1.2.3

    Hello:
    We are using Subsystems with BTF's that are deployed as ADFLibs. These Subsystem ADFLibs are imported into a Master app and the BTF's are used as a region in the Master.
    I tried to create Phase Listener that displays System.out.println msgs in the Subsystem that was then used as a region in the Master app.
    But no messages from the Phase Listener appear on the console. What am I missing? Would the Phase Listeners have to be in the Master app?
    What if I wanted the Phase Listener of just the subsystem? Is this possible?
    Below is the code for adf-settings.xml and java class that implements PagePhaseListener:
    <?xml version="1.0" encoding="UTF-8" ?>
    <adf-config xmlns="http://xmlns.oracle.com/adf/config">
    <adfc-controller-config xmlns="http://xmlns.oracle.com/adf/controller/config">
    <lifecycle>
    <phase-listener>
    <listener-id>myListener</listener-id>
    <class>com.xxxx.labs.madison.ptnr.phase.listener.MyPagePhaseListener</class>
    </phase-listener>
    </lifecycle>
    </adfc-controller-config>
    </adf-config>
    package com.xxxx.labs.madison.ptnr.phase.listener;
    import javax.faces.application.FacesMessage;
    import javax.faces.context.FacesContext;
    import oracle.adf.controller.v2.lifecycle.Lifecycle;
    import oracle.adf.controller.v2.lifecycle.PagePhaseEvent;
    import oracle.adf.controller.v2.lifecycle.PagePhaseListener;
    public class MyPagePhaseListener implements PagePhaseListener {
    public MyPagePhaseListener() {
    super();
    public void afterPhase(PagePhaseEvent pagePhaseEvent) {
    System.out.println("inside afterPhase="+pagePhaseEvent.getPhaseId());
    System.out.println("getDebugValue="+pagePhaseEvent.getDebugValue());
    if (pagePhaseEvent.getPhaseId() == Lifecycle.PREPARE_RENDER_ID) {
    System.out.println("Lifecycle.PREPARE_RENDER_ID="+pagePhaseEvent.getDebugValue());
    FacesContext fctx = FacesContext.getCurrentInstance();
    String viewId = fctx.getViewRoot().getViewId();
    FacesMessage message = new FacesMessage("Hello Page no " + viewId);
    fctx.addMessage(null, message);
    public void beforePhase(PagePhaseEvent pagePhaseEvent) {
    System.out.println("inside beforePhase="+pagePhaseEvent.getPhaseId());
    System.out.println("getDebugValue="+pagePhaseEvent.getDebugValue());
    }

    First, ensure the phase listener is working in the subsystem app.
    Second, after the master app consumes the child app (as adflib), define the phase listener in the web.xml (within the masterapp).
    face-config and taskflow config files are combined but i dont think its the same case for web.xml.

  • Using Sun JSF in JBoss-4.0.5GA

    Using Sun JSF
    1. In $JBOSS_HME/server/server-name/deploy/jbossweb-tomcat55.sar/conf/web.xml, comment out the following lines (line 243 - 247)
    <init-param>
      <description>MyFaces tlds</description>
      <param-name>tagLibJar0</param-name>
      <param-value>jsf-libs/myfaces-impl.jar</param-value>
    </init-param>2. Delete all the files under $JBOSS_HME/server/server-name/deploy/jbossweb-tomcat55.sar/jsf-libs and remove jsf-libs subdirectory.
    3. Copy the jstl.jar and standard.jar files from the $CREATOR_INSTLL_DIR/enterprise1/config/TagLibraries/JSTL11 directory to $JBOSS_HME/server/server-name/deploy/jbossweb-tomcat55.sar/.
    Since the above steps removed MyFace completely, you should not add
    <listener>
      <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
    </listener>in your web.xml any more.
    Calling EJBs from Web modules
    1. Wrap all the JAR and WAR files in an EAR file.
    2. Do not put any utility JAR file except JDBC Drivers under $JBOSS_HME/server/server-name/lib/; otherwise, you could see �classloader violation�.
    3. To share the utility JAR between the EJBs and the Web modules, put it in the EAR file and declare the utility JAR in META-INF/application.xml as follows,
    <?xml version="1.0" encoding="UTF-8"?>
    <application version="1.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
      <description>Application description</description>
      <display-name>whatever</display-name>
      <module>
        <java>webUtils.jar</java>
      </module> 
      <module>
        <web>
          <web-uri>your.war</web-uri>
          <context-root>/yourURL</context-root>
        </web>
      </module>
      <module>
        <ejb>ejb1.jar</ejb>
      </module>
      <module>
        <ejb>ejb2.jar</ejb>
      </module>
    </application>4. Modify $JBOSS_HME/server/server-name/deploy/jbossweb-tomcat55.sar/META-INF/jboss-service.xml. Change <attribute name="Java2ClassLoadingCompliance">false</attribute> to true and <attribute name="UseJBossWebLoader">false</attribute> to true. The default configuration uses different classloaders to load EJB files and WAR file, thus does not allow the Web module to call any EJB.
    Message was edited by:
    xyli33
    Message was edited by:
    xyli33

    I got it working, thanks a lot to you guys.
    yes, the problem was because of the myfaces jars in the JBoss. dj had pointed this in his reply earlier but i couldnt not get it working at that time (not sure why). so after i got prasanths reply this is what i did:
    1) re-installed a clean copy of JBoss 4.0.4RC1 using the jar installer
    (Note: if you just use the unzip and copy method, the ejb 3 won't work by default)
    2) deleted the <jboss_home>/server/default/deploy/jbossweb-tomcat55.sar/jsf-libs folder.
    3) comment out this portion in <jboss_home>/server/default/deploy/jbossweb-tomcat55.sar/cong/web.xml
    <init-param>
    <description>MyFaces tlds</description>
    <param-name>tagLibJar0</param-name>
    <param-value>jsf-libs/myfaces-impl.jar</param-value>
    </init-param>
    4) deleted the tmp, log and data folders under <jboss_home>/server/default
    directory (these were there, because i did a test start and stop)
    5) Started JBoss
    6) Deployed JSF application from JDeveloper.
    and it worked fine.
    ==>For newbie's --> watch out the the url pattern in the web.xml file created by JDeveloper if you get error : FacesContext not Found
    <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    Now, I want to get my EJB 3.0 working in JBoss which I created in JDeveloper and is working fine in OC4J but when i deploy to JBoss, it won't work. I will post a new thread for that in detail.
    thanks once again

  • Popup + before phase listener + commandlink issue

    All,
    I have a before phase listener configured on a page to open a popup and it works pretty well i.e. the popup gets opened when the page is loaded. Now i want to show the same popup when the user clicks on the commandLink. So i configured the commandLink to have a showPopupbehaviour as its child. The issue is when i click on the command link the popup is not getting opened. However if i remove the call to the before phase listener (), the popup is getting invoked from the command link.
    Please advice whats wrong in this case ? Ideally both should be working independently.
    I tried setting the immediate and auto submit also but no effect.
    thnks
    Jdev 11.1.1.5

    Hi,
    using af:showPopupBehavior issues a request to the server, which then also is handled by your phase listener. So you need to add some logic to your phase listener to not process its action when the command button is pressed. You can e.g. set the command button to partialSubmit = true and then check if the request is a partial request AdfContext.getCurrentInstance().isPartialRequest(facesContext) This way the phase listener opens the popup when a page loades but no longer after.
    Frank

  • How to get an event programmatically from a phase listener

    Hi all,
    does anyone know how I can get the component which generated the postback from a phase listener? I need this information because, in my application, I need to log into the database all the buttons and/or options the user clicked.
    Thanks in advance,
    Monique

    Best what you can do is to get all map keys of the ExternalContext#getRequestParameterMap(), those are client ID's of the input elements involved in the form submit, then use UIViewRoot#findComponent() to get the component by client ID and finally determine if it is an instance of UICommand.

  • Doubts abour JSF proccesing lifecycle and JSF phases

    Hi,
    I have doubts about the processing lifecycle of a JSF application if there are two different requests from the same user. For example, suppose an application with two buttons:
    Button 1 --> A load button connected to a actionListener method that load a lot of data from data base that will be showed in a table.
    Button 2 --> A Cancel button with immediate=true and connected to a action method that force a navigation to the same page when is pressed.
    Suppose the following sequence:
    1 -. User press button 1, I think that the following phases are executed:
    Request View --> Apply Request Values --> Proccess Validation --> Update model Values --> Invoke Application (in this phase the actionListener method is executed to load the data from database) --> Render Response (take long time)
    2-. Due to a big quantity of data the Render Response take long time and when the lifecycle is in that phase the user press the button 2. I suppose that the following sequence of phases are executed:
    Request View --> Apply Request Values -->Invoke Application (Action method that return a navigation case) --> Render Response (Render the page to the user)
    My question is, if the first request is in the Render Response phase, what happens with this phase when the second request generated by the Button 2 arrive to the server??? When the second request arrive to the server, JFS automatically cancel or stop the proccesing of the Render Response of the first request ?
    Thank you for your knowledge.

    It's always helpful to configure a "debugging" lifecycle listener that just prints out each lifecycle phase, so you can tell which phases are being executed, and in which phase some breakpoint is hit.
    This is as simple as:
    package tabpanelbug;
    import javax.faces.event.PhaseEvent;
    import javax.faces.event.PhaseId;
    import javax.faces.event.PhaseListener;
    public class LifeCycleListener implements PhaseListener
        public void beforePhase(PhaseEvent event)
        { System.out.println("BeforePhase: " + event.getPhaseId()); }
        public void afterPhase(PhaseEvent event)
        { System.out.println("AfterPhase: " + event.getPhaseId()); }
        public PhaseId getPhaseId()
        { return PhaseId.ANY_PHASE; }
    }and
    <lifecycle>
        <phase-listener>tabpanelbug.LifeCycleListener</phase-listener>
    </lifecycle>

Maybe you are looking for