Calling function from Backing Bean or JSP page

We are on Jdeveloper 10.1.3.3.0, ADF Faces, JSF Faces .., Currently there is a function call from Javascript event (onmouseover) in the JSP page. I want to call this function from a backing bean or JSP page, as I have to pass some values to this function.
For Ex., I have a function call like return submit('A','B','Test'); on the Javascript event (onmouseover) in jsp page. I want to remove this function from the javascript event and call from backing bean or jsp page to pass some values into the submit() function. I appreciate if anyone can give some example of how to call this function from backing bean or jsp page in the <SCRIPT> or <SCRIPTLET>
Thanks,
Ram

A use case would be helpful so that we can get a better idea of what you want to do.
As a general rule, there is no way to call a client side Javascript function from a backing bean, which is server side. However, there are ways to inject information from a backing bean into your Javascript call. For instance, I have an application that uses Google Maps API. It has an onload call to a Javascript function that builds the map and designates it's center point. The center point comes from a backing bean as latitude and longitude properties. So here is my body tag:
<afh:body onload="initialize(#{backing_searchResults.latitude},#{backing_searchResults.longitude},#{searchCriteria.distance})"
          onunload="GUnload()">onload calls the Javascript function called initialize, and passes the latitude, longitude, and distance from the bean. Is the function really being called from my backing bean? No - the parameters are hard coded into the onload event code when the page is rendered. Does it do the job? Sure it does.

Similar Messages

  • How to call a Javascript function from backing bean without any event

    Hi,
    Someone knows how to call a Javascript function from backing bean without any event ?
    thanks

    Please review the following thread:
    ADF Faces call javascript
    Luis.

  • ADF Question: call javascript function from backing bean?

    Hi all,
    I am running JDeveloper 10.1.3.3 with ADF BC.
    Heres my situation:
    I have a table, and after inserting a new row, then committing, I want to call a javascript function. I tried using the onkeyup javascript to force a click of the save button, and then call my function after that. However, I really only want the second function to be called AFTER the commit has occurred.
    I have tried putting a setTimeout on the second function, but this never executes then. Is there some way that I can call the second javascript function from the backing bean? Is there a better workaround for this? Here is some code:
            function submitCreate(e) {
                var _event = (window.event) ? event : e;
                var KeyID = _event.keyCode;
                switch (KeyID)
                    case 13:
                        document.getElementById("form1:tvoTable:commitButton").onclick();
                        doAjax();
                        break;
            function doAjax() {
                var item = document.getElementById("form1:inputText3").innerHTML;
                getAjax(item, "FULL");
            }Thanks,
    Heather

    Maybe try adding an af:script block in your jsp as a partial target in your backing bean when you commit to the database? We are doing something similar when we get a tab DisclosureEvent but the principle should be the same.
    In our jsp we have:
    <af:script id="scriptID" text="alert('javascript here');"/>
    In the backing bean we have:
    method(DisclosureEvent de) {
    // get a component somehow or the component, we get it from the disclosure event
    // but you could use a binding also. if you don't have the exact script element you need
    // to find it like we do below.
    UIComponent c = de.getComponent();
    // Find our real script component
    UIComponent target = c.findComponent(":scriptID");
    // get the adf context
    AdfFacesContext adfContext = AdfFacesContext.getCurrentInstance();
    // add the script as a partial target.
    if(target != null) {
    adfContext.addPartialTarget(target);
    This relies on PPR though, which you may not be doing. If you are navigating to a new page you could set an indication in a backing bean and then access that in an <af:script> block in the new page or even generate the Javascript you want depending on your logic and access all of it via an EL binding on the af:script tag:
    <af:script id="scriptID" text="#{bbean.generatedScript}"/>
    Hope this helps!
    Steve

  • Can we call a javascript function from backing bean class?

    I have a requirement. In a multiselect table, when users selects some rows and clicks a button. Depending upon some condition, an alert box should appear with 2 buttons 'Yes' and 'No'. On clicking yes, certain field values in the selected rows of table should change. On clicking no, the alert box should close. As far as i know alert box can be done only in JS.
    Please help me, if a javascript function can be called in backing bean method or suggest some way where alert boxes can appear through ADF.

    I need to go back to the backing bean as i need to iterate through each selected row of the table in a method( method written for command button) and then if atleast one of the selected rows has job field='Manager', then an alert box needs to be displayed. If none of the rows have job field as 'manager', alert box should not be displayed.
    If I write the function for onclick, i cannot iterate through the selected rows of the table in JS function.
    Please suggest a way to do this.

  • How to call popup from backing bean

    Hi,
    I have an application under jdev 11.1.1.1.0
    I am using the explorer template.
    I have my popups in one page and from another page i need to call these popups.
    I cannot use the <af:showPopupBehavior> because i am using the <af:setActionListener> in my command button.
    So in the action attribute I called my backing bean
    public String showDelBoxPopup() {
       FacesContext context = FacesContext.getCurrentInstance();
       ExtendedRenderKitService extRenderKitSrvc =
         Service.getRenderKitService(context,ExtendedRenderKitService.class);
       extRenderKitSrvc.addScript(context,"AdfPage.PAGE.findComponent('delBoxPopup').show()");
       return null;
    }But i always receive a null error.
    How can i call a popup in one page from another page using backing bean.
    Thank you in advance.
    Emile BITAR

    Hi,
    You can use <af:setActionListener> with <af:showPopupBehavior>, if you set triggerType="click" on the showPopupBehavior and contentDelivery="lazyUncached" on the popup to ensure the popup will be raised after setActionListener.
    I also don't understand what you mean by calling the popup from another page (is that page included as a region?), but if you say it works then your other option could be to bind the popup to the backing bean and use popup.getClientId() in your javascript.
    String script = "var popup = AdfPage.PAGE.findComponent(\"" + popup.getClientId(fc) +  "\"); popup.show();";Pedja

  • How to use value returned from a bean in jsp page

    Hi All,
    I have a string array value being returned from a javabean to a jsp page. I want to be able to assign the value to a variable in the jsp page.
    How do I do this?
    Many thanks :)

    thanks for your response.
    I actually used something like this:
    <% String loggedin = log.User(user,password);
    out.println(loggedin);
    %>i am not yet as much of an expert on beans as i would like to be, but i thought it is not really a bean if it has a getter method which takes arguments?

  • What is the syntax for calling function from class file by jsp

    does anyone here knows what is the syntax of how to call a function from java class file by javascript code or any way to call it?
    and where should i put the calling function code? because the function is called depend on the user click.
    for example
    <%=pc.functionName(a,b)%>
    for the variable a and b, how can i get the value from html textbox and put it in a and b...
    urgent needed...
    thx

    Jsp's are executed before the Html forms are created and loaded. Dont try to use a java code function calling on a javascript click. You'll have to explicitly redirect it into a servlet where in you can call the function you want.
    Well! another way could be using AJAX. That seems to be powerfull enough and it might also serve your purpose.
    Hope this helps

  • Unable to execute javascript from backing bean

    Hello experts,  I want to execute  javascript function from backing bean method.   
    In my .jsff  page,  I have added  the javascript as :
    <jsp:root  ..... >
    <af:resource type="javascript" >
              function fileDownloadJS() {
                                alert(" tesing js from backing bean");
        </af:resource>
    </jsp:root>
    in my backing bean method  :
    public void callJSfuntion(ActionEvent actionEvent) {
            RenderKit rk = FacesContext.getCurrentInstance().getRenderKit();
            ExtendedRenderKitService erks = (ExtendedRenderKitService) Service.getService(rk, ExtendedRenderKitService.class);
            erks.addScript(context, "fileDownloadJS();");
    I have table in my .jsff page,   inside table column,  I have command link  and when I click the link,   I am invoking bean method  :
    <af:table  ....>
        <af:column sortProperty="title" sortable="true"  
                           headerText="File name" width="250px" id="Title"
                           clientComponent="true">
                  <af:commandLink   id="cl1"    actionListener="#{MyBean.callJSfuntion}" clientComponent="true">  
                    <af:outputText value="#{row.title}" id="ot1"/> 
                  </af:commandLink>
         </af:column>
    .</table>
    But when  I  run my taskflow and  click on  the link inside the table column,    JS function is not invoked.
    Absolutely  no clue what  is the issue.
    Appreciate if you can  help me out to resolve this issue.   Thank you.

    For debugging purpose can you try :
    <script type="javascript" >
              function fileDownloadJS() {
                                alert(" tesing js from backing bean");
    </script>
    put it on top of the page and let me know what happens.
    If it doesn't work try writing the function itself in your addScript(context, script); to see if it works.

  • How To Customize displaying  of JSP page From Backing Bean

    I would like to customize the displaying of jsp page from backing bean based on user Roles
    For example
    - if the Role is Admin then backing bean should display Admin.jsp
    - if the Role is Guest then backing bean should display Guest.jsp
    Any pointers/suggestions will be highly appreciated
    Regards
    Bansi

    Thanks to all for providing thoughts
    I wanna make it more Dynamic. In the sense
    "Backing Beans should drive the rendering of first jsp page in the application " and not jsp page driving the backing bean or not to put some kind of hard coding in jsp page to see if its admin user then display certain set of UI Components or certain set of other UI components for other users.
    As we have atleast 10 different Roles and there can be Composite Roles i.e. combination of two roles. In this case how does the Backing Bean drives the rendering of jsp page?
    Regards
    Bansi

  • Passing long values from inputItem to function  in backing bean

    hi,
    in my backing bean i intend to call function func1(Long pAmount)
    on my page there is an inputItem bound in the BB.
    So, in me backing bean i'd like to achieve long value (oracle db number(10,2)) from the bound text item.
    How can i get long value ? by default it's coming easy as Number ( (Number)(itPTPAmount.getValue()).toString())
    but even though i can't convert it to Long;
    what i have is going thru String, but this way below cuts fractions:
    try{
    ptpAmount=new Long((itPTPAmount.getValue()).toString());
    catch(Exception e){System.out.println("error ptpAmount:"+e.getMessage());return;}
    please advise

    you can use doubleValue()
    http://docs.oracle.com/cd/E12839_01/apirefs.1111/e10655/oracle/jbo/domain/Number.html#doubleValue%28%29

  • How can i call a taskflow methode from backing bean ??

    Build JDEVADF_11.1.1.3.PS2_GENERIC_100408.2356.5660
    i like to call a Methode (taskflow) from backing bean!
    my bean code :
        public void imageLinkActionListner(ActionEvent actionEvent) {
            String              id      = actionEvent.getComponent().getId();
            int                 linkID  = Integer.parseInt(id.substring(4));
            DCBindingContainer  bc      = (DCBindingContainer)ADFUtils.getBindingContainer();
            DCTaskFlowBinding   tf      = null;
            System.out.println("Region Change...."+id+" INT "+linkID);
            switch (linkID) {
                case LINK_CALENDAR_REGION:
                    tf = (DCTaskFlowBinding)bc.findExecutableBinding("calendartaskflowPage");                   
                break;
                case LINK_MAIL_REGION:
                    tf = (DCTaskFlowBinding)bc.findExecutableBinding("mailtaskflowPage");                   
                break;
              case LINK_ADDRESS_REGION:
                  tf = (DCTaskFlowBinding)bc.findExecutableBinding("addresstaskflowPage");                   
              break;
              case LINK_BLOGS_REGION:
                  tf = (DCTaskFlowBinding)bc.findExecutableBinding("blogstaskflowPage");                   
              break;
              case LINK_MAPS_REGION:
                  tf = (DCTaskFlowBinding)bc.findExecutableBinding("mapstaskflowPage");                   
              break;
            default:
                return;
            if (tf != null){
                uiMainRegion.setRegionModel(tf.getRegionModel());
                uiMainRegion.setValue(tf.getRegionModel());
                tf.getExecutableBindings();
                AdfFacesContext.getCurrentInstance().addPartialTarget(uiMainRegion);
        }i like to call *#{backingBeanScope.mapBean.initMap}*
    my taskflow source
    <?xml version="1.0" encoding="windows-1252" ?>
    <adfc-config xmlns="http://xmlns.oracle.com/adf/controller" version="1.2">
      <task-flow-definition id="map-task-flow">
        <default-activity id="__1">map</default-activity>
        <view id="map">
          <page>/map/map.jsff</page>
        </view>
        <method-call id="initMap">
          <method>#{backingBeanScope.mapBean.initMap}</method>
          <outcome id="__7">
            <fixed-outcome>init</fixed-outcome>
          </outcome>
        </method-call>
        <control-flow-rule id="__2">
          <from-activity-id id="__3">initMap</from-activity-id>
          <control-flow-case id="__5">
            <from-outcome id="__6">init</from-outcome>
            <to-activity-id id="__4">map</to-activity-id>
          </control-flow-case>
        </control-flow-rule>
        <use-page-fragments/>
      </task-flow-definition>
    </adfc-config>

    Hi,
    to call the bean, use the EL in Java and reference #{backingBeanScope.mapBean.initMap} as a method expression. If you try and access the bean directly then chances are that the instance is not available. Using EL from Java always guarantees this
    Frank

  • How to call javascript function in back bean of jsf

    hi,
    i am trying to call java script function in back bean but not done. Is there any code for call javascript function in bean file.

    Java runs at server side.
    JSF produces HTML output.
    Server sends HTML output to client.
    Java stops running.
    HTML runs at client side.
    JS starts to run in HTML.
    Clear? Java is a server side language. JS is a client side language. To run JS using JSF, simply print it out to the HTML so that it get invoked when the HTML runs.

  • Clarification on application method calls from backing bean.

    Hi Experts ,
    In our application we are using two different ways to call application module methods from backing bean.
    allication module method name : addRowValidUnitInfo
    it has 2 parameters serialNumber,modelNumber
    1.
    BindingContainer bindings1 =
    BindingContext.getCurrent().getCurrentBindingsEntry();
    OperationBinding serialModelDetails =
    bindings1.getOperationBinding("addRowValidUnitInfo");
    serialModelDetails.getParamsMap().put("serialNumber",
    serialNumber.getValue().toString());
    serialModelDetails.getParamsMap().put("modelNumber",
    modelNumber.getValue().toString());
    serialModelDetails.execute();
    String result =serialModelDetails.getResult().toString();
    2.
    EWarrantyAdminModule appModule =(EWarrantyAdminModule)
    Configuration.createRootApplicationModule(amDef,config);
    try {
    String result = appModule.addRowValidUnitInfo(serialNumber.getValue().toString(), modelNumber.getValue().toString());
    } catch (Exception e) {
    finally {
    Configuration.releaseRootApplicationModule(appModule,true);
    Can any one tell me which one gives best performance and which one should be used in which situations.
    For me both are working fine but just want to know whcih is the best practice and which gives best performance.
    Regards
    Gayaz

    The approach 1 is the right way.
    Reasons:
    1) With Approach 2 - you are creating new ApplicationModule on the fly and release it at the end of the request. If you are invoking multiple method calls, you need to the same for each & every call.
    This is not reusing the existing application module.
    2) If the use cases which does calls for maintaining state across requests from the same client - across the application flow, Approach 2 cannot be used.
    Read this blog post from Jobinesh (which indirectly distinguishes both these approaches).
    http://jobinesh.blogspot.com/2010/04/invoking-applicationmodule-from-servlet.html
    Thanks,
    Navaneeth

  • Few basic doubts about accessing AM from backing bean class

    Hi ADF experts,
    I have just started working in ADF Faces.I made a sample search page.My page is attached to a managed backing bean. I have attached command button on my page to a custom method in backing bean class.
    So on, click of button this method is called in backing bean.Now, i have few doubts:
    1)How to get values of various UI beans in this event code?
    2)I am accesing AM , in my method with this code:
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext extContext = facesContext.getExternalContext();
    Application app = facesContext.getApplication();
    DCBindingContainer binding = (DCBindingContainer)app.getVariableResolver().resolveVariable(facesContext, "bindings");
    //Accessing AM
    ApplicationModule am = binding.getDataControl().getApplicationModule();
    iS this correct ?
    3) After getting handle of am how to call my custom method in AM Class?there was "invokeMethod" API in application module class in OAF, is there any such method here?
    Please help me.
    --ADF learner.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Thanks for ur response Frank, actually I am from OA Framework back ground.It would be great if help us a little with ur valuble thoughts.
    OA Framework also uses bc4j in model layer of framework. We have a requirement where our existing developers from OA Framework have to move to ADF to make a new application where time lines are quite strict.If this would not be possible we will switch to plain jsp and jdbc,but our tech experts say ADF Faces is the best tech.
    In OA Framework, Application Module is key class for all busiess logic and Controller is used for page navigation. So, I m just trying to find the same similarity , where we write we add all event codes in custom action methods in the backing bean class of page, which we consider equivalent to process form request method in Controller class of OAF.
    But there are two things, I still want to know:
    1)While page render, how to call specific AM methods(like setting where clause of certain VOs)
    2)In action methods, the way i described(I found that in one thread only)to access AM, what is wrong in that?Also, I went through
    http://radio.weblogs.com/0118231/stories/2004/09/23/notYetDocumentedAdfSampleApplications.html
    where coule of examples use similar approach to access AM from backing bean class and call custom methods of AM(Doing various, deletes etc from VOs).
    3)In these methods can we set any property of beans on the page, I am asking because in OAF, generally we use PPR for js alternatives.But all properties of beans cannot be set in post event.
    Thanks and Regards
    --ADF Learner                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to show popup from backing bean code immediately?

    Hi,
    I'm using JDeveloper 11.1.2.1.0 and have problems with showing popups. I have a button with an action on my page and a method in backing bean.
    I want to rise up few popups from this method in backing bean (for example just an anouncement that something will happen) or a dialog
    (for example a question if you want to continue).
    I understand how to get a dialog response to deal with it in code, but the problem is that the popup doesn't show up immediately, but only when
    this method called on button finishes. I'd like to handle dialog responses in the middle of the action and then the code to continue with the execution.
    Here is my backing bean code:
    private RichPopup popup;
    public String test() {
    //Some code...
    RichPopup.PopupHints hints = new RichPopup.PopupHints();
    popup.show(hints);
    //Here is the place for code which I want to be executed after popup closes,
    //but is executed before the popup shows...
    return null;
    And here is part of my jssf:
    <af:commandButton text="Test" id="cb1"
    action="#{popupBean.test}"/>
    <af:popup id="popup" binding="#{popupBean.popup}">
    <af:dialog id="dialog" type="yesNo"
    title="Dialog"
    dialogListener="#{popupBean.onDialogAction}"
    binding="#{popupBean.dialog}" clientComponent="true">
    <af:outputText value="Do you want to continue?" id="ot1"/>
    <af:clientListener method="onDialogCancel" type="dialog"/>
    <af:serverListener type="DialogCancelHandlerEvent" method="#{popupBean.onDialogCancel}"/>
    </af:dialog>
    </af:popup>
    Can someone give me some answer how to show the popup from backing bean code immediately?
    Thanks in advance,
    Tina

    If you want to execute code after popup closes, then put this code in PopupCanceledListener or in DialogListener(you can't block method execution).
    Dario

Maybe you are looking for

  • Weekly schedule line should pass to last working day of the week in SAg

    HI, In a scheduling agreement when we have weekly or monthly schedules the system displays the date in the screen as 12/2010 or 13/2010 for say a weekly schedule. However when the data is stored in the table the delivery date is always the first work

  • Should not for credit check.

    Hi, I am creating order for employee slaes and for that customer we have credit control area field is blank in customer master. It is still going for credit block. Could you please let me know how can i stop so it would not go for credit check. I wou

  • Apple Script Address Book Calling

    Hopefully someone can help me because i am beating my head against the wall. I am trying to make a script that allows me to call a number in Address Book in my Avaya Softphone app. Everything works great except that all numbers need to have "9-1" or

  • SQL Calendar using multiple date columns

    Is there any way to have a Calendar look at more than one date column? I know that it is possible to have the calendar based on a range/interval, but I need to display multiple date columns e.g. Marketing Start Date and Sales Start Date. In the Calen

  • CFC vs. Query performance

    I created a discussion board. Each entry displays the preferences of the user who posted the entry, such as 'Allow Private Messages', 'Allow Emails' etc. When looping through the entries, I have to query the database to get the preferences for each i