Calling JSP bean function on button OnClick

Hi-
A NewBie question....
I have a .jsp page and supporting .java bean.
I registed the bean in .jsp page using <jsp:useBean ...>
I want to fire a function defined in that bean on the click of a button which is defined in the .jsp page
So I am doing something like this... seems like not the correct way to do since it fires this script all the time, not just when the button is clicked.
<input name='click1' type='Submit' value='Click1' onClick='<% testBean.click1Clicked (); %>'/>
Thanks for your help.

Hi Kishor-
Thanks for the reply.
I realize that might be the case, as u explained in your two points.
so now I have created a hidden input field and use it's value as a way to communicate between javascript and jsp. and in bean's function I check the value of this hidden field, which will be set by the OnClick's javascript and then proceed accordingly.
Is this the correct way to accomplish what I am trying to?
Thanks again

Similar Messages

  • To call a bean function to set a property value with hx:ajaxRefreshRequest

    I have an input box
    I need to output some text onto an output box,When the input box value changes
    I am using Ibm jsf implementation and RSA 7.0,JSF 1.1 implementation
    I know how to call a bean property's setter method using this hx:refresh submit and associated behaviours and target actions.
    As explained in this tutorial
    http://www.ibm.com/developerworks/rational/library/06/1205_kats_rad2/
    But my aim is to call a bean function other than the setter method,because i could do some business logic there and give output.This is possible via setters too,but i believe thats a poor programming practice.
    Hope ppl have got a clear picture of my problem.
    Help me in this.

    You can use any jsf implementation you want, I suggested you only the steps to accomplish the task but I don't know the components you are using...
    You can also accomplish the task without Ajax at all using "classic" http requests but it will be very frustrating for your users...
    Catch client side event (input value change) -> fire an action that update the model -> update presentation layer with up to date model values

  • Call managed bean function using javascript

    Any one help me how to call managed bean function through Javascript onload() event.

    What do you want to do after all? Isn't the constructor/initblock of the bean sufficient? Which JSF version/implementation are you using?

  • How to call a bean method through a javascript function

    I dont discover any problems calling the bean method in this maner:
    <%= helpdesk.data() %>
    But, when I use a Button Onclick= to call the script function and which then is going call my bean method
    an error on the page is reported!
    I have include som code which gives you the idea of what Iam searching for. And is it possible to call
    the bean method without doing from a new jsp page?
    If you have any suggestions to why it doesnt work, please let me know.
    I use Apache Tomcat 4.0
    Best regards Micah.
    <jsp:useBean id='helpdesk' scope='application'
    class='helpdesk.testdb'/>
    <html>
    <head>
    <script language="javascript">
    function broadcast()
    helpdesk.data();
    </script>
    </head>
    <body>
    <input type="button" value="Broadcast" onclick= broadcast()>
    </body>
    </html>

    It's actually quite simple:
    Beans run server-side
    Javascript runs client-side
    So you will never be able to run server-side-code thru the client...

  • How to call session bean's method in JSP

    Hi All,
    I am working on a JSF web application by using sun studio creator.
    The first page have a button, the onClick javascript is as following, which bring up a alert box showing user login name.
    In JSP file, how can I call session bean's setUserName(String name) function (which I would like to store this UserName). So the following pages can use this information.
    If I can not do it this way, is there any other way to do it?
    Thanks in advance.
    var net = new ActiveXObject("wscript.network");
    alert(net.UserName);
    In managed-beans.xml
    <managed-bean>
    <managed-bean-name>BasicInfo</managed-bean-name>
    <managed-bean-class>treepractice.BasicInfo</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>

    You can find more information/details/examples at their own website.
    On the other hand, do you realize that that ActiveX stuff is IE proprietary? And that it is a browser configuration whether to allow them or not? And that this configuration is in IE7 defaulted to an (annoying) warning box before execution which is just bad for the user experience?
    With other words, forget that ActiveX garbage. Alternatives are Applets (not recommended) or Java Web Start (recommended).

  • Call function from button

    hello, i have a jsp page and i want to call a java function when the user presses a button, how can i do that? Thanks

    Yes, I already have the button in a form. Have a look at my source code
    <form name="form1" method="post" action="">
    <p>
    <input type="file" name="filePath" >
              <input name="OK" type="button" value="OK" onClick="<% readFromFile(request.getParameter("filePath")); %> "> //readFromFile is the function i want to call
         </p>
    </form>
    What am i doing wrong?

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

  • Help needed in calling a javascript function from a jsp

    Hey guys,
    I need help.
    In my jsp I have a field called date. When i get date field from the database, it is a concatination of date and time field, so I wrote a small javascript function to strip just the date part from this date and time value.
    The javascript function is
    function formatDate(fieldName)
              var timer=fieldName;
              timer = timer.substring(5,7)+"/"+timer.substring(8,10)+"/"+timer.substring(0,4);
              return timer;
    Now I want to call this javascript function from the input tag in jsp where I am displaying the value of date. Check below
    This is one way I tried to do:
    <input size="13" name="startDate" maxLength="255" value=<script>formatDate("<%=startDate%>")</script> onChange="checkDate(this)">
    I even tried this:
    <input size="13" name="startDate" maxLength="255" value="'formatDate(<%=startDate%>)'" onChange="checkDate(this)">
    But it dosen't work
    Please help. I am struggling on this for days.
    Thanks,
    Ruby

    Hey all you developers out there , Pleaseeee help me with this one.

  • How to call java script function from JSP ?

    how to call java script function from JSP ?

    i have function created by java script lets say x and i want to call this function from jsp scriplet tag which is at the same page ..thanks

  • JSPs and calling a DB function/procedure

    I looked at an example written by Oracle and I saw that they put in the <form> tag (in a JSP) an "action" that is really a name of a DB procedure. It was in the form of:
    schemaName.packageName.procedureName
    First: I've tried to do that myself -- just create simple HTML page, have an <input> with the "type" of "text", and in the <form>'s action put the procedure's full 'path' name. Did not work. Am I missing anything? What's the right way to do it?
    What I see in the browser's URL is:
    "http://serverName:portNum/.../pls/portal30/PORTAL30.MYPACKAGE.MYPROCEDURE?" But I see an empty page.
    Second: looking at the actual procedure body of the example, I saw that the procedure's parameters are given the same exact name as the names of the <input>'s in the JSP page. Like:
    <input type="text" name="txtFirstName">
    and in the procedure:
    someProcedureName(txtFirstName integer)
    Is that the way to pass parameters to a DB procedure? (by using the same name)
    Third: Can I call a DB function from a JSP's <form>'s "action" and get the return value somehow? Meaning, I want to know whether the function's operation was successful and no exceptions were thrown. And if there were some exceptions thrown, I want to let the user know somehow.... How?
    A lot of questions, I know, but I still gotta know... :-)
    Thanks!
    Dan

    Dan,
    Sorry for the late answer, hope it's not too late yet.
    1) If you make your DB procudures accessible from a plain browser, you can obviously define that URL as an html form action. Make sure that your procedures are accessible when typing in the URL in your browser. You need to check whether you have privileges to access the procedure, and the DAD settings too.How do I make my DB procedures accessible from a plain browser?
    Is just making a "GRANT" to that procedure to that user enough? And what do I need to do with the DAD?
    Is the "?" question mark in your URL, or has it been added by the forum only? You don't need it as long as you don't want to pass parameters.Question mark was added by the browser..
    3) I'd probably do it through passing the error code to the JSP as a parameter. You find information about reading parameters in the PDK. Yes, but how do I pass it BACK to the browser? I do know how to pass parameters to a "regular" JSP (one that has nothing to do with the portal). But this one involves the DB -- how do I tell my DB function to send an "answer" back to the browser? It would send the function's return value straight to the browser because the browser was the thing that called it in the first place?
    Dan

  • Calling wml script function in jsp?

    how can i write/call wml sciprt function(for doing client side validations) in a jsp?
    becoz we are using wml code in jsps, but we are not using any wml script functions for client side validations.
    please help me ...

    What do you mean by "wml".. Java server pages are a server side technology. They do not execute on the client.

  • How can I call a server function by a button?

    Hello, world...
    I have a problem...
    I need to call a server function by pushing a button. I put the condition on the label...
    This is my script:
    writeBtn1.addEventListener (MouseEvent.CLICK,writeFile1);
    private function writeFile1 (e:MouseEvent=null):void
                 checkBtn = (writeBtn1.label == "Conferma" && textInput1.text != "" );  //my condition...
                 if (checkBtn)
                     nc.call ("WriteNow",null,textInput1.text+"\n");
                    writeBtn1.label = "Fatto";
    I'd like to call the function on the release of the button...
    Can someone helps me?
    Please...
    Emiliano.

    use:
    writeBtn1.addEventListener (MouseEvent.CLICK,writeFile1);
    writeBtn2.addEventListener (MouseEvent.CLICK,writeFile1);
    writeBtn3.addEventListener (MouseEvent.CLICK,writeFile1);
    private function writeFile1 (e:MouseEvent=null):void
                if(e.currentTarget==writeBtn1){
                 // do whatever
               } else if(e.currentTarget==writeBtn2){
                 // do whateverelese
              } else {
                 // it's writeBtn3

  • How to call Java Beans from JSP (eg.put them in a WAR or package)

    Can anyone explain to me what are the steps and ways to call java beans from JSP?

    1st, put the javabean classes in the right place:
    the web-inf/classes/your_bean.class directory of corresponding web application
    2nd in your jsp page:
    <jsp:useBean id="obj_var_name" class="your_bean"/>
    <jsp:setProperty name="obj_var_name" property="smthg" value="smthg_calue"/>
    Micheal

  • Calling Session Beans in JSP ?

    Hi Folks,
    I am new to EJB3, I am doing simple applicatuions.
    Can any one please tell me how to call session beans in jsp page.
    for example my case is.. iam entering two diffrent data, lets say user name and password in jsp page and this should go in data base thru JPA (entity beans)
    Iam able to enter data from JPA in data base but if the same i have to fetch from JSP page.. iam not getting..!
    I would really appretiate for your help i need it urgent...!
    thanks in advance.

    abishek1983 wrote:
    Hi Folks,
    I am new to EJB3, I am doing simple applicatuions.
    Can any one please tell me how to call session beans in jsp page.
    Not. You can, technically, but you shouldn't. JSP should be for display purposes only, containing no Java code whatsoever.
    for example my case is.. iam entering two diffrent data,Wrong. You cannot possibly have "2 data", the very concept is impossible.
    You can have "2 data items" which is probably what you intended to say?
    lets say user name and password in jsp page and this should go in data base thru JPA (entity beans)
    Iam able to enter data from JPA in data base but if the same i have to fetch from JSP page.. iam not getting..!
    Same way you insert them. Of course JPA entities are distinctly different from entity beans. The very concept of entity beans no longer exists in the context of JPA, it's solely used to mean EJB 2.1 or earlier entity beans.
    I would really appretiate for your help i need it urgent...!
    It's not urgent.

  • Call jsp function in javascript without using Applet

    anyone knows how to call jsp function in javascript .
    just as follows:
    <%!
    public string jspcall()
    return new String("just a example");
    %>
    <script language="javascript">
    <!--
    temp = jspcall();
    //->
    </script>
    it's desn't work.
    any suggestion will help!

    it's was not able to call a jsp function in javascript.
    jsp function was on server site while javascript normally on the client site.

Maybe you are looking for

  • How to create a conuntry Hierarchy

    For anyone who need... create or replace procedure prc_path IS cursor cun is select distinct country from test1; cursor reg(v_con varchar2) is select distinct region from test1 where country = v_con; cursor st(v_con varchar2 , v_reg varchar2) is sele

  • SELECTION-SCREEN-ICON

    Hi ,   How to have a icon for a pushbutton in application toolbar using selection-screen.   help me out. Thanks.

  • Front Row Incorrectly Reads iTunes Metadata under Snow Leopard?

    There is a serious problem with Front Row under Snow Leopard. The program is unable to correctly read the TV metadata from iTunes and does not correctly filter/organize the data. TV episode/season/title data is not read resulting in a completely diso

  • How to remove previous Skype account/profile on th...

    Several years ago my nephew used this computer to Skype with his brother in Denmark.  He created his own profile.  We uninstalled Skype after that.  Now, when I would like to create my own account to Skype with my son in Spain, when I want to install

  • Multiple Row Update From Similar Table

    I am attempting to update a table based on similar table if the Entry_Type is D and they have the same log_numbers. I have created queries to show me the results I want but am having some difficulities getting the update to happen. I am getting a sin