This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes JSP / Bean prob. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "JSP / Bean prob." Watch "JSP / Bean prob." New topic
Author

JSP / Bean prob.

Anil Vupputuri
Ranch Hand

Joined: Oct 31, 2000
Posts: 527
Hi,
Iam using JRun 3.0 on IIS4.0(sp2), I developed a application using JSP/Bean combination, in JSP, Iam just using useBean to instantiate bean for first time and setting all the properties using '*' and Iam using that bean ID in servlet by just retrieving thru session which already set in JSP.
But when I tried to retrieve all the parameter information, its giving nothing. I guess the bean properties has not been set.
What could be the problem. Is it problem with getter/setter's?
I verified lettering.I use the following syntax
<jsp:useBean id="userProfile" class="UserProfileBean" scope="session">
<jsp:setProperty name="userProfile" property="*"/>
</jsp:useBean>
In servlet, retrieving bean thru session, but Iam getting objectId but property values, which r blank. what could be the reason.
Thx.


SCJP 1.5, SCEA, ICED (287,484,486)
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Verify that your JavaBean methods satisfy the naming conventions (public X getMyProperty(), public void setMyProperty(X myProperty)). Your request parameter names should match the property names, including capitalisation ("myProperty"). The first letter must be lowercase in many implementations. The property's data type should basically be a primitive type or a String.
- Peter
ruilin yang
Ranch Hand

Joined: Feb 25, 2001
Posts: 334
1) check if the names of variables match between JSP and your bean class.
2) use the following syntax:
<%@ page language="java" %>
<jsp:useBean id="objectID" scope="session" class="classID" />
<jsp:setProperty name="objectID" property="*" />
Please note you do not need:
</jsp:useBean>
It will work reliably.
hope solve your problem.
Ruilin
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by ruilin yang:
[...]Please note you do not need:
</jsp:useBean>

Good point, Ruilin. With Anil's original code, the properties will only be set when the bean is first instantiated. This can be a very sensible thing to do, but Anil may not have intended this.
- Peter
Anil Vupputuri
Ranch Hand

Joined: Oct 31, 2000
Posts: 527
Thx for ur responses. I have tried using the above code, but void. I dont understand why properties aren't setting. Even I put debugging statements in getters/setters but none is being printed on console. What could be the reason.
Thx.
Anil Vupputuri
Ranch Hand

Joined: Oct 31, 2000
Posts: 527
Any solution....waiting for.
Thx.
Brett B Doehr
Greenhorn

Joined: Jun 04, 2001
Posts: 11
To reiterate Peter's point, are you sure that you have exact matches between your request parameter names and the JavaBean variable names, and the appropriate set/get methods? Maybe you can post more of your code. For example, if your request came from a page that had:
<input name="fooBar" value="" type="text">
then your JavaBean class should have something like:
public class UserProfileBean {
private String fooBar;
...
public String getFooBar() {
return fooBar;
}
public void setFooBar(String newBar) {
fooBar = newBar;
}
}
Anil Vupputuri
Ranch Hand

Joined: Oct 31, 2000
Posts: 527
Hi all,
I got it correct, the mistake is Iam setting bean using

before passing to the servlet, Iam setting all the properties , which are null. Those properties wont set even I fill up some text fields. So I need to check in Jsp like


[This message has been edited by Anil Vupputuri (edited June 14, 2001).]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JSP / Bean prob.
 
Similar Threads
JSP, Beans and Session
A JavaBean inside a JSP function
set all form parameters using jsp:setProperty
JavaBean vs Post from a JSP
beans