File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes My bean doesn't quite work Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "My bean doesn Watch "My bean doesn New topic
Author

My bean doesn't quite work

Bryce Martin
Ranch Hand

Joined: Nov 19, 2007
Posts: 269
I've been programming jsp's for a few months now. So far I have programmed in the Model 0 pattern ;)

But after constantly being yelled at by article after article I decided to take small step away from Model 0 and try to make a bean. So I created my class...



It is very simple. I have a form with these 5 fields and a Submit button. On submit I run some javascript to see if the search criteria falls into a certain set of combinations that are allowed. After that it goes over to a jsp for some processing. But the only value that actually gets held by the bean is the first field PO. The next three return null and the last one return 0.

I did an out.print(myPackage.getPO()); ect, for all my fields. That is how I found out their values. Why would the last string be a 0 and not a null, and why wouldn't they be taking to the bean? Any ideas?

PS. I'm new here. Please be nice ;)
[ November 20, 2007: Message edited by: Bear Bibeault ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

You didn't mention what your bean has to do with your form.

While you're trying to take steps in the right direction, an important one to take -- and now is a really good time - is to stop submitting data to JSPs. Submit to a servlet that performs any data processing.
[ November 19, 2007: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bryce Martin
Ranch Hand

Joined: Nov 19, 2007
Posts: 269
I just need it to redirect to the correct page based on the search combination that was used. I'd like to start using servlets but I'm just trying to get one thing working at a time. The problem isn't on my resulting JSP. The problem is with the form info being picked up by the bean. Why isn't that happening??
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

How are you passing the form information to the bean?
Can you post the JSPs that use it (or the significant part, if they're long)?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bryce Martin
Ranch Hand

Joined: Nov 19, 2007
Posts: 269
OnSubmit i go to linkagebean.jsp where this code happens...



if I entered something into the PO field it sees it, but the next 3 are always null, and the last one is always 0. Here is the form code on my Selection.jsp.



I do some validation with javascript as to the choice combinations that are allowed. Nothing special there.

I don't put any kind of bean tag on the Selection.jsp page. Do I need to? I didn't think I did. Its odd that it only picks up the first field in the bean.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Your parameter names don't match the bean specification.

The tag:
<jsp:setProperty name="myPackage" property="*"/>
instructs the JSP engine to match the request parameters with your bean's properties.

So, if you're bean's property methods are getJob and setJob, the form parameter should be "job", not "Job".

You might have trouble with "PO".
If so, the easiest thing to do is rename it to purchaseOrder and then rename the bean properties to getPurchaseOrder and setPurchaseOrder.
Bryce Martin
Ranch Hand

Joined: Nov 19, 2007
Posts: 269
Can you explain how the case sensitivity works? It seems counterintuitive that the cases of job and Job don't match. What are the rules for this?

PS...forget about the 0 value. That is not related to my bean. I found out what that was. It was from some code farther down on my linkagebean.jsp

I almost have it, i just have to resolve the PO issue. I think i'm just going to make it Po instead of PO...that should do it.
[ November 20, 2007: Message edited by: Bryce Martin ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If you google for "Java Ben Specification" you can find all the particulars.

In a nutshell, bean properties start with a lower case letter and are camel syntax.
Examples:
firstName, lastName, socialSecurityNumber, etc..

The mutators and accessors should use the standard get/set syntax.
Examples:
getFirstName, getLastName, getSocialSecurityNumber

So, if your form param is "myParameter", the JSP engine will try to match it to a method in your bean named "setMyParameter".

Two letter variable names can get tricky (Like 'PO') so I tend to avoid them.
Bryce Martin
Ranch Hand

Joined: Nov 19, 2007
Posts: 269
Ok. So I'm still having trouble with this. I've tried so many different ways of doing this but it just won't pick up my purchaseOrder in the bean. I have two different values that have some mixed cases. The first one is purchaseOrder, the other one is custName. custName works fine. I get no errors and the data displays just perfect. So I've modeled purchaseOrder after that but it still can't find it. I'll keep playing with it, but I'm out of fresh ideas as to why it won't see it...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Is it purchaseOrder or po?

Is your accessor named getPurchaseOrder()?

Are you sure that the updated and compiled bean is in the right place? Have you restarted the app since compiling?
Bryce Martin
Ranch Hand

Joined: Nov 19, 2007
Posts: 269
Good lookout on the accessor. That was the one thing I forgot to change. I stared at that for a while ago and just didn't see it.

Thanks a Ton.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: My bean doesn't quite work