File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Difference in property= Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Difference in property="*" for jsp:setProperty and jsp:getProperty" Watch "Difference in property="*" for jsp:setProperty and jsp:getProperty" New topic
Author

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

Salman Raut
Greenhorn

Joined: Mar 31, 2009
Posts: 15
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


Best Regards
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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.


[My Blog]
All roads lead to JavaRanch
Salman Raut
Greenhorn

Joined: Mar 31, 2009
Posts: 15
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

Joined: Feb 22, 2009
Posts: 192
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference in property="*" for jsp:setProperty and jsp:getProperty