Solved

Setting Values for a Javabean from JSP

Posted on 2008-10-27
2
284 Views
Last Modified: 2013-11-24
Experts,
  I have a table display that when the user clicked on a row a jsp function is called with the selected table row id.  I would like to pass the selected rowid to my java class (bean) so that it can do some processing with the selected row (i.e. delete the row from the database).  I am having trouble setting the values in my java bean from the jsp page; though, I have no trouble getting values from the bean to my jsp.  Please help!

---
...
<jsp:useBean id="mybean" scope="request"
             class="test" />
..
..
function rowSelected(num)
{
alert("selected row:"+num); //popup window shows the correct selected row number
  <%
  mybean.setRowSelected(999); //these two lines produced the expected results
  System.err.println("Row ID:"+mybean.getRowSelected());
 
  mybean.setRowSelected(num); //but with this...jboss throws exception about not knowing what num is?
%>
}
...
...
0
Comment
Question by:johnchan2000
2 Comments
 
LVL 27

Accepted Solution

by:
rrz earned 500 total points
Comment Utility
First of all, you should put your bean in a package.  After doing that use it in your bean tag.
<jsp:useBean id="mybean" scope="request" class="your.package.test" />  

>mybean.setRowSelected(num); //but with this...jboss throws exception about not knowing what num is?
num , I think is a javascript variable and is in the browser at the client.  After the user selects a row, to get num to the server you must either make a request with a url with num as a parameter, or submit a form, or make a AJAX call.  
0
 
LVL 1

Author Closing Comment

by:johnchan2000
Comment Utility
You're confirming that what I was trying to do is not feasible.  I am now using  hidden fields to pass along the values - and it works just fine.  Thanks for the help.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now