Making a commandButton's action dependant on a javascript function's result

Hi guys,
I have a command button "Login". I have a managed bean "userLoginInfoBean" with session scope whose "loginToSystem" method I want to call when user clicks on Login button.
<h:commandButton id="loginButton" type="submit" value="Login" style="font-family: Verdana; font-size: 8pt" action="#{userLoginInfoBean.loginToSystem}">So far so good. Its working perfect.
Now before calling the action, I want to call a javascript function isGoAhead(). This javascript function will return true or false. Only when it returns true then I want to call the action.
How can I do it in JSF?
Thanks

I know using onclick attribute I can call my javascript function "isGoAhead()"
<h:commandButton id="loginButton" type="submit" value="Login" style="font-family: Verdana; font-size: 8pt" onclick="isGoAhead();" action="#{userLoginInfoBean.loginToSystem}">But the question is how to make sure that the commandButton's action only gets called if the return value from "isGoAhead()" is true?
Thanks

Similar Messages

  • CommandButton onClick() action problem

    Hi every one ,
    I want to execute an Ajax function when clicking on submit button before submitting the page like this :
    <h:commandButton value="Go" onclick="myFun();" action="#{myController.getPropertyName}"/>where this javascript function will show a yes/no message then an Ajax function will be executed according to the user choice.
    The problem is that the j.s function is not even executed but the action is submitted directly.
    And from what i understood is that JSF reserves onclick() function to execute "action" property, that's why it can't feel the onclick() i wrote.
    I also tried using onmousedown() instead but still the action is submitted directly.
    Any suggestions ?

    Hesham wrote:
    Yes, i thought so but i can't change the JSF version used in the project, so is there a way to overcome this ?Perhaps one of the other events fired by the button will be sufficient (e.g., onmouseup). You could also try to implement your own component for this.

  • How can we trape the Keys Pressed on the Keyboard and do action depending on the keys

    I want to know how we can capture the keys pressed on the keyboard by the user and do necessary action depending on the key pressed by the user....
    For example.... If user press Alt+q the form should go in the Enter Query Mode.
    Can anyone tell me how i can do this in Form 6i....
    Please Help me out from this problem...
    Thanks in Advance
    Shan

    Can somebody point me to what I need to use to
    intercept all the 'keys' for an application.
    At the moment I have set Focus to parts of the
    application when the Mouse is over it, and then get
    the Keys with a KeyListener.
    Is there a way to get the keys, as long as the Java
    app is active.
    - Its an image display program, and I want to use keys
    for - next image , zooom etc etc.
    If soemone could just point me to the right part of
    the API to look in?java.awt.Toolkit.addAWTEventListener()
    then use the mask defined in AWTEvent.KEY_EVENT_MASK to listen to all the events.
    Steve

  • Loading in a second Actions panel with the same functionality as the first, but independent from it

    The actions panel is perfect at what it does; however, if you have a few action sets and, in order to eliminate scrolling, you need to expand them into a double row of buttons, it quickly becomes difficult to maintain. As soon as you delete an action or add an action to it, it disorders the others and you have to reorganize again, which becomes a vicious cycle. I like to keep things organised and neat with all that I do and pretty much the only way to have this feature is to expand it on the back end of the software or, if possible, create a script that loads a second Actions panel with the same functionality as the first but completely independent from it. I assume that the SDK will not allow us to expand on the software in this particular way, as Photoshop is not open source; however, maybe this suggestion will be taken into account for future updates or versions since I have yet to find a suitable way to do this.
    Thank you in advance.
    Kind regards

    That would depend on the links on the page. Some pages have links that refer to different areas on the same page. If you want to force a link to open in a new tab, you can middle-click it.

  • Call jsf h:commandLink action and actionListner in JavaScript

    Hi to all
    any one can help me..
    i want to call action and actionLIstner using javascript
    means....
    i want to set <h:commandLink action="" and actionListner="" in javascript
    but not at where <h:commandLink is defined.
    plz help me...
    thanx in Advance

    If I understand you try to do following?
    <h:selectOneMenu id="persontype"
                                     value="#{bean.personType}" 
                                     styleClass="select"
                                     disabled="#{bean.editMode}"
                                     onchange="changeMode(1)">
                      <f:selectItems value="#{bean.personTypeList}" />        
    <script type="text/javascript">        
          function changeMode(mode){ 
          var comboid;
          switch(mode){
          case 0:
          comboid = document.getElementById("register:persontype");
          break;
          case 1:
          comboid = document.getElementById("registerLegal:persontype");
          break;             
          case 2:
          comboid = document.getElementById("registerPhysical:persontype");
          break;             
          window.location.href ="/register/forms.jsf?personType="+comboid.value;                                
          </script>or like
    <h:commandButton type="submit" value="FILTER" onclick="set_filter();" styleClass="submit"/>
    function set_filter(){
              document.getElementById("formId:filter").value = "filter";
            }

  • How to invoke  javascript function after business action??

    How to call javascript function(such as "window.close(), window.open(...),...") in the action method(public String doBusiness(){...}) of <h:commandButton>?If not,then,is there any alternate approach to call javascript function when the bussiness action method finished??
    Thanks a lot!

    Since your business method is called after the form is submitted, and your code is running on the server, probably the only thing you can do is this:
    Create a custom component (Maybe call it the "onLoad" component) that you always render at the top of your JSP. In the regular situation it wouldn't render anything, but in the case you mention, after your busines method, you would call a method on this new component on the server that would cause it to actually render something the next time it is rendered. When rendered this time, it could then render the "onLoad" method which has your window.close() code in it. The window would then close right away.
    The key is that you are not doing any of this on the client. The form is submitted, your business logic is executed, then the next page is rendered. When the next page is rendered, your javascript could be rendered to close the window.
    If I'm offbase here, someone please say something, I'd hate to send this guy on a wild goose chase.
    Dave

  • How can we assign a JavaScript function on an TextInput action .

    Hello All ,
    I have a requirement that on ON_BLUR event of a MessageStyledText , I have to call a JavaScript function .
    This however should not refresh the page ( No submit action to the controller) .
    So how can we tie the JavaScript function to the TextInput at design time .
    Please auggest the needfull.
    Thank you,
    Srikanth

    Hi Tapash ,
    Actually my requirement was not to submit the form to controller .
    I got the solution for that . I have registered a JavaScript function to the MessageText in PR as
    pageContext.putJavaScriptFunction("callMethod","function callMethod() { var first=document.getElementById('First').value; ");
    OAMessageTextInputBean GoalTextBean2=(OAMessageTextInputBean)webBean.findChildRecursive("Second");
    GoalTextBean2.setOnBlur("callMethod()");
    Regards ,
    Srikanth

  • How to call javaScript function in the form from Action:Tab buttion in workspace

    Hi,
    I want to trigger JavaScript function that I have written in form from Action: buttons in workspace user's account.
    Is there any way that if i hit a button on action bar, it fire a javascript function.
    Reason is: I dont want to place button on the form to perform any action on the form. I want to take control of the form from these buttons. Like submit, edit a form, etc, etc..
    Please let me know if i couldnt explain it properly.
    regards
    Sunil

    Sunil, you want to look at the "Customizing the LiveCycle® Workspace ES User Interface" document at http://help.adobe.com/en_US/livecycle/9.0/customizeworkspaceui.pdf.  The workspace is a Flash component.  For ES4 there's an option to run the workspace in HTML5 which might be more productive long-term.

  • QISRSCENARIO - Action Box - Adding a custom function module

    Hello Experts,
    Under the scenario ID for Performance Award in the transaction QISRSCENARIO I created a custom function module in order to exchange standard. I clicked on the follow-up Functions of the MCSP and then I type my new function module, then when I tried to save the changes I received this error message:
    The function module Z_CUSTOMFUNCTIONMODULE cannot be used.
    Diagnosis
    The function module Z_CUSTOMFUNCTIONMODULE is not suitable to be used as a follow-up function, as the interface does not contain the required parameters.
    Does anyone knows what parameters am I missing?
    Thanks in advance,
    AK

    I would do it this way..
    MCSP is delivered with HRWPC_PCR_SP_TRANSACTION_PA30 as the function module. In SE80, copy the function group HRWPC_PCR_SP_ACTIONS into a custom function group..say  Z_PCR_SP_ACTIONS. When prompted to copy the function modules,select HRWPC_PCR_SP_TRANSACTION_PA30 & name the custom object as , say, Z_PCR_SP_TRANSACTION_PA30. put your custom code inside this function module.Activate the custom function group & function module.Now got to the Action Box & replace the Std function for MCSP with your custom function module.
    ~Suresh

  • Is it possible to run an action from an acrobat javascript

    I'd like to run an action created in the "Action Wizard", from a javascript.
    Is it possible?
    Otherwise I need a way to save a pdf from javascript, with the same settings as set up in the action (downsample images and discarding objects).
    Can that be done?
    Thanks,
    Andreas

    Thanks for confirming that actions can not be started from Acrobat javascript.
    The suggestion to use preflight for optimized save has been done on a couple of questions similar to mine, but never explained in detail, so I'll just add some detail, while exploring it:
    I didn't know where to find the PDFOptimizer settings for preflight in Acrobat Pro XI, but it's here:
    1. Show the "Print production" pane, by checking it in the small foldout menu in the top of the right hand menu.
    2. Under Print production click Preflight.
    3. from the Options menu in the top right corner of the Preflight window, select Create new preflight profile.
    4. Under "Fixups" you will find many of the Save optimized PDF options, such as Downsample images, and discard object.

  • Not able to call action method from the javascript

    I am using weblogic 10.3.2 portal.
    My requirement is to call a action in controller throuhg java script when user selects a different option in a dropdown.
    When try it we are not able to call it is returning null as a elementId. Below is the snippet of my code.
    <%@ page language="java" contentType="text/html;charset=UTF-8"%>
    <%@taglib uri="http://beehive.apache.org/netui/tags-html-1.0" prefix="netui"%>
    <%@taglib uri="http://beehive.apache.org/netui/tags-databinding-1.0" prefix="netui-data"%>
    <%@taglib uri="http://beehive.apache.org/netui/tags-template-1.0" prefix="netui-template"%>
    <netui:html generateIdScope="true">
    <head>
    <netui:base/>
    </head>
    <script language="JavaScript" type="text/JavaScript">
    function SelectBANSubmit(id)
         var scope = document.getElementById("scopeOneSpan");
         alert("value====arv" + scope);
         //var form = document.getElementById(lookupIdByTagId(form,scope));
         //alert("value====arv" + form);
         var knoVal = document.getElementById(lookupIdByTagId(id,scope));
    alert("in method" + knoVal);
         </script>
    <netui:body>
    <span id="scopeOneSpan">
         <netui:form action="getBillDetails" >
         <netui:select dataSource="actionForm.selection" tagId="arvind" optionsDataSource="${actionForm.resDTO.kno}" onChange="SelectBANSubmit('arvind')"/>
              </netui:form>
         </span>
         </netui:body>
    </netui:html>
    Any help would be appreciated.

    Below is my code
    JS Code
    function fundemo(id)
    alert("so currently we are in fundemo function ");
         var scope = document.getElementById("scopeOneSpan");
    alert(scope);
         var check = document.getElementById(lookupIdByTagId('textbox1',scope));
    alert("check id is " + check.id + " and its value is "+ check.value);
    JSP Code
    <%@ page language="java" contentType="text/html;charset=UTF-8"%>
    <%@taglib uri="http://beehive.apache.org/netui/tags-html-1.0" prefix="netui"%>
    <%@taglib uri="http://beehive.apache.org/netui/tags-databinding-1.0" prefix="netui-data"%>
    <%@taglib uri="http://beehive.apache.org/netui/tags-template-1.0" prefix="netui-template"%>
    <netui:html generateIdScope="true">
    <head>
    <netui:base/>
    </head>
    <script type="text/JavaScript" src="D:/testWS/testWebProject/WebContent/WEB-INF/js/test.js"> </script>
    <script language="JavaScript" type="text/JavaScript">
    function SelectBANSubmit(id)
    alert("In JS Method of the JSP File ");
    fundemo(id);
    </script>
    <netui:body>
    <span id="scopeOneSpan">
    <netui:form action="getBillDetails">
    <td >
    <netui:textBox dataSource="actionForm.selection" tagId="textbox1" />
    </td>
    <td>
    <netui:button type="button" onClick="javascript:fundemo('textbox1')" value="Test click"/>
    </td>
    </netui:form>
    </span>
    </netui:body>
    </netui:html>

  • How to call action and actionListner in javascript

    Hi to all
    i want to call <h:commandLink> action and actionListner in javaScript
    for example
    <h:commandLink id="link" onclick="javascript:unction();"/>
    <Script>
    function()
    document.getElementById("link").action="#{someBean.someActon}"
    </Script>
    can i do like that in jsf
    waiting for ur reply

    You can't change the bean action in JS. Just change/delegate the actual action in the bean action method.

  • How to call javascript function & action method on clicking jsf  button?

    I have one jsf custom button. I am checking client side validations in mail by calling javascript function & also sending mail by calling action method of a bean which will execute at server side for onclick event of that button. Because of this when I click on that button its calling both javascript function and action method. So even though validations failed its sending mail. How can I overcome this problem?? Please help me....

    I am asking regarding commanLinks in jsf. I have the following code block in jsf. Even though mailSentMessage('true'); returns false, its calling action="#{emailObjectAction.sendEmail}" method. thats why I got that doubt. try the following code.
    <h:commandLink id="mailBtn123Send"      onclick="return mailSentMessage('true');" value="send mail"     action="#{emailObjectAction.sendEmail}">          
    </h:commandLink>

  • In Custom Tag how to add h:commandbutton with action

    Hi, I created a custom tag in facelets (& Seam), below is the code snippet
    <tag>
    <tag-name>customdiv</tag-name>
    <component>
    <component-type>customtag.MyCustomTag</component-type>
    <component-class>com.mydomain.testing.customtag.MyCustomTag</component-class>
    </component>
    </tag>
    In this class I am using ResponseWriter to generate the content.
    I am trying to add a button and associate action to it but it doesn't provide me any option to associate action to the commandbutton
    "<h:commandButton action="#{childdiv.addChildDiv}" value="add div"></h:commandButton>"
    Also the XHTML doesn't even recognize the h:commandbutton tag
    "HtmlCommandButton htmlCommandButton = new HtmlCommandButton();
    writer.startElement("h:commandButton", htmlCommandButton);
    writer.writeAttribute("value", "add div", "");
    writer.endElement("h:commandButton");"
    Please suggest

    JSF<h:form>
        <h:dataTable value="#{myBean.dataList}" var="dataItem">
            <h:column>
                <h:selectManyListbox value="#{dataItem.selectedItems}">
                    <f:selectItems value="#{myBean.selectItems}" />
                    <%-- Or use value="#{dataItem.selectItems}" if it does depend per row. --%>
                </h:selectManyListbox>
            </h:column>
        </h:dataTable>
        <h:commandButton value="add" action="#{myBean.add}" />
        <h:commandButton value="save" action="#{myBean.save}" />
    </h:form>MyBean (session scoped)private List<DataItem> dataList; // +getter
    private List<SelectItem> selectItems; // +getter
    public MyBean() {
        dataList = new ArrayList<DataItem>();
        // Do your thing. It is just a stub example.
        selectItems = new ArrayList<SelectItem>();
        selectItems.add(new SelectItem("value1", "label1"));
        selectItems.add(new SelectItem("value2", "label2"));
        selectItems.add(new SelectItem("value3", "label3"));
    public void add() {
        dataList.add(new DataItem());
    public void save() {
        // Do your thing to save the dataList. All values are already set in there.
        // Just doing a sysout here to prove it.
        System.out.println("Saved: " + dataList);
    }DataItemprivate List<String> selectedItems; // +getter +setter
    // Just for convenience so that it is readable in the sysout.
    public String toString() {
        return "DataItem[" + selectedItems + "]";
    }For more about datatables you may find this article useful: [http://balusc.blogspot.com/2006/06/using-datatables.html].

  • CommandButton's Action method doesn't  work

    Hi all
    My English isn't very good
    I use jdeveloper 11.1.1.3.0
    I have SelectOneRadio with two options. When I select each option two PanelGroupLayouts' visible should change:
    <af:selectOneRadio id="sor1" layout="horizontal"
    binding="#{Bean1.sor_Value}"
    valueChangeListener="#{Bean1.chg_sor}"
    autoSubmit="true">
    <af:selectItem label="1" value="1" id="si1"/>
    <af:selectItem label="2" value="2" id="si2"/>
    </af:selectOneRadio>
    public void chg_sor(ValueChangeEvent valueChangeEvent) {       
    if (sor_Value.getValue().toString().equals("1")) {
    pgl_1.setVisible(true);
    pgl_2.setVisible(false);
    } else {
    pgl_1.setVisible(false);
    pgl_2.setVisible(true);
    AdfFacesContext.getCurrentInstance().addPartialTarget(pgl_1);
    AdfFacesContext.getCurrentInstance().addPartialTarget(pgl_2);
    In each pgl I have a commandButton with a method related to theirs' action property. but When I click each button nothing happen and their related method don't run.
    but when I use rendered instead of visible in method: "chg_sor" , buttons' action method work well but in this case another error occurs because I can't ppr components that are not rendered.
    I don't know how solve this problem?
    Habib

    Thanks Frank
    In each pgl I have inputText with required=True. and if required field is null and pgl become invisible(visible = false) so the button's Action method on the other pgl(visible = true) doesn't run.
    why this happen?
    Habib
    Edited by: Habib Eslami on Feb 19, 2013 10:00 PM

Maybe you are looking for

  • Is there a way to transfer contacts from Mac Address Book to an iPhone?

    I tried posting this before but no one answered.  I dont currently have an iphone (or any smartphone).  I do have a Mac and I have my contacts in the Mac Address Book (not in an email client like Gmail, Yahoo, or Hotmail) I want to know if I get an i

  • While creating RFx getting error

    hi we are using SRM 7 SP13 classic scenario.while creating RFx getting error. Line 0001: Item type 'Service' not allowed for this Item. i created SC with free text and selected type -service .when purchaser is trying to create RFx getting error like

  • Writing SNMP Manager using SNMP4J

    Hello, I am writing a SNMP Manager that is supposed to do the following: (1) Send snmp commands to snmp-agents, and handle thier response. (2) receive snmp traps from snmp-agents. I am using SNMP4J software package for writing the snmp manager. I wou

  • Aperture & iPhoto

    Dear All, Whenever I connect my iPhone to my mac it always opens Aperture is there a way to change it so that it opens iPhoto instead of Aperture so I import my photo's into iPhoto? Many Thanks Lyon

  • In Yahoo Mail thumbnail photos appear broken in email messages

    I cannot view thumbnail photos in email messages that have photo attachments in my Yahoo Mail. The thumbnail appears as a broken image. When I click on the thumbnail it does open up a valid photo image. The problem occurs all the time in every email