How to set a bean property to empty string using jsp/jstl?

I have a jsp that uses <jsp:setProperty name="beanname" property="*"/> to map submitted form values to a bean.  This is great unless a user wants to blank out a value (say, they put an address part in the wrong field and go back to correct.)  According to the documentation, jsp:setPropoerty will ignore any empty strings passed to it and leave the existing bean value.

So, I tried using JSTL tags like so:

<c:forEach var="parm" items="${param}">
  <c:set target="beanname" property="${parm.name}" value="${parm.value}"/>
</c:forEach>

However, this behaves exactly the same: values that have input in the form are set, but those that are empty retain their former values.  

Anyone know how I can set the values to empty strings once they've been set?  

Thanks,
David
mousseheadAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rrzCommented:
Your idea is good. It just needs two adjustments.  
1) put ${} around beanname
2) use parm.key instead of using  parm.name
<c:forEach var="parm" items="${param}">
                 <c:set target="${beanname}" property="${parm.key}" value="${parm.value}"/>
</c:forEach>
0
mousseheadAuthor Commented:
Sorry, that didn't work.  Seems like c:set just passes through to the jsp:setProperty method.  Any other ideas?
0
rrzCommented:
It works for my test case. Please  try the following.
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<jsp:useBean id="testBean" class="rrz.TestBean" scope="session"/>
<c:forEach var="entry" items="${param}">
                 <c:set target="${testBean}" property="${entry.key}" value="${entry.value}"/>
</c:forEach>
<html><body><form>
                  <input type="text" name="one"/>
                  <input type="text" name="two"/>
                  <input type="submit"/>
</form>
one = ${testBean.one}<br/>
two = ${testBean.two}
</body></html>
//////////////////////////////////////////////////////////
package rrz;
public   class TestBean{
   private String one = null;
   private String two = null;
   public void setOne(String one){this.one = one;}
   public void setTwo(String two){this.two = two;}
   public String getOne(){ return one;}
   public String getTwo(){ return two;}
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mousseheadAuthor Commented:
That did the trick, just not in JSTL 1.0, which I'm stuck with for the moment.  Thanks for your help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.