954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to call jsp use bean method inside javascript

hi all,

I want to call a class function using beans inside java script. but it is not working. It calls that function only 1 time.

<jsp:useBean id="track" scope="session" class="ReturnProgress"></jsp:useBean>

<script type="text/javascript">
function getProgress()
{
document.getElementById('progress').innerHTML = '<%=track.findProgress()%>';
}


</script>


I want that Whenever user clicks on button , I call getProgress function on onclick event that fetches progress using findprogress() method.
please help.

gshockneo
Newbie Poster
9 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

you probably need to supply some more information. you say it only calls the method once, but are you sure this is the result of your onclick event? if it is infact calling it from the onclick, then each click should call it again, and maybe your output is not actually changing? this would then indicate a issue with your java, and not the java script.

good luck

sillyboy
Practically a Master Poster
686 posts since Mar 2007
Reputation Points: 85
Solved Threads: 64
 

Thanks for reply.
You are right. It gets called when page loads.
Then after each time you click it keeps on displaying same information i.e. it does nt call function.
So how can i make sure that this function does not get called when page loads but on button click.

gshockneo
Newbie Poster
9 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

can you post your html (w/ javascript)?

EDIT: it should just be something like:

onclick="getProgress()"
sillyboy
Practically a Master Poster
686 posts since Mar 2007
Reputation Points: 85
Solved Threads: 64
 
<html>
<head>
<jsp:useBean id="track" scope="session" class="ReturnProgress"></jsp:useBean>


<script type="text/javascript">
function getProgress()
{
document.getElementById('error')='<%=track.findProgress()%>';
}
</script>
</head>
<body>

<p id = "error"> </p>
<button onclick = "getProgress()">click me</button>
</body>
</html>


Is it correct to call this function like this beacuse this function runs on server side.

gshockneo
Newbie Poster
9 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

Hi,

Did you ever resolve this?

I would like to call a set method in a bean using a value that
I extract from getElementById. I can get the value OK and usually
I send these back to my page and access them as request parameters.

I am trying to avoid having to resend the page of course.
i tried this but the JavaScript failed with an error:

clientBean.setClientId(selectedClient.value);


clientBean is a session bean created with a usebean tag.
setClientId is a set method in an entity bean I created.
selectedClient.value is the value I want to pass as an argument.

the Javascript is below:

<head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>ExpenseEntryGet JSP Page</title>
        <link rel="stylesheet" href="css/CascadeMenu.css"/>
        <script type="text/javascript" src="scripts/CascadeMenu.js">
        </script>  
        <script language="java", type="text/javascript">
        function SetSelectedClientID()
            {
             var clients = document.getElementById('clientSel');   
             var selectedClient = clients.options[clients.selectedIndex];
             clientBean.setClientId(selectedClient.value); 
            }

Any idea as to how to access my set method via the usebean this way?
It is the opposite of what you want to do seemingly which is bean value
to tag element value.

Thanks,
Brianhi all,

I want to call a class function using beans inside java script. but it is not working. It calls that function only 1 time.

<jsp:useBean id="track" scope="session" class="ReturnProgress"></jsp:useBean>

<script type="text/javascript">
function getProgress()
{
document.getElementById('progress').innerHTML = '<%=track.findProgress()%>';
}


</script>


I want that Whenever user clicks on button , I call getProgress function on onclick event that fetches progress using findprogress() method.
please help.

bofcarbon1
Newbie Poster
1 post since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You