Brian Slezak wrote:
>
> > Okay, let's set stage here to make sure we talk about the same thing. What
> > I responded to earlier was what the JSP spec says about calling bean access
> > methods automatically when <jsp:setProperty name="foo" property="*"> is used.
> > This is what I referred to, from section 2.13.2.1:
> >
> >   If you set propertyName to * then the tag will iterate over the current
> >   ServletRequest parameters, matching parameter names and value type(s) to
> >   property names and setter method type(s), setting each matched property to
> >   the value of the matching parameter. If a parameter has a value of "", the
> >   corresponding property is not modified.
> >
> > If you're talking about something else, such as using request.getParameter()
> > in a scriptlet to manually set a bean property value, then the rules are
> > different. If you call the bean's access method like this, the property will
> > of course be initialized to "". Same thing if you use a <jsp:setProperty>
> > action like this:
> >
> >   <jsp:setProperty name="foo" property="bar"
> >     value="<%= request.getParameter(\"bar\") %>" />
> >
> > Hans
> > --
> > Hans Bergsten           [EMAIL PROTECTED]
> > Gefion Software         http://www.gefionsoftware.com
>
>     Ok.  Well I have tried using the setProperty tag with property="*", but it
> had no effect whether left out or not.  What I'm talking about is say you have a
> form, and just hit submit without entering any information in any fields.  Take
> this example (assuming you have an accompanying Bean to go with it):
>
> <html>
> <head>
> <title> Test Page </title>
> <jsp:useBean id="bean" scope="session" class="nameBean" > </jsp:useBean>
> <body>
> <p>The property name is null = <%= ( request.getParameter("name") == null ) %>
> </p>
> <form method="get">
> <p>Name:<input type="text" name="name" size="20" value=" <jsp:getProperty
> name="bean" property="name" /> "></p>
> <p><input type="submit" value="Submit" name="submitBtn"><input type="reset"
> value="Reset" name="ResetBtn"></p>
> </form>
> </body>
> </html>
>
>     When this page is initially loaded, it will tell you that "The property name
> is null = true".  After hitting the submit button with NOTHING in the field, it
> will tell you "The property name is null = false".

That's because you never set the property value of the bean, and you are not
testing if the *property* is null, you're testing if the *parameter* value is
null. That's a big difference. If you change the test like this you should see
that the property remains null:

  <jsp:useBean id="bean" class="nameBean" />
  <jsp:setProperty name="bean" property="*" />
  The property name is null = <%= ( bean.getName() == null ) %>

Note that I added <jsp:setProperty> to set the bean's properties. I also
removed scope="session", since I assume you're just trying to figure out
how it works. If you place the bean in the session scope, it just complicates
things. And finally, I test the property value instead of the parameter
value.

When you understand how this works, you can try putting the bean in the
session scope again. You will see that if you submit the form with a
non-empty value in the form field, the matching bean property will be
set. If you then submit the form again, but now with the field empty,
you will see that the bean property value remains the same (since the
<jsp:setProperty> action does not call the property setter method at all
when the corresponding parameter value is an empty string).

Hans
--
Hans Bergsten           [EMAIL PROTECTED]
Gefion Software         http://www.gefionsoftware.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to