Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference in property="*" for jsp:setProperty and jsp:getProperty

 
Salman Raut
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have 2 questions:
1)
The following is the scenario:
The user enters the form data in a html page. The form action points to a jsp page.
In the jsp the values are set in the bean using jsp:setProperty and retrieved from the bean and displayed on the jsp using jsp:getProperty.
The text boxes in the html have the same name as the properties in the bean.

SO I am able to set all the properties in the bean from jsp using:


The container, after seeing property="*" in jsp:setProperty, does the mapping between html text box names and bean property names and then populates the bean.

But when I want to retrieve the bean values in the jsp:getProperty using *, it gives an error. I am forced to retrieve values one by one.
In short, this statement fails:




Is there any logical reason why the container does not obey us for retrieving all the values?




2) The bean class has to be in a package. In other words src is the home directory for all the source files, I cannot put MyBean.java directly inside the src folder. If I put it directly under src folder, it gives an error.
I am forced to package it inside the src folder.
Is there any reason for this rule?

Thank you

Best Regards
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any logical reason why the container does not obey us for retrieving all the values?

What would you expect to do with it ?

I am forced to package it inside the src folder. Is there any reason for this rule?

From JSP2.0, it is illegal to refer to any classes from the unnamed package. The reason is described in the JSP specification, JSP.11.2 JSP Page Implementation Class :
[i]As of JSP 2.0, it is illegal to refer to any classes from the unnamed (a.k.a. default) package. This may result in a translation error on some containers, specifically those that run in a JDK 1.4 or greater environment. It is unfortunate, but unavoidable, that this will break compatibility with some older JSP applications. However, as of JDK 1.4, importing classes from the unnamed package is not valid (see http://java.sun.com/j2se/1.4/compatibility.html#source for details). Therefore, for forwards compatibility, applications must not rely on the unnamed package.
 
Salman Raut
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Christophe,

I understand why java beans must be inside a package.

About the jsp:getProperty:

I expected


this code to spit all the values in the jsp in the same order as they are defined in the bean.
It might not be very useful practically but I was wondering it should still not give me a error.


 
Ryan Beckett
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can assure you the star operator maps POST data to bean properties. It doesn't work the other way, its just the rules of the language. Personally, I wouldn't present information in a text field, and I think the gurus agree with me.

And, yes your classes must be in a package. Just another rule. Good luck.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this code to spit all the values in the jsp in the same order as they are defined in the bean.

I'm not sure that the order of the fields are preserved when you get them using reflection, but that would have to be checked.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic