JSTL Bean Session

I have a page that display data from my postgresql database in textboxes, that the user can modify. This page also do some user input validation, so if the user dont complete a required field, it goes to a retry page. I store these input fields in a javabean to redisplay in the retry page. The thing is if for example the email address is required, and I am on my retry page that display the data from my bean, and I remove the email address and submit the page again, it dont check if my email fields is empty, as it remember my value from the bean. This is not right. Its as if my bean dont store my fields if its empty. Here is a snippit of my jstl retry page and bean: What must i do for it to see that my field is empty and validate that, or store the empty value if its not required?

JSTL:

<jsp:useBean id="updateUser" class="fnb.esolutions.jsp.internal.mois.ValidateUpdateBean" scope="session"/>

<jsp:setProperty name="updateUser" property="*"/>

<c:set var="email" value='${updateUser.email}'/>

<jsp:expression>updateUser.getErrorMsg("email")</jsp:expression>

<input type="text" size="25" maxlength="35" name="email" value="${email}"/>

BEAN:

public class ValidateUpdateBean {

private String email;

if (email.equals("") || (email.indexOf('@') == -1)) {

errors.put("email","Please enter a valid email address.");

email="";

allOk=false;

}

else {

errors.put("email","");

}

public String getErrorMsg(String s) {

String errorMsg =(String)errors.get(s.trim());

return (errorMsg == null) ? "":errorMsg;

}

public ValidateUpdateBean() {

email="";

public String getEmail() {

return email;

}

public void setEmail(String eml) {

email=eml;

}

public void setErrors(String key, String msg) {

errors.put(key,msg);

}

[1954 byte] By [Reniera] at [2007-10-2 22:13:25]
# 1

something not right for your JSTL:

Should be:

<input type="text" size="25" maxlength="35" name="email" value="<c:out value='${email}'/>"/>

by Avatar Ng

[KLJUG]

Avatar_Nga at 2007-7-14 1:30:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

>This is not right. Its as if my bean dont store my fields if its empty.

Yup, you're absolutely correct.

It won't.

And this is one of the major things I don't like about the <jsp:setProperty> tag - it treats empty and null values as "don't set this property"

http://java.sun.com/products/jsp/syntax/1.2/syntaxref1216.html#8856

Because the ValidateUpdateBean you are using is in Session scope, it remembers the previous value.

Possible solutions:

- make the bean request scope rather than session - will work for a single page entry screen

- Use a different population method than the jsp:setProperty tag to populate the bean. The commons beanutils package provides a populate method that is a bit more intelligent, and treats null and empty string as two different values.

- "reset" your bean each time.

evnafetsa at 2007-7-14 1:30:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...