Javascript refer to backing bean getter

Hey all,
So I have a a little javascript going on and I'd like to have it grab a constant I have in my backing bean. I was wondering what the easiest way to do that would be.
This snippet is in a .jsff that makes heavy use of my backing bean, GIQDBackingBean.java
<af:resource type="javascript">
var constant = [insert code to grab from backing bean]; <af:resource>
The backing bean has this getter which contains the constant in question:
public int getMaxPdfBenes() {
return GIQDUtils.getMaxPdfBenes(); //<- this gets the constant from a static utility class
Thanks for the suggestions.

Your replied solutions would work I'm sure but after a little bit of messing around I decided it was a bit much for just grabbing a constant. Here's the way I did it which I will post in case someone else has the same question.
<af:outputText id="maxPdfBenes" value="#{giqdBackingBean.maxPdfBenes}"
visible="false"/>
The constant is stored in output text via an EL expression that grabs it from the backing bean and then set to invisible.
Then it's just a matter to referring to the outputtext with a javascript variable.
var maxPdfBenes=document.getElementsByName("pt1:r1:0:maxPdfBenes"); // in this case "pt1:r1:0" are container ids
Much easier IMO.

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.

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

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

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

  • Is there a way to get a (return) value back after running Javascript statements in the backing bean?

    I have a usecase  where I need to run a javascript function from within the backing bean and get the value returned by the function.
    Example:
              In Java I have two variables  x and y, I want the javascript to return the larger value z.
              This is what I'm doing, but I have no means to get the values of variable z.
              StringBuilder script = new StringBuilder();
              script.append("var  z;");
              script.append("var  x = " + x + ";");
              script.append("var  y = " + y + ";");
              script.append("if  (x > y)  z = x  else z = y");
              FacesContext fctx = FacesContext.getCurrentInstance();
              ExtendedRenderKitService erks = Service.getRenderKitService(fctx,
              ExtendedRenderKitService.class); erks.addScript(fctx, script);
         The actual usecase is a bit complicated. It's a dragNdrop paradigm.
         I cannot capture the muse Release event (DropEvent ?) in the client side as (most likely) it is captured by ADF.
         The drop target is a RichTextEditor. I need to convert the DropEvent.getDropX() and DropEvent.getDropY() to get the caret position in the text editor.
    Any other solution to the issue is highly appreciated.
    Thanks,
    -ab

    you can try it!
    erks.addScript(fctx, js_funcation_name("'"+x+"'","'"+y+"'","'"+x+"'","'"+x+"'",.....));//bean-> javaScript
    add javascript:
                   AdfCustomEvent.queue(p, 'XXXXX', {parameter:parameter_value},true);
    add:
    <af:serverListener type="XXXXX" method="#{ManageBean.funcation}"/>//js->bean

  • Value from backing bean in javascript confirm in 10.1.3

    Hallo,
    Please help
    I have 2 problems:
    Page with 1 record, where 8 items are updatable.
    In entity I 've a method where I set a value in bean. (BotId1 is one of these 8 updatebale items)
    What I expect: when I change a value in BotId1 the value of botId in ValiderenBotBean will be also changed
    public void setBotId1(Number value) {
    setAttributeInternal(BOTID1, value);
    EL.set("#{ValiderenBotBean.botId}",BotId.toString());
    My bean (session scope):
    package viewcontroller.pagedefs.produceren.backing;
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    public class ValiderenBotBean
    private static Log log = LogFactory.getLog(ValiderenBotBean.class);
    private String botId;
    public ValiderenBotBean() {
    // accessors
    public void setBotId(String botId) {
    log.debug("setBotId : " + botId);
    this.botId = botId;
    public String getBotId() {
    log.debug("getBotId : " + this.botId);
    return this.botId;
    Op my generaten page I have the button:
    <af:commandButton actionListener="#{bindings.Commit.execute}"
    action="Commit" onclick="if (validateForm('dataForm')){return(confirm(#{ValiderenBotBean.botId} + 'la')}"
    rendered="#{(((jhsUserRoles['JDMR_PRD03']) or (jhsUserRoles['JDMR_PRD03'])) or (jhsUserRoles['JDMR_PRD03'])) or (jhsUserRoles['JDMR_PRD03'])}" textAndAccessKey="#{nls['SAVE_BUTTON_LABEL_KOPPELENPRODUCTIEGEGEVENS']}"
    id="KoppelenProductiegegevensSaveButton">
    <af:resetActionListener/>
    </af:commandButton>
    I get the following error:
    Foutdetails webpagina
    Gebruikersagent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB6.6; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.1; AskTB5.6)
    Tijdstempel: Thu, 17 Feb 2011 13:54:46 UTC
    Bericht: Syntaxisfout
    Regel: 3744
    Teken: 1
    Code: 0
    URI: http://172.16.6.108:8988/demeter/adf/jsLibs/Common10_1_3_2_0.js
    The code from Common:
    3732 function _callChained(
    3733 a0,
    3734 a1,
    3735 a2
    3736 )
    3737 {
    3738 if(a0&&(a0.length>0))
    3739 {
    3740 if(a2==(void 0))
    3741 {
    3742 a2=a1.window.event;
    3743 }
    3744 var a3=new Function("event",a0);
    3745 a1._tempFunc=a3;
    3746 var a4=a1._tempFunc(a2);
    3747 a1._tempFunc=(void 0);
    3748 return!(a4==false);
    3749 }
    3750 else
    3751 {
    3752 return true;
    3753 }
    3754 }
    Problem nr.1:
    When I call the button I do not see any logging that indicate that the value is set in backing bean
    Workaround: I made item on my page depending on item where I put my code.
    Result: I have to press 2 times on my button to execute the button code. First time to make the validation and the second time the button code itself.
    Not nice. The validation is also slow.
    But ok:
    Problem 2:
    I still get the same error, I see logging of execution of my validation.
    There is also the difference between loggings is 2 cases:
    If I use
    onclick="if (validateForm('dataForm')){return((#{ValiderenBotBean.botId} + 'la')}"
    what I really want instead of
    onclick="if (validateForm('dataForm')){return'la')}"
    I get:
    17-feb 14:28:40 DEBUG (ValiderenBotBean) -getBotId : -1
    17-feb 14:28:40 DEBUG (ValiderenBotBean) -getBotId : -1
    It means that value is obtained correctly.
    But still the same error.
    If I put for test purpose
    the following code into my bean:
    public String getBotId() {
    log.debug("getBotId : " + this.botId);
    botId = "23";
    return this.botId;
    I do not get any error.
    Any ideas?
    Please help

    Thanks, Amit,
    I will try it tomorrow.
    Some remarkes:
    1. I need javascript for confirmation
    2. I really do not PPR. It takes so long. The user use the scanner to put the value into input items in order speed up the process. And now PPR...
    3. My transient attribute will depend on 8 items. Even more waiting process.
    What I really want is to execute my db function only 1 time "onclick" or "oncommit" and according to outcome of db-function ask user for confirmation of commit.
    I tried already to implement dialog from ADF with launchDialog function.
    But ReturnListener did not function while I launch the Dialog manually.
    Anna

  • Calling setter on backing bean via JavaScript / AJAX using JSF2

    My application requires me to invoke a setter on a backing bean instance. I am trying to do this using the following javascript code:
    var stateListWidth = document.getElementById("myform:stateListWidth");
    stateListWidth.setAttribute("value", 100);
    jsf.ajax.request(this, event, {execute: 'stateListWidth', render: 'stateListWidth'});and added a hidden field as follows:
    <h:form id="myform">
    <h:inputHidden id="stateListWidth" value="#{cityController.stateListWidth}"/>However my setter method is never called. I can see the parameters (myform:stateListWidth = 100) are POST'd to the server side, but not translated into a setter invocation. Any ideas if this is possible and how to do this.

    I got it working. Had to specify the full ID of the element myform:stateListWidth rather then just stateListWidth.
    var stateListWidth = document.getElementById(myform:stateListWidth);
    stateListWidth.setAttribute("value", 100);
    jsf.ajax.request(this, event, {execute: 'myform:stateListWidth', render: 'myform:stateListWidth' });I still wonder if there is a better way without using a hidden field to get this working?

  • Get selected row from af:table in backing bean

    Hi Experts,
    I have an af:table and i have seelctBoolean check box in that. If the user select 'x' nos of check boxes i want to display the row data of those selected rows. Can somebody help me in getting the selected row data in backing bean?
    I am using adf faces and backing bean.
    JSF Code:
    <af:table value="#{demo.partyList}" var="row"
    rowBandingInterval="0" binding="#{demo.t1}" id="t21"
    rowSelection="multiple">
    <af:column>
    <af:selectBooleanCheckbox text="#{row.person_first_name}"
    label="Label 1" id="sbc1"
    />
    </af:column>
    <af:column>
    <af:inputText value="#{row.emirate}"/>
    </af:column>
    </af:table>
    <af:commandButton action="#{demo.print}" text="Print"/>
    BB Code:
    public void print(){
    // what code to write here
    }

    This is the code
    JSF ::
    <af:table value="#{createOpportunity.dataList}" var="row"
    rowBandingInterval="0" binding="#{demo.t1}" id="t21">
    <af:column headerText="Model">
    <af:selectBooleanCheckbox text="#{row.modelRange}"
    label="Label 1" id="sbc1" value="#{row.selected}"/>
    </af:column>
    <af:column headerText="Description">
    <af:outputText value="#{row.description}"/>
    </af:column>
    <af:column>
    <af:inputText value="#{row.quantity}"/>
    </af:column>
    </af:table>
    <af:commandButton action="#{createOpportunity.print}" text="Print"/>
    Backing bean Code::
    public void print () {
    selectedDataList = new ArrayList<ModelDescription>();
    for (ModelDescription dataItem : dataList) {
    if (dataItem.isSelected()) {
    System.out.println(dataItem.getQuantity());
    selectedDataList.add(dataItem);
    // dataItem.setSelected(false); // Reset.
    Clicking on the print button shows "We have 0 rows selected"
    Thnks for ur replies guys ..
    Edited by: Wannabe Java Guru on Mar 9, 2011 1:43 AM

  • Is there any way to create backing bean, After page gets created?

    Hi
    Any one can please answer to my quick question !!!
    Is there any way to create the backing bean ,after a jsf page gets created using ADF ..?
    When i first time created the jsf jppx page i unchecked the option to generate backing bean, but later some time I would like to have backing bean for the newly created page. so is there any way to create backing bean ...?
    Thanks in Advance

    Have your page in the visual design mode then go to the Design->Page Properties menu and you'll be able to select auto-bind on the second tab.

  • How to get selected items from a tree in backing bean without adfbc

    Hi ADF Experts,
    Below is my code for af:tree. My question is how can I get selected Items from the selectionListener (without adf bc) this uses formation of tree from backing bean.
    Using Jdev 11.1.1.7.0
    <af:tree var="node" value="#{pageFlowScope.MerchandizeBean.model}"
                      binding="#{pageFlowScope.MerchandizeBean.treeModel}"     id="tree" immediate="true" autoHeightRows="0"
                           styleClass="AFStretchWidth" rowSelection="multiple"
                           selectionListener="#{pageFlowScope.MerchandizeBean.treeNodeSelection}">
                    <f:facet name="nodeStamp">
                      <af:commandLink text="#{node.classDescription}"
                           actionListener="#{pageFlowScope.MerchandizeBean.createListManyItemForMerchandise}"           id="displayTable" partialSubmit="true">
                      </af:commandLink>
                    </f:facet>
                  </af:tree>
        public void treeNodeSelection(SelectionEvent selectionEvent) {
            // Add event code here...
            RichTree tree = (RichTree)selectionEvent.getSource();
                    TreeModel model = (TreeModel)tree.getValue();
                    //get selected value
    Thanks
    Roy

    Hi,
    in a multi select case, try
    RowKeySet rks = tree.getSelectedRowKeys();
    Iterator iter = rks.iterator();
    while(iterator.hasNext()){
    Object aKey = iterator.next();
    tree. setRowKey(aKey);
    Object rowData ? tree.getRowData();
      .... do something with the data here ...
    Frank

  • How to get the value of a checkbox in the backing bean

    How to get the valaue of a checkbox in the backing bean?

    Hi this may help you for selecting single check box
    <h:outputText value="Enabled : "/>
                              <h:selectBooleanCheckbox value="#{Bean.isEnabled}"/>                    
                              <h:commandButton value="Submit" action="#{Bean.submit}"/>
    private Boolean isEnabled;
        public Boolean getIsEnabled() {
            return isEnabled;
        public void setIsEnabled(Boolean isEnabled) {
            this.isEnabled = isEnabled;
        public String submit(){
         System.out.println(isEnabled);
            return isEnabled;
        }for selecting multiple check box
                              <h:selectManyCheckbox value="#{Bean.items}">
                                  <f:selectItem itemLabel="one" itemValue="one" />
                                  <f:selectItem itemLabel="two" itemValue="two" />
                                  <f:selectItem itemLabel="three" itemValue="three" />
                               </h:selectManyCheckbox>
                   <h:commandButton value="Submit" action="#{Bean.submit}"/>
    private List<String> items;
        public List<String> getItems() {
            return items;
        public void setItems(List<String> items) {
            this.items = items;
        public String submit(){
            System.out.println("List : " + this.items);
            return "done";
        }Hope this helps you

  • How to get current db value in backing bean

    Hi,
    I'm using jdeveloper 11.1.2.3.0
    I would like to know how could I access the old value of an attribute in backing bean.
    I know I can get it in the EntityImpl level with getPostedAttribute function,
    but as I see I don't have permission to access this function in the ViewImpl.
    I get this error:
    Error(151,33): getPostedAttribute(int) has protected access in oracle.jbo.server.EntityImpl.
    Could you help?
    What is the correct way to get the current value on db in backing bean?
    Thanks a lot!

    You can add a transient attribute to the Entity object to hold the old value of the desired attribute, then you can add this attribute to the view object.
    check [url http://www.youtube.com/watch?v=iKVIiK0FBXI]Retrieving the previous value of an ADF BC attribute 

  • How to get a value for Select One Choice in the backing bean

    Friends,
    Does any one have any idea, how to get the value of a selected item value from the Select One Choice component in the backing bean iin valueChangeListener method. Right now I am always getting the sequence of the selected item, instead the actual selected value. I tried using 'ValuePassTrhough=true' also.. but didn't help
    Below is the my code snippet
    <af:selectOneChoice value="#{bindings.country.inputValue}"
    required="#{bindings.country.hints.mandatory}"
    shortDesc="#{bindings.country.hints.tooltip}"
    id="soc1" autoSubmit="true" valuePassThru="true"
    valueChangeListener="#{pageFlowScope.Bean.onValueChange
    <f:selectItems value="#{bindings.country.items}" id="si2"/>
    </af:selectOneChoice>
    Thanks in advance.

    check my other post at Re: Pass data from a variable to another page

Maybe you are looking for

  • IPod Touch not being recognised

    Bought a new iPod Touch on Friday and connected it instantly and without any problems to my MacBook. Later that evening, I attempted to connect it also to my iMac running Leopard and this did not work. I have since re-installed Tiger on my iMac but i

  • ECS Goods Receipt Errors

    Hi, i am opening this thread since i couldn't find any threads about that topic and i cannot believe that i am the only one having this issue. In general, the issue we face with SRM 5.5 ECS is that we have a lot of issues with the valuated goods rece

  • Imap authentication fail error  - cannot email pdf

    !I installed acrobat XI about 6 months ago and still have not been able to figure out how to get it to send a pdf other than closing it. Copying it from file location and then posting in an amail. HIGHLY ANNOYING!!! When i try send directly from open

  • Formula in Update rule(Urgent)

    Dear Gurus, Iam written Formula in update rule Get source system type is SUBSTRING( Source System, 2, 1 ) And Get Client Formula is RIGHT( Source System, 3 ) Above formula  syntax is correct. But when iam loading data getting below error. Formula in

  • Exposure slider makes photo darker

    I have seen this question asked a couple of times, but have not seen a solution. Whenever I so much as "touch" the exposure slider in the adjust panel (iPhoto 6.0.6), the photo gets darker. No change in the value of the slider -- it still reads zero.