Forums Register Login

page 360 if property="*"

+Pie Number of slices to send: Send
In page 360,

Given
<jsp:useBean id="person" type="foo.Person" class="foo.Employee">
<jsp:setProperty name="person" property="*"/>
</jsp:useBean>

In foo.Person we have "name" property & in foo.Employee we have "empID" property.

The request parameter names in the html are "name" and "empID".

The JSP handwriteen say's that
"I want you to iterate through the request parameters, and find any that matches this bean's
property names and set the value of the matching properties equal to the value of the corresponding request paramaeter."

My understanding of the above is that both the properties of the bean (name and empID)will be set.

Is it wright.
But in page 414 BULLET POINTS it says that
"If you specify a 'type'attribute in <jsp:useBean>,you can set properties in <jsp:setProperty> ONLY on properties of the 'type' ,but NOT on properties that exist only in the actual 'class' type."


since the type of <jsp:useBean> is foo.Person and since it contains only name property.
ONLY it will be set.empID will not be set.

Is it Wright.

PLEASE explain me.
satish
+Pie Number of slices to send: Send
I am also confused.
This code also working.


<%@ page import="foo.*" %>
<html>
<body>
<jsp:useBean id="person" type="foo.Person" class="foo.Employee">
<jsp:setProperty name="person" property="name"/>
<jsp:setProperty name="person" property="empID" value="<%= new Integer(request.getParameter("empID")).intValue()%>"/>
</jsp:useBean>
<jsp:getProperty name="person" property="name"/>
<jsp:getProperty name="person" property="empID"/>
</body>
</html>

 
+Pie Number of slices to send: Send
Hello Satish,

Page 360 of HFS is correct. The jsp:setProperty action, when used with property="*", will iterate over all request parameters and attempt to set the property within the JavaBean, irrespective of the 'type' as declared in the jsp:useBean tag. The jsp:setProperty action uses introspection to find the setter methods for each request parameter; and introspection ignores the "declared type" of the object and deals directly with the "actual class" of the object. Make sense?

The penultimate (second to the last) bullet on page 414, is not correct.

However, that bullet is right in one respect that wasn't highlighted in the book. When the jsp:useBean action is used, the JSP page will now include a local variable in the generated service() method, which does follow polymorphic rules.

For example, the JSP code:


Is roughly equivalent to the following scriptlet code:


Notice that the declared type is the superclass, Person, but the created object is of type Employee.

What do you think this code would do?


If you guessed, that a compile-timer error is thrown, then you are correct. Java "typing rules" are in effect even within a JSP page.

HTH,
Bryan
[ December 05, 2006: Message edited by: Bryan Basham ]
+Pie Number of slices to send: Send
Hi Bryan,

Is this (page 414 bullet) going to be included in the errata?

I could not find it here: http://www.oreilly.com/catalog/headservletsjsp/errata/headservletsjsp.confirmed

There have been a number of posts on this topic, and it will definitely help.

Thanks,
Anu
+Pie Number of slices to send: Send
Hello Anupama,

I have submitted an errata entry for this mistake.

Thanks for the suggestion,
Bryan
+Pie Number of slices to send: Send
Hi All,
<jsp:getProperty name="person" property="empId"/> does not work. So we can take the statement "the property accesed depends on type" for jsp:getProperty. But as pointed earlier the jsp:setProperty property="*" sets all the Properties eventhough type does not have the property.
<jsp:useBean type="Person" class="Employee">
Eliminate 95% of the weeds in your lawn by mowing 3 inches or higher. Then plant tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1878 times.
Similar Threads
Polymorphism of the jsp:useBean
jsp:useBean tag query.
HFSJ Bean related standard actions question
Bean standard action doubt
HFS page 361
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 00:32:14.