Execute a method before a page is displayed?

I love JSF, but I have continuously run in to a wall trying to figure out how to execute code before a page is displayed. Is there some Listener/Binding mechanism that I could tap into that would be called before Render Response?
A Phase Listener is too general, I don't want something that walks the tree for every request.
Action/ValueChange Listeners are only called after a user takes an action.
Putting calls (for example DAO) in getter methods works in some circumstances, but is fragile and is insufficient when you need to populate multiple fields on a bean but only want one (DB) call. (You can put it on the first one that will be called, but this destroys reusability).
The only sucessful strategy I have found is having an init() that returns boolean and calling it from the first <h:outputText> on the screen's render field. This is obviously a painful hack.
This is a general question, but my current scenario is a single DB lookup needs to get a list of beans before a page is displayed. (users can link directly to the page). Once the lookup is complete the list of beans is displayed in 3 seperate data tables with 3 seperate action bindings. So it doesnt really make sense to do the db lookup in one get method that populates the 2 other lists, though it would be a functional approach.
Any thoughts?

I love JSF, but I have continuously run in to a wall
trying to figure out how to execute code before a
page is displayed. Is there some Listener/Binding
mechanism that I could tap into that would be called
before Render Response? In vanilla JSF? No.
In JSFTemplating: yes.
It provides an "initPage" event which is invoked every time a page is "initialized" (which may be a long time before it is displayed). It also provides an <event> component which includes a "beforeEncode" event which is invoked during renderring.
A Phase Listener is too general, I don't want
something that walks the tree for every request. I agree.
Action/ValueChange Listeners are only called after a
user takes an action. Yep.
Putting calls (for example DAO) in getter methods
works in some circumstances, but is fragile and is
insufficient when you need to populate multiple
fields on a bean but only want one (DB) call. (You
can put it on the first one that will be called, but
this destroys reusability).Exactly.
The only sucessful strategy I have found is having an
init() that returns boolean and calling it from the
first <h:outputText> on the screen's render field.
This is obviously a painful hack.Yep.
This is a general question, but my current scenario
is a single DB lookup needs to get a list of beans
before a page is displayed. (users can link directly
to the page). Once the lookup is complete the list of
beans is displayed in 3 seperate data tables with 3
seperate action bindings. So it doesnt really make
sense to do the db lookup in one get method that
populates the 2 other lists, though it would be a
functional approach.The "events" I mentioned above for JSFTemplating allow any # of parameterized "handlers" to be invoked. "handlers" are more reusable than #{} method bindings due to their support for multiple inputs and outputs. You also do not have to do any faces-config.xml file configuration, they are defined via Java SE 5 @annotations.
If you want examples or help trying this out... let me know. JSFTemplating pages can be mixed with JSPs as well... although once you start using JSFTemplating pages, you're not likely to make any more JSP pages.
Good luck!
Ken Paulsen
https://jsftemplating.dev.java.net
Any thoughts?

Similar Messages

  • JSF action before the page is displayed?

    Hi all,
    What's the best way to execute a backing bean method before the page is rendered?
    I have to fill out some selectOneMenus on the page with a backing bean method.
    Will the onload JavaScript function in the <body> tag do this for me? How does one call a JSF method from JavaScript?
    Thanks for any help!
    Illu

    Why not just bind the value of a selectOneMenu to a list of SelectItems, like this:
                        <h:selectOneMenu styleClass="selectOneMenu" id="acctprodMenu" value="#{accountServiceMappingAction.mappingBean.acctPrdId}" >
                             <f:selectItems value="#{adjustmentsInit.accountProducts}"/>
                        </h:selectOneMenu>      Where in the adjustmentsInit bean, there is a method like this:
         public List getAccountProducts() {
              ArrayList temp = new ArrayList();
              Iterator itr = someService.getAccProdList.iterator();
              while (itr.hasNext()) {
                   AccountProduct acct = (AccountProduct) itr.next();
                   SelectItem item =
                        new SelectItem(
                             new Integer(acct.getAccountProductId()),
                             acct.getAccountProductName());
                   temp.add(item);
              return temp;
         }This way, once you load the page, it will have what you need in it.

  • JDev 11.1.2.1 Execute method (with bind variable) before page is displayed

    Hi All,
    I have a view object with a query that uses a bind variable. I drag the data control onto my .jsf page to create a table. I create a query method on a view scope bean. The query method uses the contents of one of the bean's attributes to set the bind variable for the query:
    vo.setNamedWhereClauseParam("CraIdBindVar", sessionBean.getCraId());
    I place a button on the page that invokes the query method and it populates the table. This is fine but I don't want the user to have to click on the 'query' button when they navigate to this page. I have found forums that discuss creating an AMImpl.jave method, creating a binding on the page, creating an executable for the binding. This works in that the method is executed before the page is displayed. However, the AMImpl method cannot call sessionBean.getCraid() to get the necessary data item to populate the bind variable.
    Is there a way to execute my view scope bean method before the page is displayed? Or perhaps a way for the AMImpl.java method to access the view scope variable?
    Thanks, Steve

    Steve,
    you can drag a method call activity onto the task flow. Then select the new method call activity and open the property inspector. Here you select the method from your bean in the method property. Now you first navigate to this method call activity and then to the page.
    Timo

  • Option 2: Clear URL parameters jut before page is displayed

    Is it possible to clear the URL parameters after they have
    been used to
    filter out recordsets, etc. but before the page is displayed
    so that the URL
    address does not have any url paramters ?
    A

    I did, thing is that it is using the 'insert' behaivor from
    DW, I went to
    the line where the Querystring is added to the URL and
    commented it. That
    did the trick.
    A
    "RobGT" <[email protected]> wrote in
    message
    news:ej1nkq$krp$[email protected]..
    >
    > Send them through a form POST instead of using GET?
    > Cheers,
    > Rob
    >
    http://robgt.com/ [Tutorials and
    Extensions]
    > Firebox stuff:
    http://robgt.com/firebox
    > Skype stuff:
    http://robgt.com/skype
    > SatNav stuff:
    http://robgt.com/satnav
    >
    >

  • Can we call a method before and after Export operations in ADF 11g

    Hi,
    My problem is I have to execute a method before and after the export operation.Is this posible in ADF 11g
    Regards,
    Felix

    Hi,
    in response to a similatr post of yours, I replied
    1. Drop af:exportCollectionActionListener on a command button
    2. set the command button to display = false
    3. In your Java code, call
    ActionEvent ae = new ActionEvent(button);
    ae.queue();
    Everything you put before
    ActionEvent ae = new ActionEvent(button);
    ae.queue();
    will fires as a pre-trigger, everything after as a post trigger
    Frank

  • How to execute a backing-bean method before loading JSP Page?

    Hi everybody.
    Scene:
    An AdfForm, with
    -SelectChoice, referenced to a <list> of pageDef, which is referenced to an ADF BC.
    Goal:
    -Executing the query of the ADF BC before load the SelectChoice, to load the correct values.
    A good question to know:
    Exists any way to execute a method of backing before loading a JSP Page?
    Any similar to onload method of javascript. It could be fantastic.
    Thanks in advance,
    Jaime

    hi Jaime
    If I understand correctly, you are using the ADF Model for data binding.
    Because your goal is "Executing the query of the ADF BC ...", maybe you can also consider to refresh an executable in your Page Definition.
    See also "10.5.5 How to Use Refresh Correctly for InvokeAction and Iterator Bindings"
    at http://download.oracle.com/docs/html/B25947_01/bcdcpal005.htm#BJECHBHF
    It says "... You can use the Refresh property on iterator bindings and invokeAction executables in your page definition to control when each are evaluated during the ADF page lifecycle, either during the prepareModel phase, the prepareRender phase, or both. ...".
    Although you have posted your question in a structured way, which is a good thing, I think it would help to understand your question if you can explain how you determine "the correct values" for your list, what is varying?
    success
    Jan Vervecken

  • How to call AMImpl method before loading the page(task_flow_config.xml)

    Hi experts,
    I have requirement like,
    I need to call AmImpl method, before rendering the page.(I heard like we can do it in task_flow_config.xml by using method_Invoke operation,But I am not sure about How it is going to work, also i need to know the implementation part,,,help pls )
    (I need to do in Task_Flow.)
    Inside that method I have some logic, where I will setting the BindVariable of my one ViewObject and I need to run the ViewOblect,So that DataShuold be available while page loading.
    I have some different logic after that,,,,
    can anyone suggest me for this??
    thanks
    Santosh

    thanks to Timo n TK,
    I have use case like,
    In the search page I have 2 LOV dropdowns say LOV1 and LOV2. Both list of values are created based on the independent View Objects based on the Query.
    LOV2 VO query is having the Bind Variable, for that Bind variable will be getting the value from the one of the AM method based on the user logged in.
    Also I need to display LOV2 dropdown in the page when user selects LOV1 as a 'SCM', for others it should be in hidden state.
    As per requirement I have to display LOV2 only for LOV1 value as 'SCM'. So I dont want to use valueChangeListner() for this.
    Instead I want populate LOV2 value before page rendering(because in that time i will be having all the parameter to populate ) by executing LOV2 VO Query.
    Once in search page user selects LOV1 as 'SCM', I should display 'LOV2' values in the dropdown.
    If i execute LOV2 VO in the AMImpl method say A() before page rendering ,then if user select LOV1 as 'SCM', will same data available in the dropdown (LOV2 dropdown is based on the LOV2VO)??
    Can u pls suggest me how can i render ,LOV2 when LOV1 as 'SCM' by using 'rendered' property without having valueChangeListner??
    pls suggest me the right approach as per my use case..
    waiting for reply,,
    Thanks
    Santosh

  • Calling a method before entering a page

    Hi,
    What is the best way for calling a method before entering a page in ADF, when this page is the fist page that user in enter into it in Application, I mean there is not any other page before this page ( in this case I am able to call that method in task flow with method call).
    Also, I want this method calls only one time....
    Thanks.
    Edited by: Amir Khanof on Jun 29, 2010 5:19 AM

    Hi,
    one option would be to add a method for the afterPhase property of the f:view component on a JSPX page and listen for the after restore phase. Then check if the request (you get this from the FacesContext) is a GET request, which indicates that the page was requested from the browser and not in the process of navigating in the application. If the conditions are true, access the method and execute it
    Frank

  • How to execute a method after page Load?

    My question is very similar to what was discussed in following thread:
    How to execute a method after page Load?
    My requirement is that I want to run a method in backing bean of a page, immediately after the page gets loaded. In that method I want to invoke one of the method action included in the pagedef of this page, conditionally.
    I tried using the approach given in the above thread, i.e to use <f:view afterPhase="#{backing_security.setPermPriv}">, but the problem is that our page is not using 'f:view' , so I explicitly added one f:view with afterPhase property set , but it is not working, page it self is not getting loaded, it is throwing the error:
    Root cause of ServletException.
    java.lang.IllegalStateException: <f:view> was not present on this page; tag [email protected]e8encountered without an <f:view> being processed.
         at org.apache.myfaces.trinidad.webapp.UIXComponentELTag.setProperties(UIXComponentELTag.java:108)
         at javax.faces.webapp.UIComponentClassicTagBase.findComponent(UIComponentClassicTagBase.java:733)
         at javax.faces.webapp.UIComponentClassicTagBase.doStartTag(UIComponentClassicTagBase.java:1354)
         at org.apache.myfaces.trinidad.webapp.UIXComponentELTag.doStartTag(UIXComponentELTag.java:71)
         at oracle.adfinternal.view.faces.taglib.UIXQueryTag.doStartTag(UIXQueryTag.java:41)
         at oracle.adfinternal.view.faces.unified.taglib.UnifiedQueryTag.doStartTag(UnifiedQueryTag.java:51)
         at oracle.jsp.runtime.tree.OracleJspBodyTagNode.executeHandler(OracleJspBodyTagNode.java:50)
         at oracle.jsp.runtime.tree.OracleJspCustomTagNode.execute(OracleJspCustomTagNode.java:262)
         at oracle.jsp.runtime.tree.OracleJspNode.execute(OracleJspNode.java:89)
         at oracle.jsp.runtimev2.ShortCutServlet._jspService(ShortCutServlet.java:89)
         at oracle.jsp.runtime.OracleJspBase.service(OracleJspBase.java:29)
         at oracle.jsp.runtimev2.JspPageTable.compileAndServe(JspPageTable.java:665)
         at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:387)
         at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:822)
         at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:746)
    Please help to resolve this issue, or am I doing anything wrong?

    Hi,
    I assume that your view is a page fragment and here - indeed - the f:view tag cannot be used. If you use ADF then one option would be to use a custom RegionController on the binding layer to listen for the render phase to invoke the method. Another option would be to use a hidden field (output text set to display="false" and have this component value referencing a managed bean property. The managed bean property's getter method can now be used to invoke the method you want to run upon view rendering
    Frank

  • Calling a method before page rendering begins

    I'm new to JSF. I'm looking for a way to get a method from my backing bean called AFTER page contents are initialized but BEFORE the page is rendered. I want to initialize some components dynamicaly and add them as children of an existing component, and then get everything rendered. How can it be done?

    What about binding a bean property to your component you wish to add to dynamically?
    Could you describe a little more of what you are trying to do? There may be a more elegant way of solving the problem.

  • Execute Method Before Detail VO is Refreshed

    Hi all,
    JDeveloper 11.1.2
    I have two entity based view objects with master-detail relationship defined by a view link. The detail view object is based on an advanced Oracle database view, which needs a database procedure to be executed before it can be queried.
    Besically, I want to execute a method when master view object current record is changed, before detal views are refreshed.
    Is this possible? As an ADF noob, I see lots of methods to override, but which one?
    I hope you can help.
    Regards,
    Håvard

    Haavard,
    This is a use case I've never run across before, so my "answer" here is really just thinking out loud (I've not tried).
    First, you'll have to make sure that your View Object isn't based on an Entity Object (I'm guessing), otherwise the EO cache may get in the way of refreshing the VO.
    Perhaps you could have a read of [url http://download.oracle.com/docs/cd/E16162_01/web.1112/e16182/bcadvvo.htm#sm0341]this part of the docs, which tells how to do a programmatic VO to get some ideas. What I would probably try first is overriding executeQueryForCollection() to first call the stored procedure and then call super.executeQueryForCollection().
    Again, not tried/tested, so something for you to try out :)
    Edit - Timo and I posted about the same time - his idea seems promising, too.
    Best,
    John

  • Execute java code before rendering the page

    Hi,
    In a task flow, can I execute some java code before the page/view is rendered (i.e. some preprocessing). I would need to be able to have access to the bindings on the page.
    Thanks!

    Can you try doing as specified below:
    If it is simple JSPX, you could use the phase listener as follows:
    JSPX Code:
    <f:view beforePhase="#{SamplePageBean.phaseListener}">
    <af:document id="d1">
    <af:form id="f1">
    <af:panelFormLayout id="pfl1">
    <f:facet name="footer"/>
    </af:panelFormLayout>
    </af:form>
    </af:document>
    </f:view>
    Bean Code:
    public class SamplePageBean {
    public SamplePageBean() {
    public void phaseListener(PhaseEvent phaseEvent) {
    if (phaseEvent.getPhaseId().equals(phaseEvent.getPhaseId().RENDER_RESPONSE)) {
    // DO NECESSARY INITIALIZATION
    Thanks,
    Navaneeth

  • How can i disable a submit button and execute submit_action method on click

    Good Day,
    On my page I have a submit button that execute the submit_action method of the page backing bean that submit data captured on the page into a database and activate another class that send mail at the same time on a click of the submit button,the mail process takes a while before returning back to the page.I was able to disable the submit button to prevent the user from keep click while the process is running but the issue is on clicking the submit button it only disable the submit button without executing the submit_action method of the page backing bean.How can i disable the submit button and execute submit_method of the backing bean at the same time.
    Thanks in advance.

    I tried this out on one of my pages to see if it works.
    First, I added the following JavaScript to my submit button's onClick event:
    this.disabled=true; return true;When I clicked the submit button, it was disabled but the form was not submitted.
    I deleted the JavaScript from the onClick event and added the following JavaScript to the form's onSubmit event:
    var button = document.getElementById("form1:submitButton"); button.disabled=true; return true;When I click the submit button, it was disabled and the form was submitted but the button's action method was not called.
    The next thing I tried was to change the onSubmit event code:
    var button = document.getElementById("form1:submitButton"); setTimeout("button.disabled=true", 500); return true;This seemed to work. The difference was that I added a 1/2 second delay before disabling the button.
    See if that works for you. If not then I'm fresh out of ideas.

  • Decision step with method before workitem execution

    I have a decision step, which uses method before workitem execute uses BO Bus2094 - 'Display' method.
    When an agent receives a workitem, try to execute the workitem 'Getting an information message 'Error when starting submethod'.
    When i see the information of the error -
    "At least one submethod could not be processed.
    See the technical Workflow log to determine the error cause."
    When i check technical log of workitem, 2 steps are in error mode.
    1.  Dialog work item executed - Error when starting submethod
    2. EXECUTE_METHODS  - System error in asynchronous method start
    This is happening in Quality system, not in DEV system.
    Any inputs to resolve this.

    Hi,
    @Sivagami: I wonder, how a container element e.g. BUS2094 that was passed to a copy of the DECISION task is automatically executed just before the decision dialog? Good stuff, if it works like this, I'll try this at a later time.
    @Indira: Depending on the Release and such things I have expirienced several smaller bugs regarding the decision steps, especially when extending the data flow (from/to workitem), using the in-place-decision Workitem exit. So maybe you're already doing everything right, but just the inbox doesn't works as designed.
    To work around this problem, you could enter the object methods as a secondary method, which then will display the Sales document in a separate window,
    or you follow the proposal of Sivagami. If the Sales document doesn't seem to appear, you could enforce the display, by globally substitute the business object DECISION to one of your own, re-define the object's method Process that read the business object fromt the work item container and executes it's display method, which is basically the same result you'd like to have.
    Best wishes,
       Florin

  • Want to check page is displayed on browser or not ?

    In my code:
    in every half an hour it opens my browser and access a website(just like www.yahoo.com).
    I want, in any case if page not displayed it make a file and saved it on my pc. How can i check the page is displayed or not ?

    No need to apologize. Yes there is... Im disgusted with myself :o)
    I shall be signing myself up for a public flogging immediately.
    If the OP uses your code snippet verbatim without realizing
    what's going on, he'll be surprised later if he finds out
    that another url makes his code barf "for no particular reason" ;-)Indeed. I've never used the HttpUrlConnection stuff before - I've normally just used commons.HttpClient - but it certainly seems pretty "clunky" (a POST method gets magically use just because an output stream is open).
    AFAIK, there's nothing in rfc2616 which states that a GET request must not include an entity body - so this seems pretty odd behaviour.
    Its also at odds with its own java-doc (I set the requestMethod to "GET", but by opening an output stream it automatically became a "POST". Nothing I could find in the java doc to explain this....).
    Anyway, as is probably obvious, Im just trying to find excuses to cover up my mistate :o)

Maybe you are looking for