You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Art Vandalay <av...@yahoo.com> on 2003/02/20 18:50:25 UTC

Is This A Bug?

The logic:present tag checks to see if a field in a
form is null.

However, when a form is created after an HTML form is
submitted, Struts will pass an empty String into the
setter method if the corresponding value on the page
is empty.

This seems inconsistent. It seems (to me, anyway) that
Struts should either:

1. check for null or empty string in
PresentTag.condition

- OR -

2. pass null into the setter methods

Here is my scenario:

I have a seach page. The user performs a search. If
the search is successful, then I fill in a Form with
values returned from the search. These values are, of
course, mapped to HTML elements on the page. I also
want to enable some buttons on the page in that case.
If the search was not successful, I want to disable
the buttons.

The way I sought to accomplish this was to use
logic:present to see if a certain field was filled in
on the form. 

My form has a validate method. In the case where the
user has not entered a search criteria (left the field
blank), I want to return an error message but keep the
buttons disabled.

The problem is that Struts is calling my setter
methods with empty Strings, then calls validate().
validate() returns errors and the JSP is
reconstructed.

However, since the field being evaluated in
logic:present is now an empty String (no longer a
null) the buttons enable when they shouldn't.

I guess I could reset the values in my form to null if
the validate fails, but that seems like it should be
unnecessary. Not to mention that it would be a lot of
work to go through all my forms as I'm sure this
problem will come up elsewhere in my application.

Has anyone else had problems because of the
"inconsistency" between logic:present and empty String
fields? If so, how did you solve it?

__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org