Executing Method on pageload

Hello,
I'm looking for a solution to execute a method on a backing bean, when a view is loaded. Well I could workaround that with using a commandButton to link to the page and execute the method as an action handler, but that's not really an elegant solution.
Good ideas highly appreciated!
Best regards,
Timo Elverkemper

hallo little
hope u find the answer from the below desc.
phaselistener is called for every page load...
JSF PhaseListener - Is This User Logged In?
JavaServer Faces (JSF) is being touted as the next generation of web application development from the powers that be (IBM, Sun, Oracle), and has been tugging at my interest the past 8 months. In my quest to use it I quickly found myself drowning in the different complexities, but through much head to wall banging I have prevailed and would like to share some of those experiences with you through tips.
This tip shows how to register a PhaseListner at the Restore View phase of the JSF Lifecycle. The PhaseListener checks to see if the user has logged in, and if not it returns them to the login page. One could check to see if a user is logged in on each page and have code duplicated across many different backing beans, but going the PhaseListener route guards against that and allows you to have one point of checking for login credentials. To learn more about the JSF Lifecycle point your browser to http://www.javaworld.com/javaworld/jw-11-2002/jw-1129-jsf-p2.html
Figure 1 shows how to register the PhaseListener using the lifecycle and phase-listener tags. This should be placed in your faces configuration file, often named faces-config.xml.
Figure 1
<lifecycle>
<phase-listener>com.loffler.copycenter.controller.LoggedInCheck</phase-listener>
</lifecycle>
Figure 2 shows Java class LoggedInCheck implementing PhaseListener. The method getPhaseId is used to tell the PhaseListner which lifecycle phase this class should be called. In this example PhaseId.RESTORE_VIEW is used. You will have to understand the different phases to make sure a particular one fits for you. This one works in this case because it happens after backing beans have been updated form data from the web page.
Figure 2
package com.mowyourlawn.controller;
import javax.faces.application.NavigationHandler;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;
public class LoggedInCheck implements PhaseListener {
    public PhaseId getPhaseId() {
        return PhaseId.RESTORE_VIEW;
    public void beforePhase(PhaseEvent event) {
    public void afterPhase(PhaseEvent event) {
        FacesContext fc = event.getFacesContext();
        // Check to see if they are on the login page.
        boolean loginPage =
          fc.getViewRoot().getViewId().lastIndexOf("login") > -1 ? true : false;
        if (!loginPage && !loggedIn()) {
            NavigationHandler nh = fc.getApplication().getNavigationHandler();
            nh.handleNavigation(fc, null, "logout");
    private boolean loggedIn() {
        return LoginController.loggedIn().booleanValue()c;
Figure 3 shows what happens when a from-outcome of �logout� is encountered. Reference the nh.handleNavigation(fc, null, "logout"); line of code in Figure 2 to understand how the two are related. Again this should be placed in your faces-config.xml file.
Figure 3
<navigation-rule>
  <from-view-id>*</from-view-id>
    <navigation-case>
      <from-outcome>logout</from-outcome>
      <to-view-id>/login.jsp</to-view-id>
    </navigation-case>
</navigation-rule>
The above article was written by Aaron Bartell. If you have any questions
about this article, contact Aaron at mailto:[email protected].

Similar Messages

  • Using value selected in selectOneChoice as variable for execute method

    I have already created data controls for the session bean method so I can drag and drop on to the jsp. This works fine when entering the data into the input text fields but I really need the first value to come from an initial page and the second value to come from the dropdown. I just don't know how to get the value or how to connect it to the button for execution.
    The method takes two values
    value 1, org is passed in (how do I pass from another page? I will actually have the render for this input field set to false so it does not display)
    value 2, typeId from a selectonechoice drop-down list (how do I manipulate the soc to pass the information? Currently it looks as if it is just passing the elementAt number, I need get the actual value for the item selected. Where can I retrieve it?)
    I have a button ready to execute the method on the session bean which should take these values. (of course the inputvalue for the soc was not typeId but I changed it. The values for the soc are actually coming from another method performed earlier.)
    This is what I have so far:
    I have my input text field waiting on info to be populated from the previous page (currently I manually entered it)
    I have my selectonechoice populated
    A button with the execute method already set (b/c I initially used the drag-drop functionality to test my method)
    Forgive me for repeating myself so much.
    Thanks!

    Passing a value between pages:
    http://download.oracle.com/docs/cd/E15523_01/web.1111/b31973/af_lifecycle.htm#BABIHDAA
    Getting a value from a list item:
    http://www.oracle.com/technology/products/jdev/tips/mills/listvalue/listbindingvalue.html
    http://blogs.oracle.com/shay/2009/11/getting_the_value_from_a_selec.html

  • Execute() Method is undefined

    Hi all.
      I am developing a WebDynpro Application which will use a EJB for business logic. I am using a javabean as interface between EJB ane WebDynpro. I created a instance of model in webdynpro and i am trying to retrive the data from backend. But in webdynpro, while writing the execute() method, it displaying that execute() method is undefined for this type.
        Kindly give some suggessions to rectify this.

    Hello Pavan,
    Is your EJB Bean which is having execute method is in classpath ? Is those Home interface and all are in Proper place?
    Thx & Rgds
    SS

  • How can I find the source of report in the executable method= "Spawned" ?

    Dear all:
    how can I find the source of report in the executable method=>"Spawned" ?
    Regards,

    Hi,
    Please see this thread.
    To View Spawned Concurrent Program Source Code
    To View Spawned Concurrent Program Source Code
    Regards,
    Hussein

  • What are the operations we can do on incoming message in execute() method of pipeline component?

    Hi,
    Actually I am new to BizTalk and not getting idea about how to process message in execute method?
    Thanks in advance

    Hi Rocky,
    You can have any kind of processing done (logic applied) on the incoming message and produce output message and only restriction is implementation of the interfaces.
    As you are new to BizTalk, I suggest to go through following articles for better understanding and insight:
    http://blogs.msdn.com/b/brajens/archive/2006/11/25/how-to-develop-biztalk-custom-pipeline-components-part1.aspx
    http://blogs.msdn.com/b/brajens/archive/2006/12/03/how-to-develop-biztalk-custom-pipeline-components-part2.aspx
    http://tech-findings.blogspot.in/2013/10/custom-zipreceivepipeline-to-unzip.html
    Maheshkumar S Tiwari|User Page|Blog|BizTalk
    Server : How Map Works on Port Level

  • IDocumentQuery.Execute() method throws user does not have edit permissions exception

    I'm trying to query a document folder for all of its containing documents. Its a basic query like this:
    IPortletContext PortletContext = PortletContextFactory.CreatePortletContext(Request,Response);IRemoteSession PTSession;PTSession = PortletContext.GetRemotePortalSession();IDocumentManager documentManager = PTSession.GetDocumentManager();
    IDocumentQuery documentQuery = documentManager.CreateQuery(FolderID); documentQuery.SetSortProperty(ObjectProperty.Name);IObjectQuery queryResults = documentQuery.Execute();
    When I'm logged into the portal as an administrator, everything works fine. However if I'm logged in as a "regular" user, I get this exception when calling the Execute() method:
    Plumtree.Remote.PRC.PortalException: Exception of type Plumtree.Remote.PRC.PortalException was thrown. ---> System.Web.Services.Protocols.SoapException: Server was unable to process request. --> Access denied: Current user does not have edit permission
    I'm sending the Login Token to the portlet. Now I've tried giving the user Edit rights on the document folder as well as Edit the Knowledge Directory rights in the Activity Manager, but neither gets rid of the exception. I'm not sure what other "Edit" permissions to check. I don't even see why the user would need "Edit" permission to anything in the first place since the Execute() method simply returns an IObjectQuery that doesn't have any ability to make changes to any objects. I know that I could use the SearchFactory interface, but I wanted the results to be real time. Any help would be much appreciated. Thanks!
    Jimmy

    The problem here is that the query is created with default settings to show unapproved documents -- only users with edit access can see unapproved documents. Add the bold line to your code and it will work.
    IDocumentManager docManager = prcSession.GetDocumentManager();IDocumentQuery docQuery = docManager.CreateQuery(iFolderID);docQuery.SetShowUnapproved(false);IObjectQuery queryResults = docQuery.Execute()

  • PreparedStatement and execute() method

    Hi to all.
    I would like to understand a thing.
    Why the execute() method gives me back false also if the SQL instructions is well executed?
    Is this right?
    TIA
    Omar

    Returns:
    true if the first result is a ResultSet object; false if the first result is an update count or there is no result
    http://java.sun.com/j2se/1.4.2/docs/api/java/sql/PreparedStatement.html#execute()

  • How can I execute method of Component for name

    Hello,
    My program has JInternalFrame with some components. Write me please - how can I execute method of Component for name of Component ?
    Like this:
    ... findObject("jTextArea1").cut();
    Thank you in advance.

    just cycle through the container's components until
    you find one where getName equals "jTextArea1"Thank you for your answer.
    I'm creating components in runtime (I add panel+JTextArea in JTabbedPane) and I don't know how many components will be in JTabbedPane.
    I know only it's names.
    I wan't to execute metod JTextaRea_n_.cut() via using JTextaRea_n_.Name.
    How ?

  • Send a mail to manager in execute method of my eventhandler class.

    Hi everyone,
    I want send an email in execute method of my eventhandler class.
    How can I do this?
    Thanks
    Regards.

    You can use JavaMail, or tcEmailOperations and the NotificationResolver to send email notification. Not sure what help you are looking on this.
    -Bikash

  • Execute method of IWDPDFDocumentCreationContext throwing error

    Hi All
    I am using NWDS2004s SPS10
    I need to generate a pdf. I am using "IWDPDFDocumentCreationContext" Interface to create the pdf from given xml and xdp. When i use the "execute" method of the interface it throws me following error.
    webdynpro.clientserver.adobe.pdfdocument.base.core.PDFDocumentRuntimeException: PDFDocument Processor failed to process Render Request.
         at com.sap.tc.webdynpro.clientserver.adobe.pdfdocument.base.core.PDFDocumentRuntimeException.<init>(PDFDocumentRuntimeException.java:25)
         at com.sap.tc.webdynpro.clientserver.adobe.pdfdocument.base.core.PDFDocumentProcessor.process(PDFDocumentProcessor.java:55)
         at com.sap.tc.webdynpro.clientserver.adobe.pdfdocument.base.core.PDFDocumentCreationContext.execute(PDFDocumentCreationContext.java:146)
         at com.sap.tc.webdynpro.clientserver.adobe.pdfdocument.base.core.PDFDocumentCreationContext.execute(PDFDocumentCreationContext.java:170)
         at com.sap.tc.webdynpro.clientserver.adobe.pdfdocument.impl.PDFDocumentCreationContextWDImpl.execute(PDFDocumentCreationContextWDImpl.java:94)
    Please help.
    Regards
    Sonal Mangla

    Hi Deepak
    We are getting exactly the same error. We have also created OSS message for the same.
    It would really help if you can post the solution.
    Thanks & Regards
    Rupesh

  • Execute Method must not return a resultSet

    Hi.
    I am using DataModifyQuery to insert a record in MS SQL. On that Table there is one trigger defined whcih in turn insert data into some other table. in case there is any error the trigger return a error message.
    When i execute the Sql with DataModifyQuery and there is a error return from the trigger then Toplink gives me a error message.
    Execute Method must not return a resultSet
    how can i over come this sistuation.
    Thanks.

    Nadir wrote:
    I was lost. Right, there was no return statement. Below works now
    public String getIPAddress(){
    String hostip = "";
    try {
    hostip = InetAddress.getLocalHost().getHostAddress();
    System.out.println("ip is "+hostip);
    } catch (UnknownHostException e) {
    hostip = e.getMessage();
    return hostip;
    -----It compiles. I wouldn't say it works. If I call a method getIPAddress(), I expect the String I get back to be an IP address. I don't want to have to parse it to determine that it's not an error message. That defeats the whole purpose of the exception mechanism. If that method can't get the IP address, it should throw an exception. In this case, there's no reason to catch the exception; just let it propagate up out of that method.
    Beginners often seem to think that exceptions are something that just arose on their own out of the language, and the designers had to add try/catch in order to be able to stop them from preventing our code executing. That's not the case. They were deliberately added to the language as a better way of indicating an error than checking return values at every step.

  • Execute method is undefined for Request_ZBpProjectGetlist2.

    I created a webservice for a BAPI and imported to Web Dynpro DC using Web Service Model.
    But I am getting an error in wdContext.currentRequest_ZBpProjectGetlist2Element().modelObject().execute();
    It says Method execute() is undefined for Request_ZBpProjectGetlist2.
    Can anyone help me why the execute method is not available for webservice model...

    Hi Sridhar,
    Please check execute method available for Request_ZBpProjectGetlist2 or not.
    Organize your import and check Request_ZBpProjectGetlist2 is imported or not.
    BR
    Arun

  • How populate and execute methods gets called in UserDefined Action Classes?

    In Struts2, if we override methods populate() and execute() , then if we made any request to some Action class which overrides these methods, then how does it look for these 2 methods??
    and why populate() method called first and later execute() method????
    Harishwar
    Edited by: Harishwar_Madhya on Sep 3, 2010 2:47 AM
    Edited by: Harishwar_Madhya on Sep 3, 2010 2:49 AM

    45RPMSoftware wrote:
    Thanks for this. Alas, I do not have the source code used to generate the jar file, and I have no means of getting it. I imagine, therefore, that I will not be able to update the manifest file.The manifest file is just a simple text file.
    You can get at it by unpacking/repacking the jar file with the jar utility (tar like syntax).
    ... I assume that classpath is rather like the unix path.It specifies a list of jar files and directories containing java class files (and more).
    Is there anything that defines the classpath for each login session and, if so, how do I add to it?As the link I posted says;
    you can set a CLASSPATH env.var.

  • Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain

    Hi All,
      I have created a custom web part in VS 2008 for Share point server 2010 with DevExpress v12.2.17, and deployed as Sandboxed solution. when i add that web parts in web part zone i am getting the error as "Web Part Error:
    Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain: An unexpected error has occurred. ".
    If there is any way to get detailed error either log file or event viewer.
    Kindly advice to find the cause of the problem.
    Thanks,
    Selvakumar.S

    Hello,
    Are you impersonating your code? Have you tried to debug your code by attaching SPUCHostService.exe? if not please do so.
    You also need to check ULS log for more information about this error. Here is one ref link if this could help
    http://sohilmakwana.wordpress.com/2013/11/29/sandbox-error-unhandled-exception-was-thrown-by-the-sandboxed-code-wrappers-execute-method-in-the-partial-trust-app-domain/
    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • MDMJavaAPI: Execute() method is not running.

    Hi Gurus,
    I am trying to delete the repository using MDMJavaAPI.
    Here is the whole code for deleting repository.
    =============================================import com.sap.mdm.commands.AuthenticateRepositorySessionCommand;
    import com.sap.mdm.commands.CommandException;
    import com.sap.mdm.commands.CreateRepositorySessionCommand;
    import com.sap.mdm.commands.DestroySessionCommand;
    import com.sap.mdm.net.ConnectionException;
    import com.sap.mdm.net.ConnectionPool;
    import com.sap.mdm.net.ConnectionPoolFactory;
    import com.sap.mdm.repository.RepositoryStatus;
    import com.sap.mdm.repository.commands.DeleteRepositoryCommand;
    import com.sap.mdm.repository.commands.GetRepositoryStatusCommand;
    import com.sap.mdm.server.DBMSType;
    import com.sap.mdm.server.RepositoryIdentifier;
    @author tarunsha
    To change the template for this generated type comment go to
    Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
    public class TestDeleteRepository {
                        public static final int STATE_NOT_CONNECTED = 0;
                        public static final int STATE_CONNECTED = 1;
                        public static int state = STATE_NOT_CONNECTED;
                        public static ConnectionPool simpleConnection;
                        public static RepositoryIdentifier repIdentifier;
                        public static String session;
                        public static String connection = "ntbomsap14";
                        public static String repository = "Test_JavaMDMapi_Tarun";
                        public static DBMSType dbmsType = DBMSType.MS_SQL;
                       public static void main(String[] args)throws CommandException, ConnectionException {
                       //Creating Connection.
                       simpleConnection = ConnectionPoolFactory.getInstance(connection);     
                       //Establishing connection with Repository.
                       repIdentifier = new RepositoryIdentifier("Test_JavaMDMapi_Tarun", connection, dbmsType);
                       //Creation Repository Session.
                       CreateRepositorySessionCommand createRepositorySessionCmd = new CreateRepositorySessionCommand(simpleConnection);
                       createRepositorySessionCmd.setRepositoryIdentifier(repIdentifier);
                       createRepositorySessionCmd.execute();
                       System.out.println("Create Repository Session Cmd is Executed.......");
                       session = createRepositorySessionCmd.getRepositorySession();
                       System.out.println("STATE_CONNECTION_ESTABLISHED.....");
                       AuthenticateRepositorySessionCommand authenticateRepositorySessionCmd = new AuthenticateRepositorySessionCommand(simpleConnection);
                       authenticateRepositorySessionCmd.setSession(session);
                       authenticateRepositorySessionCmd.setUserName("Admin");
                       authenticateRepositorySessionCmd.setUserPassword("");
                       authenticateRepositorySessionCmd.execute();
                        session = authenticateRepositorySessionCmd.getSession();
                        GetRepositoryStatusCommand getRepStatusCmd = new GetRepositoryStatusCommand(simpleConnection);
                        getRepStatusCmd.setSession(session);
                       getRepStatusCmd.execute();
                        RepositoryStatus repStatus = getRepStatusCmd.getStatus();  
                        if(repStatus.getStatus() == RepositoryStatus.RUNNING) {
                        System.out.println("Cannot delete a repository with status running! Canceling deletion process...");
                        destroy(session);     
                      DeleteRepositoryCommand deleteRepCmd = new DeleteRepositoryCommand(simpleConnection); deleteRepCmd.setRepositoryIdentifier(repIdentifier);     
                      deleteRepCmd.setSession(session);
                      // Excute the command...
                      System.out.println("Running");//Just for checking wheather control is reaching here or not.
                    deleteRepCmd.execute();
         System.out.println("Execution of DeleteRepositoryCommand successful.");
                      destroy(session);
                      public static void destroy(String session) throws CommandException{
                                  DestroySessionCommand destroySessionCmd = new DestroySessionCommand(simpleConnection);
                                  destroySessionCmd.setSession(session);
                                  destroySessionCmd.execute();
                                  session = null;
                                  System.out.println("STATE CONNECTION is DESTROYED......");
    =============================================
    When control reaches at execute method of DeleteRepositoryCommand class, it displays the following error msg.
    com.sap.mdm.commands.CommandException: com.sap.mdm.internal.protocol.manual.ServerException: The current Protocol operation is not supported for the session specified.
    *     at com.sap.mdm.repository.commands.DeleteRepositoryCommand.execute(DeleteRepositoryCommand.java:69)*
    *     at Test_Package.TestDeleteRepository.main(TestDeleteRepository.java:85)*
    Caused by: com.sap.mdm.internal.protocol.manual.ServerException: The current Protocol operation is not supported for the session specified.
    *     at com.sap.mdm.internal.protocol.manual.AbstractProtocolCommand.execute(AbstractProtocolCommand.java:112)*
    *     at com.sap.mdm.repository.commands.DeleteRepositoryCommand.execute(DeleteRepositoryCommand.java:64)*
    *     ... 1 more*
    Exception in thread "main"
    Could you suggest me, what i have to do in this situation.
    I need your help.
    Edited by: Tarun Sharma on Jan 2, 2008 5:46 PM
    Edited by: Tarun Sharma on Jan 2, 2008 5:50 PM
    Edited by: Tarun Sharma on Jan 3, 2008 11:32 AM

    Hi Namrata,
    If we are deleting an repository, it means we are making connection with repository that's why we have to createRepositorySession rather than serverSession.
    According to this JavaDoc note:
    "NOTE: This command used to take in a repository session. This command had be changed to take in a server session. The setRepositoryIdentifier is also required."
    the method setRepositoryIdentifier is defined in CreateRepositorySessionCommand not in ServerSessionCommand. That's why we have to use RepositorySessionCmd.
    According to your advice I changed CreateRepositorySessionCommand and AuthenticateRepositorySessionCommand with ServerSessionCommand and AuthenticateServerSessionCommand but getting Same Error "The current Protocol operation is not supported for the session specified."
    Thanks
    Tarun
    Edited by: Tarun Sharma on Jan 3, 2008 10:44 AM

Maybe you are looking for

  • Access to istore causes blue screen crash

    I am running an ipod and itouch - PC is Windows XP. With the newest version of itunes, everything works fine between itunes on the PC and the devices, EXCEPT trying to access the store for music or podcasts. I see the headings of the store displayed,

  • Deployment Progress Monitor

    Once I start the application using "Debug" or "Run", the Deployment Progress Monitor will show the messages: "Starting Application" ... "asadmin -start-domain ...." and then this status window will be kept open even with "Automatically close" set. As

  • Request for cookbook on Mobile SERVICE Application

    Hi, I've been trying to get some technical docs for Mobile SERVICE, but I couldn't. I'm new to Mobile Service CRM, and have just started to support CRM mobile client SERVICE application. I have downloaded some related documents from SAP, but if you h

  • Macbook Air or Macbook Pro? What do you think?

    I am currently in my last year of high school and will be off to university next year. I am thinking of getting a Mac but i'm not sure which one. I am just wondering if what do you guys think? Macbook Air or the Pro one? I will be mostly using it for

  • Cats name

    my ipad is disable please help unlock