Rene Muniz wrote:
>
> I am using ServletExec and I see the same behavior, even when I specify property name
>
> <jsp:setProperty name="bean" property="propertyName" />
>
> Looking at the source code I noticed that my set method in my bean is not being
>called at all
> because of the spec specifies that if the field is an empty string "" the property
>does not get
> changed.
> So what about the following scenario.
> If the field first returned some data (meaning at some point in the past the user
>filled
> data in) like in:
>
> Cell Number: <INPUT TYPE="TEXT" NAME="cellNumber" VALUE="<%=bean.getCellNumber()%>" >
>
> when the user cleared the attribute expecting it to delete it from the backend
>storage
> it will find that
> the data is still there. This causes a lot of trouble because you can't use
>setProperty
> to set data in
> your bean. To me that is VERY STUPID, I had to get the parameters from the request
> and pass them to the bean to ensure that the method would be called and the field
>would
> get cleared.
I'm pretty sure that the behavior is specified this way to be consistent for
all types of form elements.
For instance, if you use a check box or selection list element, the corresponding HTTP
parameter is only sent if the element is selected. In this case the JSP container has
no way to figure out which property setter method to call with a null value (or empty
string). For text field elements, the corresponding HTTP parameter is always sent, with
the value empty string if it's not filled out. So here the JSP engine *could* call the
setter method, but it would not be consistent with the behavior for check boxes etc.
> Has anybody found a nicer way of doing that? As the amount of fields increases so
>does
> the jsp code to handle this.
First of all, this is only a problem for beans in the session or application scope.
In page and request scope, a new bean instance is created every time the form is
submitted so all bean properties starts out with their default values.
Assuming you really need to keep the bean in the session scope, one way around this
is to add a "reset property" to your bean, e.g. a method called setReset(). This
method resets all the other properties to their default values. You can then use
it like this in your JSP page:
<jsp:setProperty name="bean" property="reset" value="" />
<jsp:setProperty name="bean" property="*" />
Hans
> On Fri, 11 Feb 2000 22:45:34 +0000, D. J. Hagberg <[EMAIL PROTECTED]> wrote:
>
> >In section 2.13.2.1 of the JSP 1.0 specification where the syntax of
> ><jsp:setProperty name="x" property="y" param="z"/> is documented, the
> >following appears:
> >
> >---------------------- snip -------------------------
> >property
> >
> >The name of the Bean property whose value you want to set.
> >
> >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.
> >---------------------- snip -------------------------
> >
> >I am confused by the last sentence in this spec (if a parameter has a
> >value of "" [which I presume to mean the empty string], the
> >corresponding property is not set). This is apparently a changed
> >behavior between JRun 2.3.3 build 155 and build 157.
> >
> >Does this rule only apply when property="*" or does it apply for ALL
> >specified property names? In other words, to pick up empty form
> >elements do I simply need to break out my
> >
> ><jsp:setProperty name="bean" property="*" />
> >
> >to
> >
> ><jsp:setProperty name="bean" property="formElem1" />
> ><jsp:setProperty name="bean" property="formElem2" />
> >. . .
> >
> >or do I need to write special code to handle form elements that the user
> >could have deliberately (and reasonably) emptied out, such as the second
> >line of an address?
> >
> >Thanks for any input...
> >
> > -=- D. J.
--
Hans Bergsten [EMAIL PROTECTED]
Gefion Software http://www.gefionsoftware.com
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html