How to avoid @PostConstruct on page Faces beans during postback?

Hello, we're using GlassFishV2/JSAS9.1 with Mojarra 1.2_04-b22-p05 for a large project, and experiencing performance issues on form-less JSF commands when used in conjonction with @PostConstruct annotations. I feel this is an architectural issue I'm not able to resolve though, so I was wondering if anyone could shed some light on whether I'm missing something, there is some known workaround or it's a known JSF problem?
The scenario is as follows:
* Page my.jsp references Faces Beans MyFB.java
* MyFB has @PostContruct method, which execute expensive logic to initialize the data model before rendering phase
* my.jsp has a <commandLink action="#{anotherFB.myCommand}">
* anotherFB.myCommand executes some logic and nav to another.jsp
Now what seems to happen is that when we click on the commandLink, JSF does a postback to the same URL, instantiates MyFB, calls @PostConstruct on MyFB, and then instantiate anotherFB to call myCommand on it and nav to another.jsp
In this situation, the expensive @PostConstruct logic to prepare data for rendering on my.jsp is executed although it is totally useless to the use case and hurts site performance a lot.
I tried to use immediate="true" attribute, but it doesn't seem to prevent the @PostConstruct...
In the case of a JSF form commandButton on the same bean, I can see how that would be necessary, but for a commandLink to another bean, why is JSF calling @PostConstruct on the previous page beans??
I seem to be able to workaround this problem doing an if (getFacesContext().getRenderKit().getResponseStateManager().isPostback(getFacesContext()) in our @PostConstruct method and then make sure all the getters are NPE-safe, but if the commandLink is in a common include file, I'd then have to do this in every single beans within my app, which is not reasonable IMHO.
Has anyone else experienced this problem? Or even maybe worked around it somehow?
I'm curious if I'm missing something or if this is a major JSF architectural issue...
Thanks!

Thanks for the suggestion.
We used to do this in the past, but this yields a host of other issues including:
* no control over when getters get called and in what order
* getters can get called multiple times, so you have to implement some caching to avoid init re-execution and it can get complicated in large object models
* if a getter implements logic and blows up in the rendering phase, part of the page may have already been flushed out and you can't recover with an error page
etc.
@PostConstruct is a great standard-based option to get a bean initialized early in the JSF lifecycle, but there's just this one issue with commandLink that's problematic... :(
We're sometimes using Shale's prerender callback, which is not invoked on a postback, but I was hoping there was maybe a standard-based solution?

Similar Messages

  • How to avoid submitting a page when tabular form rows are empty

    Hi,
    I have a master detail form in my application. There are 2 tables that are used Table A and Table B. Table A contains Ticket number and Table B refers to Table A through a foriegn key and Table B have columns like Date,Name, Age, ticket_id (that refers to the ticket_number of the Table A).
    This is how the application works:
    In a page there is a field for Ticket Number, once the user enters the Ticket Number and click Add Details, a tabular Form with 5 empty field appears... (Done through Page Process->Data Manipilation->Add Rows)
    This form contains fields Date, Name and Age. Once the user fills in all the details and click Submit button, the page is submitted. Whatever values that was entered is saved in Table B. Page Sucess message appears. This works fine.
    But once the Ticket Number is entered and Add Details is clicked, and without entering the values in the Tabular Form, if Submit button is clicked, there is no error showing up neither I see Page success message. But this should not be allowed. There should be some error showing up...
    Tabular Form Validations works only when user enters some values in the Tabular Form and click Submit. For the above scenario, where the form is untouched the validation doesnt work.
    How can I get this done? Any ideas?

    Hello Suzi,
    >> if (document.wwv_flow==null)
    The document.wwv_flow is an object representing the current form that was just rendered on your screen. As such, it can never be null.
    >> How to avoid submitting a page when tabular form rows are empty
    The correct way, especially for versions prior to APEX 4.0 is to use JavaScript, but for that, you need to know and understand how APEX generates your tabular form, HTML wise.
    To be very brief, APEX attached a unique ID to every updatable cell in the tabular form, using a certain pattern – each updatable column is getting a unique name (e.g. ‘f01’,’f02’ etc.) and the ID of a cell is a combination of this name with the serial row number the cell is on. For example, a cell on the third row in an updatable column called ‘f04’ will be given an ID of f04_0003. (More detailed explanation, with an example, can be found in my book).
    What you should do is to check these cells according to your validation policy (e.g. is all five row must be filled, is all the columns in a specific row must be filled, etc.).
    Regards,
    Arie.
    &diams; Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all.
    &diams; Author of Oracle Application Express 3.2 – The Essentials and More

  • How to avoid Invalidation of Stateful Session Bean in case of an Exception?

    Hi developers,
    I'm working on a project using JSF, Toplink and EJB 3.0 using JDev.
    I'm using a statefull session bean that is stored in the session but when an exception occurs in a business method in the stateful bean the bean crashed and can never be reused and returns the following trace :
    06/06/05 10:19:12 java.rmi.NoSuchObjectException: Session has timed out or was invalidated
    06/06/05 10:19:12      at com.evermind.server.ejb.StatefulSessionEJBObject.throwPassivisationException(StatefulSessionEJBObject.java:335)
    06/06/05 10:19:12      at com.evermind.server.ejb.StatefulSessionEJBObject.OC4J_transactionPreExecute(StatefulSessionEJBObject.java:717)
    06/06/05 10:19:12      at com.evermind.server.ejb.interceptor.system.TxRequiredInterceptor.invoke(TxRequiredInterceptor.java:51)
    06/06/05 10:19:12      at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:69)
    06/06/05 10:19:12      at com.evermind.server.ejb.interceptor.system.DMSInterceptor.invoke(DMSInterceptor.java:52)
    06/06/05 10:19:12      at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:69)
    06/06/05 10:19:12      at com.evermind.server.ejb.StatefulSessionEJBObject.OC4J_invokeMethod(StatefulSessionEJBObject.java:840)
    06/06/05 10:19:12      at PriseChargePS_StatefulSessionBeanWrapper21.trouverAssure(PriseChargePS_StatefulSessionBeanWrapper21.java:1747)
    06/06/05 10:19:12      at Pensions.Traitements.AssureTraitement.donnerAssure(AssureTraitement.java:130)
    06/06/05 10:19:12      at Pensions.view.backing.priseCharge.PriseCharge.chercherAssure_action(PriseCharge.java:189)
    06/06/05 10:19:12      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    06/06/05 10:19:12      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    06/06/05 10:19:12      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    06/06/05 10:19:12      at java.lang.reflect.Method.invoke(Method.java:585)
    06/06/05 10:19:12      at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:126)
    06/06/05 10:19:12      at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:72)
    06/06/05 10:19:12      at javax.faces.component.UICommand.broadcast(UICommand.java:312)
    06/06/05 10:19:12      at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
    06/06/05 10:19:12      at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
    06/06/05 10:19:12      at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
    06/06/05 10:19:12      at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
    06/06/05 10:19:12      at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
    06/06/05 10:19:12      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
    06/06/05 10:19:12      at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:64)
    06/06/05 10:19:12      at oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl._invokeDoFilter(AdfFacesFilterImpl.java:367)
    06/06/05 10:19:12      at oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl._doFilterImpl(AdfFacesFilterImpl.java:336)
    06/06/05 10:19:12      at oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl.doFilter(AdfFacesFilterImpl.java:196)
    06/06/05 10:19:12      at oracle.adf.view.faces.webapp.AdfFacesFilter.doFilter(AdfFacesFilter.java:87)
    06/06/05 10:19:12      at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:629)
    06/06/05 10:19:12      at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:376)
    06/06/05 10:19:12      at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:870)
    06/06/05 10:19:12      at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:451)
    06/06/05 10:19:12      at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:218)
    06/06/05 10:19:12      at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:119)
    06/06/05 10:19:12      at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
    06/06/05 10:19:12      at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
    06/06/05 10:19:12      at oracle.oc4j.network.ServerSocketAcceptHandler.procClientSocket(ServerSocketAcceptHandler.java:230)
    06/06/05 10:19:12      at oracle.oc4j.network.ServerSocketAcceptHandler.access$800(ServerSocketAcceptHandler.java:33)
    06/06/05 10:19:12      at oracle.oc4j.network.ServerSocketAcceptHandler$AcceptHandlerHorse.run(ServerSocketAcceptHandler.java:831)
    06/06/05 10:19:12      at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
    Please help !

    Your question is not how to create/compile a stateless session bean, you are asking how to use those weblogic specific annotations. A weblogic forum is a better place to ask that.

  • How to avoid printing a page if does not contain data in smart forms

    deat all,
    here is urgent requirement for me .
    i have 3 pagelayouts in smartforms.
    if there is no data in page 2 how to avoid it from printing(the second page should not come in even if it contains hedings and logo)

    try like this
    if@section:IND=1
    this template
    end ifsectionbreak
    if@section:IND=2
    this template
    end if

  • How to avoid starting a page with line breaks?

    Hello. I've just started to refine my Master's thesis and some of the topics moved up and down as I edited their contents. The problem is that in some cases the topic breaks right after the title, and the rest of the contents just move away to another page. Is there any way to avoid starting a page with line breaks or broken topics?

    At the end of your title, you didn't inserted a line break but a paragraph break (carriage return).
    Acivate the mode "Show hidden characters"
    Select the carriage return (paragraph break)
    Delete it
    Press Shift + return to insert a true line break.
    It may be useful to apply that several times if you inserted several carriage returns between the title and the first filled line.
    Yvan KOENIG (VALLAURIS, France) 15 mai 2011 19:40:14

  • How to avoid present 302 page

              Hi,
              In my app, I use jsp with servlet, and the servlet acts as the "traffic cop",
              that is, the users fill up the form in jsp pages, and the jsp pages are submitted
              (post) to this servlet, this servlet do some work and get the next jsp page to
              present, and use response.sendRedirect(page). The problem is the "sendRedirect"
              method, some user complain that they submit the form and got a page says "The
              document you reqested has moved temporarily" and there is a link, after the user
              clisk the link, it got the right page.
              I checked the log file, the form post returns 302 code, and the next page (redirected
              by sendRedirect method) is invoked as GET and returns 200.
              I thought about the forward, but the images in the jsp all has relative path,
              so the call will be /myservelt/images/...gif. That doesn't work.
              what can I do to avoid the problem and send the page directly?
              Thanks
              

              Thanks. I still can't have a good idea how to deal with. By reading it I may set
              the status code to 303 and get the post to be auto redirected, but this is the
              http1.1 new feature, I don't know what's the percentage of browsers support http1.1.
              I am assuming the older version browsers is for http1.0
              "Deepak Vohra" <[email protected]> wrote:
              >
              >For status codes refer to
              >http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/Servlet-Tutorial-Response-Status-Line.html
              >
              >
              >"John" <[email protected]> wrote:
              >>
              >>Hi,
              >>
              >>In my app, I use jsp with servlet, and the servlet acts as the "traffic
              >>cop",
              >>that is, the users fill up the form in jsp pages, and the jsp pages
              >are
              >>submitted
              >>(post) to this servlet, this servlet do some work and get the next jsp
              >>page to
              >>present, and use response.sendRedirect(page). The problem is the "sendRedirect"
              >>method, some user complain that they submit the form and got a page
              >says
              >>"The
              >>document you reqested has moved temporarily" and there is a link, after
              >>the user
              >>clisk the link, it got the right page.
              >>
              >>I checked the log file, the form post returns 302 code, and the next
              >>page (redirected
              >>by sendRedirect method) is invoked as GET and returns 200.
              >>
              >>I thought about the forward, but the images in the jsp all has relative
              >>path,
              >>so the call will be /myservelt/images/...gif. That doesn't work.
              >>
              >>what can I do to avoid the problem and send the page directly?
              >>
              >>Thanks
              >
              

  • How to avoid Moved Temporarily page

    Hi,
    In my app, I use jsp with servelet, and the servelet acts as the "traffic cop", that is, the users fill up the form in jsp pages, and the jsp pages are submitted (post) to this servelet, this servlet do some work by calling other helper class and get the next jsp page to present, and use response.sendRedirect(page). The problem is the "sendRedirect" method, some user complain that they submit the form and got a page says "The document you reqested has moved temporarily" and there is a link, after the user clisk the link, it got the right page, and do another submit for next step, the same thing happed aggain.
    I checked the log file, the form post returns 302 code, and the next page (redirected by sendRedirect method) is invoked as GET and returns 200.
    what can I do to avoid the problem some user has by presenting the page directly?
    Thanks

    If you use "forward" instead of "redirect" that won't happen. It might even be a better design, since redirecting displays a URL in the browser's address bar that the client can use to go directly to the JSP instead of through your traffic cop.

  • How to avoid a blank page at end of the page?

    Hi Experts,
    I have created a smartform where i need to display the line items based on the customer data.
    I have created a command at the end of the loop. For every new customer it has to go to new page. After the completion of the report i'm getting a blank page at the end.
    If i take a single customer or multiple customer, I'm getting a blank page at the end. I need to avoid this.
    Please let me know the procedure to avoid it.
    Thanks and Regards,
    Abdur Rafique

    Hi,
    Try this logic
    In the "Initialization" tab of global definitions
    DESCRIBE TABLE IT_TAB LINES W_COUNT.
    Here IT_TAB contains all the customers
    While looping IT_TAB count the records into W_COUNT_CURRENT " Current record count
    In the COMMAND give the condition
    W_COUNT_CURRENT  <> W_COUNT (Go to new page as long as current customer is not the last customer)
    For the last customer both variable will be equal and there will not be a new page.
    Note that the COMMAND must be at the end of the LOOP for this logic to work
    Regards

  • How to avoid TEST PRINT page

    Dear All,
    How to aviod the test print page in printing. I am getting SAP cover page(test print page) for every time I am printing. I ma using the following code.
      CASE sy-ucomm.
        WHEN 'PRNT'.
          DATA: l_params TYPE pri_params,
                l_valid TYPE c,
                l_arc_params TYPE arc_params.
              l_params-prsap = 'X'.
          CALL FUNCTION 'GET_PRINT_PARAMETERS'
            EXPORTING
              destination            = 'LPIN'
              copies                 = 1
             list_name              = 'TEST'
             list_text              = 'Test NEW-PAGE PRINT ON'
              immediately            = 'X'
              layout                 = 'X_65_132'
              line_count             = 65
              line_size              = 220
              release                = 'X'
              mode                   = 'CURRENT'
              no_dialog              = 'X'
            IMPORTING
              out_parameters         = l_params
              valid                  = l_valid
            EXCEPTIONS
              archive_info_not_found = 1
              invalid_print_params   = 2
              invalid_archive_params = 3
              OTHERS                 = 4.
          NEW-PAGE PRINT ON   PARAMETERS l_params NO DIALOG.
          PERFORM display_data.
          NEW-PAGE PRINT OFF.
      ENDCASE.
    Thanks,
    Ranjan

    Hi,
    Just check it out. I m printed report directly instead of display.
    w_destination = 'LOCL'.
        CALL FUNCTION 'GET_PRINT_PARAMETERS'
          EXPORTING
            destination    = w_destination
            layout         = 'X_58_170'
            no_dialog      = 'X'
          IMPORTING
            out_parameters = params
            valid          = valid.
        IF valid <> space.
    ALL DISPLAY PARAMETER RIGHT ON PRINTER
          NEW-PAGE PRINT ON PARAMETERS params NO DIALOG.
        ELSE.
    GIVE ERROR PRINTER DESTINATION IS NOT VALID
          MESSAGE s208(00) WITH text-010.
        ENDIF.
      ENDIF.
    User write stament, That will dirctly go for print.
    OFF THE PRINTING AFTER REPORT IS DISPLAY
      IF valid <> space.
        NEW-PAGE PRINT OFF.
      ENDIF.
    it may sortout ur problem.
    Regard,
    Vinod

  • How to avoid that every page of a smartform is going to be printed out

    Hi,
    I have following problem. In my smartform I builded different pages (like a cover page, different lists etc.). The user should decide by setting parameters what lists he want to print. So if he don´t need the cover page, it should not be printed out.
    Is there any way to set this up in the smartform? Right now, the printing parameters (what the user wants to print) are stored in an internal table and should be processed in the smartform. My problem is that there is no way to implement conditions on a page in a smartform.
    Please let me know if somebody has a solution for this requirement.
    Thanks a lot,
    John Caspar
    <MOVED TO CORRECT FORUM BY MODERATOR>
    Edited by: Alvaro Tejada Galindo on Apr 15, 2009 8:49 AM

    Hi Micky,
    The external debugging works. Thank you very much!
    And how can I reward you?

  • How to supress top of page in ALV during page breaks...

    Hello Experts,
    I am currently developing a report using the old ALV(REUSE_ALV_LIST_DISPLAY) since
    I need to have page breaks(using the SORT event) depending on the sort criteria. But
    I noticed that for every page break, the top of page automatically displays. I only
    need to display it one or depending on other factors.
    So how do we supress top of page event?
    Thank you guys and take care!

    Hi Viraylab,
    Try out like this ..
    1. Declare a global variable g_flag = 0.
    2. if g_flag = 1.
          top-of-page.
          your heading.....
          and default g_flag = 0.
       endif.
    3. *your Output
          Perform display.
    4. Form display.
           Your --- Code...
            g_flag = 1.
        endform.
    Regards,
    sg

  • How to avoid blank page in the report?

    adding a field in the grouping and checking the page break option means then we are getting blank page as the first page of the report? How to avoid this blank page?

    Usually blank pages appear as first page due to the presence of filler lines (//////) on top of report header.Please ensure that the top header is exactely started from top of page itself.

  • How to avoid printing a blank page when there is 'no data' in the report.

    how to avoid printing a blank page when there is 'no data' in the report.

    try like this
    if@section:IND=1
    this template
    end ifsectionbreak
    if@section:IND=2
    this template
    end if

  • Cheque printing. How to avoid last page in case of check printing in F110?

    F-68 prints only one page whereas F110 prints 2 pages.
    How to avoid last page in case of check printing using F110? Is there any other option than changing the Script.

    Hi,
    Im also facing the same issue. Generates 1 page with F-58 but 2 pages with f110. Kindly let me know how to resolve.

  • How to avoid the page to move up when I click the button on the Tableview?

    Hi, EP fellows.
    I currently have 3 tableViews and 1 header form set in one jsp page (I know, it may not be a good design to put three tableView in one jsp page.....but for the sake of avoiding client side eventing between each tableViews..I combined them into one jsp page). I set the Load/Navigation value to be URL. 
    Here is the problem. Everytimes I click on the Navigation button (Up/Down) to navigate the tableView data to another page, the whole page will move up and away from the table that I navigating.
    I know it is bacause the page get refreshed, and go to the first item of the page. In this case, how do I avaoid the page to move up and away form the tableView? As it is really look bad when user click on the button, they have to scroll back to the tableView they click.
    Thanks for advices.
    Kent

    As far as i remember,this javascript function pops user a dialog to save a file:
    javascript: document.execCommand('SaveAs','1',null);
    But i m not sure will it pop up for pdf, just try to google javascript to save a pdf file.
    --Mukul                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Maybe you are looking for

  • Open dataset......

    Hi Folks, I am trying to get some data using Open dataset.The program is not showing any errors and executing fine,but I was not able to find the data that I am going to get using OPEN DATASET.Where will I be able to see the data.In the given path th

  • Webcal and webmail where Calendar and Mail use SSL but Web does not

    I have Lion Serer 10.7.3 up and running. I have the same SSL cert in use for calendar, address book, and email, but not for web service. Calendar is running great via iCal.app and on iOS. 1.  Trying to access the webcal at http://myserver.com/webcal

  • Accessing Adapter Specific Attributes from ABAP proxy

    Hi, Now i have a scenario from where i take a file from FTP and send it to ERP by proxy. While taking the file i am taking also the file name by setting adapter-specefic message attributes -> File Name. So the file name appears inside the SOAP Header

  • Change the 'ContextUri' and ServiceUri for a web service with workshop

    Hi all, I've created a web service and its url is set by default by workshop, let's say http://myServer:7001/app/services/myWebService.jws Is there a way in workshop to modify the url, so that I can call my web service this way : http://myServer:7001

  • Nokia lumia 800 volume problem

    I can't turn my volume up or down. I think its something to do with the buttons because sometimes I can turn it up. Other times I try and it will turn it down. This does my head in as my volume is now stuck on 10/30