• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSP not setting Bean properties

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am facing this problem for a while and could find any answer. Please help me with this.
I am using Tomcat5.0, j2sdk1.4.2
I am having the useBean syntax as
<jsp:useBean id="mybean" scope="session" class="hello.plans">
<jsp:setProperty name="mybean" property="*"/>
</jsp:useBean>

in my main jsp page.
i am including another jsp page using <%@include file="sub.jsp"%>

and in this sub.jsp page i gave the form action as another jsp page. but when the submit button in the form of 'sub.jsp' is pressed, the values in "mybean" are not getting updated. I made bean property names for 'hello.plans' same as form field names in 'sub.jsp'. Is there something that i am not doing? or doing wrong? any help is appreciated.
Thanks,
Mamatha.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure of your page structure, you might want to post your code.

It sounds like you have the:
<jsp:setProperty name="mybean" property="*"/>
tag in the page with the form. It should be in the page that in that page that receives the post (not the one that sends it).

Also: Java conventions dictate that class names start with an upper case letter. Not following the conventions makes it very difficult for others to read your code.
 
Mam Kat
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to set some properties from main.jsp page and some more from sub.jsp page. So i did put <jsp:setProperty name="mybean" property="*"/> in both the pages. Can i do something like that?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The <jsp:setProperty name="mybean" property="*"/> tag works by parsing the HTTP form parameters, matching them up to the setter methods in your bean, and setting those properties with the form values.

That tag would need to be in the JSP that is handling the form request.

The <%@ include ...%> merges the code before the generated servlet code is created. This means, that the two pages are, essentially, one. You wouldn't need to have the setProperty tag or the useBean tag in each of them. Just make sure that the setProperty tag comes before the include directive.

If all of this seems confusing, it's because it is.
This is why you will often see me (and several of the more seasoned developers who hang around here) recommending that new developers first learn servlets. Once you understand the underlying concepts these tags (which are abstractions of the underlying concepts) are a lot easier to learn.
 
Mam Kat
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ben thanks for your reply.
I know that <%@include makes it a single page. As it's not setting the properties i just tried by putting <jsp:setProperty/> in both the pages.
Right now i am explictly calling request.getParameter() for different form fields and setting the corresponding bean properties. don't know why introspection is not working by itself.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My larger point is that, if Page A contains a form who's action is Page B,
putting a setProperty tag in Page A (or one of it's includes) is pointless.

The parameter values do not exits in the request object until the form has been posted. Page B would be able to retrieve them as request parameters.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you defined appropriate getters/setters for the properties?

ie

jsp:setProperty works with the methods, not with the actual properties.
 
Mam Kat
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stefan,
I defined getter and setter methods properly. thanks for your suggestion.
Ben,
You are right. thanks for the help.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic