Thanks for your answer but this doesnt work! The following lines have no affect on the bean: <jsp:setProperty name="myBean" property="firstName" value="<%=null%>"/> <jsp:setProperty name="myBean" property="firstName" value="<%=""%>"/>
Which container are you using? I've tested this with Tomcat 4.1.24 and it works as it should; the Java expression value is used as-is to set the property to null or an empty string.
<jsp:setProperty name="myBean" property="firstName" value=""/>
A "value" attribute with a static empty string means the property setter method isn't called; this is according to the spec. But with a Java expression, as above, it should work (and does in TC 4.1.24).
Also: <jsp:setProperty name="myBean" property="*" value=""/> or <jsp:setProperty name="myBean" property="*" value="<%=""%>"/> causes: org.apache.jasper.JasperException: jsp.error.setProperty.invalid
Right. As someone else pointed out, you're not allowed to mix the "*" syntax with the "value" attribute.
Any other ideas?
Some ideas have already been provided by others, such as removing the bean and create a new one that gets populated with the current values, or to define a "reset" property with a setter method that resets all other property values to their defaults:
<jsp:useBean id="myBean" scope="session" class="..." /> <jsp:setProperty name="myBean" property="reset" value="whatever" /> <jsp:setProperty name="myBean" property="*" />
But as you describe in another reply, when you only want to reset a subset of the properties it's not a nice solution, since view logic creeps into the model. In this case, resetting all properties that correspond to text fields with a Java expression may be better:
<jsp:useBean id="myBean" scope="session" class="..." /> <jsp:setProperty name="myBean" property="firstName" value="<%= null %>" /> <jsp:setProperty name="myBean" property="*" />
or if you use JSTL:
<jsp:useBean id="myBean" scope="session" class="..." /> <c:set target="myBean" property="firstName" value="" /> <jsp:setProperty name="myBean" property="*" />
The best approach for a complex case like this is probably not to use <jsp:setProperty> at all; use an MVC architecture (maybe using Struts) to let a servlet (or Action class) process the request and forward to JSP pages just for rendering the response.
Hans
-----Original Message----- From: Hans Bergsten [mailto:[EMAIL PROTECTED] Sent: Thursday, June 12, 2003 5:25 PM To: [EMAIL PROTECTED] Subject: Re: JSP:Setproperty and empty strings
Tim Davidson wrote:
yeah, the spec is unclear on this point. I have tried this and it doesnt have the desired behaviour: <jsp:SetProperty name="RequestParmBean" property="inputfieldA" value=""/> This will not set inputfieldA to an empty string. Does anyone know why they implemented it in this way?
I think it was for consistency with the auto-population model, i.e., when using property="*". But, the result is very confusing, I agree.
This should work, though, since a request-time attribute value is used as-is:
<jsp:setProperty name="RequestParmBean" property="inputfieldA" value='<%= "" ' />
or to set it to null:
<jsp:setProperty name="RequestParmBean" property="inputfieldA" value='<%= null ' />
Messy ... An alternative is to use JSTL's <c:set>:
<c:set target="${RequestParmBean}" property="inputfieldA" value="" />
Hans
-----Original Message----- From: Zerbe John W [mailto:[EMAIL PROTECTED] Sent: Thursday, June 12, 2003 4:48 PM To: [EMAIL PROTECTED] Subject: Re: JSP:Setproperty and empty strings
If I am reading the spec correctly, you can initialize all of your properties individually prior to setting them from the request params. I believe that the line you quoted from the spec only applies when setting properties from request params.
eg: <jsp:SetProperty name="RequestParmBean" property="inputfieldA" value=""/> <jsp:SetProperty name="RequestParmBean" property="inputfieldA" param="inputfieldA"/>
or, assuming an input form the "inputfieldA" and "inputfieldB": <jsp:SetProperty name="RequestParmBean" property="inputfieldA" value=""/> <jsp:SetProperty name="RequestParmBean" property="inputfieldB" value=""/> <jsp:SetProperty name="RequestParmBean" property="*"/>
-----Original Message----- From: Tim Davidson [mailto:[EMAIL PROTECTED] Sent: Thursday, June 12, 2003 9:30 AM To: [EMAIL PROTECTED] Subject: JSP:Setproperty and empty strings
Hi
Using <jsp:setProperty...> is is possbible to set empty strings? and if so how?
I realise the spec says: "If the parameter has an empty or null value, the corresponding Bean property is not set. "
but can anyone reccommend a fix?
thanks in advance.
========================= To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant archives, FAQs and Forums on JSPs can be found at:
http://java.sun.com/products/jsp http://archives.java.sun.com/jsp-interest.html http://forums.java.sun.com http://www.jspinsider.com
DISCLAIMER: The information contained in this e-mail may be confidential and is intended solely for the use of the named addressee. Access, copying or re-use of the e-mail or any information contained therein by any other person is not authorized. If you are not the intended recipient please notify us immediately by returning the e-mail to the originator.
DISCLAIMER: The information contained in this e-mail may be confidential and is intended solely for the use of the named addressee. Access, copying or re-use of the e-mail or any information contained therein by any other person is not authorized. If you are not the intended recipient please notify us immediately by returning the e-mail to the originator.
========================= To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant archives, FAQs and Forums on JSPs can be found at:
http://java.sun.com/products/jsp http://archives.java.sun.com/jsp-interest.html http://forums.java.sun.com http://www.jspinsider.com
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant archives, FAQs and Forums on JSPs can be found at:
http://java.sun.com/products/jsp http://archives.java.sun.com/jsp-interest.html http://forums.java.sun.com http://www.jspinsider.com
-- Hans Bergsten <[EMAIL PROTECTED]> Gefion Software <http://www.gefionsoftware.com/> Author of O'Reilly's "JavaServer Pages", covering JSP 1.2 and JSTL 1.0 Details at <http://TheJSPBook.com/>
=========================================================================== To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant archives, FAQs and Forums on JSPs can be found at:
http://java.sun.com/products/jsp http://archives.java.sun.com/jsp-interest.html http://forums.java.sun.com http://www.jspinsider.com
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant archives, FAQs and Forums on JSPs can be found at:
http://java.sun.com/products/jsp http://archives.java.sun.com/jsp-interest.html http://forums.java.sun.com http://www.jspinsider.com
-- Hans Bergsten <[EMAIL PROTECTED]> Gefion Software <http://www.gefionsoftware.com/> Author of O'Reilly's "JavaServer Pages", covering JSP 1.2 and JSTL 1.0 Details at <http://TheJSPBook.com/>
=========================================================================== To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant archives, FAQs and Forums on JSPs can be found at:
http://java.sun.com/products/jsp http://archives.java.sun.com/jsp-interest.html http://forums.java.sun.com http://www.jspinsider.com