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).

Similar Messages

  • 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.

  • 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

  • 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

  • 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

  • Calling controller methods in view.

    Hi Friends,
         I am created two methods in component controller, while i am accessing those two methods in view, i am not getting
         wdGet<Controller_name>Controler() method in the view.
         How can i get that?
    Thanks & Regards,
    Murali

    Hi Murali,
    This is because you didt add the componet controller under Required Controllers for the view.
    For that, take the view, and take its properties. There you will see a option called Required Controllers. Click Add and add your  component controller (carefully select component controller).
    Now try to access the method by the code you mentioned.
    Regards,
    Jithin

  • 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);

  • 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).........

  • Call Java Method on Commanlink action without page refresh

    Hi,
    I have a radio button in my application which on click calls a new JSP page inside DIV tag of the same JSP. Now before calling that JSP Page i want to perform some functionality . So i placed a commandlink on radio like this -
    <h:commandLink action="#{controller.deleteData}">
         <h:selectOneRadio id="licenseType" layout="lineDirection" value="#{controller.licenseType}" onclick="javascript:getServerInfo();">
                 <f:selectItem itemValue="#{dataTableItem}"/>
         </h:selectOneRadio>
    </h:commandLink> What I am looking for is that when a user clicks on Radio, first a Java method named deleteData() is called and then onclick() event of Radio is processed which loads a new JSP Page inside DIV tag beneath the radio button.
    But what happens is that as i click on Radio, command link takes precedence and refreshes the page.
    Is it possible for commanlink to just call the method and don't refresh or reload the page ????
    Plz assist with some code example

    Thanks Milind..... :-)
    I've not tried it as yet but i guess it would wok for radio.
    Is there any such event available for command link or command button too.... in which i just call the method on click and the page may not refresh ?
    Would "actionListener" event like this -
    <h:commandLink actionListener="#{controller.getsaveData}">call a java method and refresh the page or just call the method and leave the page as it is.
    If thats possible can u assist with some code examples ???
    USAGE :_ Actually I have a commandLink on which I have put a graphic Image "Submit" and on clicking of this image I just want the java method to be called but the page should not refresh or reload. Here is the code -
    <h:commandLink actionListener=" action="#{controller.getsaveData}">
                      <h:graphicImage url="/IMAGES/save_changes.JPG" height="27"
                                      width="136"/></h:commandLink>{code}
    Can u assist me with this Plz.{code}{code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to call a custom controller method from view

    Hi,
    I ve created a simple web service and consumed it in a model. Mapped the input & output parameters to custom controller context which in turn mapped to component controller's context which in turn to view's contexts.
    How to call a custom controller method from view?
    Please explain the syntax.
    Regards,
    Manoj.

    Hi Patralekha,
    Give some idea for the below scenario:
    I ve created a simple web service and consumed it in a model. What I did was
    1) for the input parameters, mapped the node from view->custom controller->model
    2)for the output parameter, mapping from model->custom controller->view.
    It works fine.
    But I don't want to access model nodes directly, rather I want to set the input param in somewhere else (like custom controller) before calling the appropriate method, same for the response also.
    Share me your thoughts.
    Regards,
    Manoj.

Maybe you are looking for

  • Graph Capabilities in XML Publisher

    Just started evaluating XML Publisher as a possibility for reporting multiple Balanced Scorecard KPIs from E-Business Suite onto one report, as that functionality is NOT provided by Oracle. I presume the idea of XML Publisher is to make development o

  • Financial Reports Issue

    Hi, When I am trying to run Financial Reports in workspace getting the following erroer. *5200: Error executing query: Java.lang.ArithmeticException: / by zerojava.lang.ArithmeticExceptoion*. the issue with the only Planning reports. Consolidation re

  • URGENT!! ERROR WITH EXPIRED CERTIFICATE USING JDK 1.4.2.05

    Hi, I have created a client/server application with SSL and have found the following problem. I have made these two tests: 1) jdk 1.4.2.03 --> the certificate is expired, I obtain this exception "No trusted certificate found". it's ok 2) jdk 1.4.2.06

  • Can't print using Photoshop CC.

    Using a Mac, OS 10.9.4, just installed Photoshop CC, when clicking File/Print I receive the following: "There was an error opening your printer.  Printing functions will not be available until you have selected a printer and reopened any documents. 

  • Installation Failed: Administrator Privileges

    Hello All! I am trying to install the new InDesign CC (2014) trial but Installation Failed appears immediately when I click Try with the reasoning "Administrator privileges are required to install. Please retry, or cancel to install later". I don't k