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.

Similar Messages

  • Calling Controller method before page render

    Hi All,
    I have created menu in my web application using DHTML Tabber where each menu item is a link.
    I am using Facelets with JSF 1.2 .
    I want on click of each menu item a page should load in the body section of my template but before that I want a controllers method to be executed which would do some initializations. I cannot change the links in my menu to be <h:commandLink> since the menu is created using javascript (it cannot have <h:commandLink> in it) .
    How do I achieve this ?

    I think the issue here is generating the action on the server side when the link is selected.
    You might want to look into the solutions people have devised for so-called pretty URLs in JSF. Scales, a component library companion to Mojarra, the Sun RI, contains some support for these.
    Solutions that spring to mind off the top of my head are using a PhaseListener to detect the links and queue the event or using a placeholder component which processes the links in the decode (similar to how commandLink works).

  • 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 call java method on page load?

    How to call java method on page load?
    Thanks

    Hey Dan,
    Well, if you want to execute a java method when page is load, you need to put the clientlistener in af:document. Let me to show you an example (I can't find my post :P),
    JSPX page:
    <f:view>
    <af:document>
    <f:verbatim>
    <script>
        function loadPage(event) {
            alert('Hello World!');
    </script>
    </f:verbatim>
    <af:clientListener method="loadPage" type="load"/>
    </af:document>
    </f:view>If you try this code you can see that when the page has been load, you recieve the alert "Hello World!".
    Furthermore, this is the javascript AJAX function that let you to call a servlet:
    function ajaxFunction () {
        var httpRequest;
        if (window.XMLHttpRequest) {
            httpRequest = new XMLHttpRequest();
        } else if (window.ActiveXObject) {
            httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
            httpRequest.overrideMimeType('text/xml');
        httpRequest.onreadystatechange = function() { alertContents(httpRequest); };
        httpRequest.open('GET', '/appname/servletname', false);
        httpRequest.send('');
    function alertContents(httpRequest) {
        if (httpRequest.readyState == 4) {
            if (!httpRequest.status == 200) {
                alert('Request error. Http code: ' + httpRequest.status);
    }Where 'appname' is your application name and 'servletname' is the name of the servlet that you want to call. Obviously, you can call any URL ;)
    JVN

  • 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

  • Very simple question: Call JavaBean method on page load?

    Someone clicks on a URL that contains parameters like: http://server/page.jsf?param=b
    How do I trigger a JavaBean method to run during page load? I see many JSF examples where JavaBean methods get called during form clicks and that works great but here I want to run code on page load.
    This must be really simple; sorry I'm new to this technology.
    Must I use <% ... %> syntax or can I use actual JSF tags or configuration to accomplish this?
    Thanks very much in advance!

    Putting a lot of logic in getter( ) function is not the best idea considering that getter( ) could be called all over the place. Using constructor for same purpose is also a bad idea especially with request scope beans. This could also happen many times at different stages. You are right, having a page load concept could be useful. Unfortunately JSF framework does not support. You could architect around it in case desperate. Or if using JSF implementation of certain vendors like IBM, you can take advantage of their implementation that was extended to support pageLoad and postBack events (similar to .NET).
    Many postings on this forum dealt with topic. Feel free to review like this one:
    http://forum.java.sun.com/thread.jspa?forumID=427&threadID=541382

  • Preventing the method calling (WSDL Method) when page loads first

    Hi Gurus,
    I have created a WebService, which will return a set of data depending on some search criteria. If No search criteria is mentioned, then it will fetch all data.
    I have successfully called that webservice using DataControl in ADF , now the issue is at time of the loading of ADF Page , it fetches all data.
    But I want to fetch the data after pressing the search button in the Page, not at time of loading of the page.
    Please help!!
    Thanks in advance
    SG_SOA

    ADF : adfFacesContext.initialRender issue

  • Call a method before Next operation to set selected values

    Use Case: I display a VO as a ADF Select Many Check Box. This VO is the detail of a master/detail. I managed to store the selection state in a managed bean on autoSubmit. Then the user navigate to the next master record, then goes back to the previous record. The Previous and Next buttons were created using the Operations in the data controls. I would like to put back the selection state when clicking on Previous or Next.
    There is plenty of tutorial on how to get the selected values, but none on how to set the selected values. How would you do it?
    JDev 11gR1

    What I ended up doing:
    1. Redefine action listener for the navigation buttons
        public void nextQuestion(ActionEvent event) {
            saveSelectedState();
            navigateQuestion("Next");
            restoreSelectedState();
        private void navigateQuestion(String operation) {
            OperationBinding operationBinding = ADFUtils.findOperation(operation);
            operationBinding.execute();
    2. The save and restore selection state using bindings
         // Guava Multimap
        private ListMultimap<Number, Integer> selectedIndices;
        private void saveSelectedState() {
            // Get question id
            DCIteratorBinding questionBinding = ADFUtils.findIterator("QuestionsView1Iterator");
            Row question = questionBinding.getCurrentRow();
            Number questionId = (Number)question.getAttribute("Id");
            JUCtrlListBinding listBinding = (JUCtrlListBinding)ADFUtils.getBindingContainer().get("AnswersView2");
            int[] valueIndices = listBinding.getSelectedIndices();
            selectedIndices.putAll(questionId, Ints.asList(valueIndices));
        private void restoreSelectedState() {
            // Get question id
            DCIteratorBinding questionBinding = ADFUtils.findIterator("QuestionsView1Iterator");
            Row question = questionBinding.getCurrentRow();
            Number questionId = (Number)question.getAttribute("Id");
            int[] valueIndices = Ints.toArray(selectedIndices.get(questionId));
            JUCtrlListBinding listBinding = (JUCtrlListBinding)ADFUtils.getBindingContainer().get("AnswersView2");
            listBinding.setSelectedIndices(valueIndices);

  • How to call a method on clicking Search Button in a jspx page.

    Hi All,
    I made a simple search page with two search criteria. Also i used LOV's for selecting the values to these view criteria's.
    Now i need to validate the criteria's being passed before page renders. Based on the validation i would like to change my base query of the page.
    Is this is possible to have two different query for the same page.
    If yes then please guide me to achieve this !!!
    Regards
    Siva

    Hi Arun ,
    Thanks for the reply,
    This is the actual scenario,
    I need to allow user to querying using a particular atrribute say A1 but applying A1 directly as a criteria on my base query along with other criteria will not fetch any details.
    Instead
    I need to fire the same query with A1 alone initially and on top of the fetched results i need to apply the other criteria
    OR
    I need to get the A1 from user and fetch some other attribute let's say A2 corresponding to A1 and this A2 has to applied as the new attribute along with the other attributes.
    Can this be achieved.
    Regards
    Siva
    I am using jdev 11.1.1.6

  • Any way (event) to call Java method after view created in JSF 2.0

    Hi,
    I am using JSF 2.0 Mojarra's implementation.
    I am interested to know if there is a way to call Java methods before and/or after view has been restored.
    I wanted to initialize data for my page in this Java method.
    I could see there is an event class PostRestoreStateEvent added in JSF 2.0. How to use it?
    I tired to use f:event element as below, but it does not work. Can anyone share anyother idea to achieve this behaviour?
    <f:metadata>
    <f:event type="postRestoreState" listener="#{employeeLoadBean.loadAfterRestoreView}"/>
    </f:metadata>
    Regards,
    Kishore K S

    Hi,
    The problem is solved as below.
    <f:metadata>
    <f:event type="javax.faces.event.PostRestoreStateEvent" listener="#{employeeViewEventListener.postRestoreState}"/>
    </f:metadata>
    The above calls the Java method #{employeeViewEventListener.postRestoreState} whenever View has been restored.
    It was not working when shortName of the event (ie., postRestoreState) is given and throwing ClassNotFound exception.
    Regards,
    Kishore K S

  • How to call a method in one JSP from another JSP?

    say that I have 2 JSPs.
    JSP one has a button.
    JSP two has some method that, say, find the square root of the number passed from JPS one.
    How to - when click - the button on page one call the method on page two?
    Please note that I can not use object binding, but I want passing the actual parameter and call the method on page two.
    Please note that this is an update of a previous post on the same topic called "Object scope".
    Thank you all very much.

    No, i dont know how to call other than main methods from other classes
    And one more doubt i have i.e. Like in C can we see the execution of the program like how the code is being compiled step by step and how the value of the variable changes from step to step like(Add Watch).........

  • How will you  collect error records in call transaction method

    hello
    how will handle errors in call transaction method...

    DATA: BEGIN OF ITAB OCCURS 0,
          F1(10) TYPE C,
          F2(18) TYPE C,
          F3(15) TYPE C,
          END OF ITAB.
    DATA: BEGIN OF ITAB1 OCCURS 0,
          F1(2) TYPE C,
          F2(10) TYPE C,
          F3(18) TYPE C,
          F4(15) TYPE C,
          END OF ITAB1.
    DATA : ITAB2 LIKE ITAB OCCURS 0 WITH HEADER LINE,
                IT_SUCCESS LIKE ITAB OCCURS 0 WITH HEADER LINE,
                IT_ERROR LIKE ITAB OCCURS 0 WITH HEADER LINE.
    DATA : BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE,
               T_BDCMSGCOLL LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
      CALL TRANSACTION 'VA01' USING BDCDATA MODE 'N' UPDATE 'S'
                                MESSAGES INTO T_BDCMSGCOLL.
      PERFORM ERRORHANDLING TABLES ITAB2 USING COUNT1 COUNT2.
      REFRESH BDCDATA.
    FORM ERRORHANDLING TABLES   P_ITAB2 STRUCTURE ITAB
                       USING    P_COUNT1
                                 P_COUNT2.
      IF SY-SUBRC <> 0.
        CALL FUNCTION 'FORMAT_MESSAGE'
          EXPORTING
            ID        = SY-MSGID
            LANG      = '-D'
            NO        = SY-MSGNO
            V1        = SY-MSGV1
            V2        = SY-MSGV2
            V3        = SY-MSGV3
            V4        = SY-MSGV4
          IMPORTING
            MSG       = T_BDCMSGCOLL
          EXCEPTIONS
            NOT_FOUND = 1
            OTHERS    = 2.
        IF SY-SUBRC <> 0.
          MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
        IF P_COUNT1 = 1.
          WRITE : / ' The records not loaded are '.
          P_COUNT1 = P_COUNT1 + 1.
        ENDIF.
        LOOP AT P_ITAB2.
          WRITE : / P_ITAB2-F1 , P_ITAB2-F2 , P_ITAB2-F3 .
          CLEAR P_ITAB2.
          DELETE P_ITAB2 INDEX 1.
        ENDLOOP.
        WRITE : /.
      ELSE.
        IF P_COUNT2 = 1.
          WRITE : /  ' The records loaded are '.
          P_COUNT2 = P_COUNT2 + 1.
        ENDIF.
        LOOP AT P_ITAB2.
          WRITE : / P_ITAB2-F1 , P_ITAB2-F2 , P_ITAB2-F3 .
          CLEAR P_ITAB2.
          DELETE P_ITAB2 INDEX 1.
        ENDLOOP.
        WRITE : /.
      ENDIF.
    ENDFORM.                    " errorhandling

  • Issue with calling a  method activity before page render

    Hi All,
    I am using Jdeveloper 11.1.1.7.
    I am trying to achieve the approach defined in "1.b. Calling a Method in Backing Bean:" elaborated in the blog - https://blogs.oracle.com/adf/entry/an_epic_question_how_to
    As illustrated, I defined a default method activity (binding to a method in managed bean) and a view activity activity in a bounded task flow.
    When I launch the application (running the view activity), following error is encountered -
    oracle.adf.controller.metadata.ParsingException: ADFC-02020: Cannot find default activity 'check' in task flow definition '/WEB-INF/task-flow-definition.xml#task-flow-definition'.
        at oracle.adfinternal.controller.metadata.model.xml.XmlUtil.createAndLogParsingException(XmlUtil.java:474)
        at oracle.adfinternal.controller.metadata.model.xml.MetadataResourceXmlImpl.parseTaskFlowDefinition(MetadataResourceXmlImpl.java:507)
        at oracle.adfinternal.controller.metadata.model.xml.MetadataResourceXmlImpl.parse(MetadataResourceXmlImpl.java:361)
        at oracle.adfinternal.controller.metadata.provider.mds.MdsMetadataResourceProvider.parseResource(MdsMetadataResourceProvider.java:748)
        at oracle.adfinternal.controller.metadata.provider.mds.MdsMetadataResourceProvider.getMDSCachedResourceOrParse(MdsMetadataResourceProvider.java:732)
    Please advise.
    Best Regards,
    Ankit Gupta

    Hi Cvele, Timo,
    Many thanks for the suggestions.
    To avoid confusions, I have created a new application altogether. It seems that the method call is not being called when I run the page.
    For your reference I have attached the task flow definition and method code below -
    Task Flow Definition
    <?xml version="1.0" encoding="windows-1252" ?>
    <adfc-config xmlns="http://xmlns.oracle.com/adf/controller" version="1.2">
      <task-flow-definition id="task-flow-definition">
        <default-activity id="__1">methodCall1</default-activity>
        <managed-bean id="__11">
          <managed-bean-name id="__13">TestBean</managed-bean-name>
          <managed-bean-class id="__10">TestBean</managed-bean-class>
          <managed-bean-scope id="__12">request</managed-bean-scope>
        </managed-bean>
        <view id="view1">
          <page>/view1.jspx</page>
        </view>
        <view id="exception">
          <page>/exception.jspx</page>
        </view>
        <method-call id="methodCall1">
          <method>#{requestScope.TestBean.checkURL}</method>
          <return-value id="__15">#{TestBean.checkURL}</return-value>
          <outcome id="__14">
            <to-string/>
          </outcome>
        </method-call>
        <control-flow-rule id="__2">
          <from-activity-id id="__3">methodCall1</from-activity-id>
          <control-flow-case id="__5">
            <from-outcome id="__6">go</from-outcome>
            <to-activity-id id="__4">view1</to-activity-id>
          </control-flow-case>
          <control-flow-case id="__8">
            <from-outcome id="__9">error</from-outcome>
            <to-activity-id id="__7">exception</to-activity-id>
          </control-flow-case>
        </control-flow-rule>
      </task-flow-definition>
    </adfc-config>
    Method Code
    public String checkURL() {
    // Add event code here...
    System.out.println("method activity called");
    return "error";
    Best Regards,
    Ankit Gupta

  • How to Render A Page From beginning(even if it was rendered)?

    Hi there,
    our problem is like...
    we use popup windows in our jsf ERP application to fill some fields of opener window,
    like when we open the popup window, there are a few query fields and sorting part and datatable, selection fills the opener window's specific areas,
    lets come to the problem, after querying and closing the window,when we want to reopen that popup it shows the old page, with datas inside it....
    we solved the problem by resetting bean(session) in the page code and giving null values to the components in the components.
    but we want to bring a global solution, we have lots of different popups like this, and all these popups are opening via javascript with a 'reset' parameter.
    we want to render the page from beginning if it has 'reset' parameters.(this means if it was rendered before , render component tree from beginnin even if it exist)
    we tried to do this at phaseListener before restroView, but failed.
    any brilliant solution with code example?
    regards
    Edited by: etahan on Oct 30, 2008 2:21 AM

    what i find as a solution , to check these pages in a phaseListener. but at which phase?
    if u use before RestoreView u wont be able to get viewId , so it is better to check this at after RestoreView Phase,
    I already eliminate other phases
    Because I want only a fresh render from beginning so no need to tire the server for nothing.
    so second problem how to distinguish the popup query windows from others
    because i dont want this check to be done for every page:)
    when we call these popup windoes we send a parameter that u can pick up anything useful for u, we use “reset” here, and u can pick this code inthe
    public void afterPhase(PhaseEvent e) method.
    FacesContext context=FacesContext.getCurrentInstance();
    HttpServletRequest request = (HttpServletRequest)context.getExternalContext().getRequest();
    if(request.getParameter(“reset”)!=null)
    if(e.getPhaseId()==PhaseId.RESTORE_VIEW)
    { Application application = context.getApplication();
    ViewHandler viewHandler = application.getViewHandler();
    UIViewRoot viewRoot =viewHandler.createView(context,context.getViewRoot().getViewId());
    context.setViewRoot(viewRoot);
    }of course u have to register ur phase listener in your faces-config
    nowww whenever one of the pages with “reset” paramater
    it will be cleared and rendered in that way.
    but opppps probably u will get data in ur datatable! Probably because u use session bean ,
    u can sort this problem out doing like this
    in the Getter method of ur bean instance,
    check the “reset” parameter if it exists then
    set ur bean null, then u wont have data in ur binded fields.
    Edited by: etahan on Oct 30, 2008 8:14 AM

Maybe you are looking for

  • Ti 17 crashes after Update 10.4.3

    Hi As I say in the title, my 17' crashes after update10.4.3. I' have entirely erase the disk and reinstall the system 10.4. Updating with 10.4.3 : same issue. Erasing all the disk an reinstalling (with 2 partitions). Updating with 10.4.1 : ok. Updati

  • Acct Assignment mandatory

    Hi I have created 1 Raw Material and now creating PO.But I am getting the following error There is no provision for value-based inventory management for this material type in this plant. Account assignment is thus necessary I have never made any such

  • Read credit memo item from worklist item

    Hi All, My requirement is In CIC approver open the approval workitems & select reject then execute decision. At the time i have to do two thing: 1. Need to display reject reason popup window. ( This part i have doen now popup is display) 2. From the

  • SAP 3.1H--help

    Hello everyone. I need help on ALE IDoc transaction codes in sap R/3 3.1H.My client is using SAP 3.1H system and i know the transaction codes for 4.6c. How different is the 3.1H system from 4.6c and what are the major difference between the transacti

  • FRM-41067: Cannot find menu item: invalid Id

    Hello, I have a menu, when i try to execute query by entering a value i received this message. i checked all my code, everything seems correct. someone can tell me what it could be wrong in my menu?