Thanks.
Erik
Joe Germuska wrote:
At 5:10 PM -0500 11/8/04, Erik Weber wrote:
Here is a way to do it that works with 1.1:
<logic:messagesPresent name="org.apache.struts.action.ERROR"
property="username">
<bean:message key="error.username.required"/>
</logic:messagesPresent>
<p>Username: <html:text property="username"/></p>
Omitting the "name" attribute in this would have the same effect as
including it - it's the default. It's suggested that if you are
storing messages in your actions using "saveErrors" or "saveMessages"
(or dealing with validation errors, which are stored as if using
"saveErrors") then you shouldn't specify "name" literally; instead,
you can either rely on the default (to get errors) or use the
"message" attribute with a value of "true" (to get saveMessages
messages) or "false" (to get errors -- that is, the default
behavior). This helps to "encapsulate" the logic of how Struts
handles those messages, and makes your JSP a bit less verbose also.
Additionally, your code above assumes that the nature of the error
message is such that you know that the user should be shown the
"error.username.required" message -- it's probably more flexible to
let the validation/error handling framework create an ActionMessage
object with that key itself, and then you would use the messages
object; this way if any other error should come up (say you add a
max-length restriction, or forbidden characters), then you don't have
to change your JSP.
In another response I demonstrated how html:messages can be used to
achieve the same result you had above, plus this added flexibility I
mention.
Some people still like to use "html:errors", which predates
html:messages and which has a slightly different syntax for providing
any HTML which might "wrap" your messages. Personally, I prefer
html:messages.
None of this changed from Struts 1.1 to Struts 1.2.
Hope this helps,
Joe
Not sure if that tag has changed for 1.2.
Erik
Struts User wrote:
Hello,
Currently, I am using struts validator to validate the fields in my
ActionForm.
Before I updated to struts 1.2.4, I could add an error this way -
errors.add(
"username", new ActionError("error.username.required"));
If the validation failed, the error message for username will be
displayed right beside the user name text field if I use <P>Username:
<html:text property="username"/></P>.
Can someone tell me how to display error message beside an input field
using struts validator?
Thanks,
Lee
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]