--- "Yu, Yanhui" <[EMAIL PROTECTED]> wrote:
> This is posted a couple of times, hope someone can
> help me out:
> 
> 
> > What I need to do is this:  I would like to
> display an error message to
> the
> > user in a little more customized way, such as, if
> some special characters
> > are not allowed in a field, if they entered any of
> this special character
> > set, (say @#$), I would like to display that "@#$
> is not allowed in this
> > field".  

You can do things like this in the Struts Validator
framework.  It is in the nightly source in the
contrib/validator directories and posted at
http://home.earthlink.net/~dwinterfeldt.;

This is a partial code snippet that uses a regular
expression to check if any of these characters are in
the field you are checking.  The regular expresion and
the error message are created based on the 'chars'
constant.  The double quote is escaped because this
information is stored in xml.  The '^' means all the
following are not allowed in the regular expression
(mask variable).  The 'msg name="mask"' overrides the
default error message for the mask validator.  The
'arg0 name="mask"' takes precedence over the arg0
element without a name attribute for the mask
validator.  This is a bit to get into, but it will do
what you want.

partial snippet from xml configuration file:
<formset>
 <constant name="chars" value="&quot;@#$" />
      
 <form    name="nameForm">
   <field    property="firstName"
depends="required,mask">
      <msg name="mask" key="my.errors.invalid" />
      <arg0 key="nameForm.firstName.displayname"/>
      <arg0 name="mask" key="${chars}"/>
      <var>
            <var-name>mask</var-name>
            <var-value>[^${chars}]</var-value>
      </var>
   </field>    
 </form>
</formset>

ApplicationResources.properties:
my.errors.invalid={0} is not allowed in this field.


> Also I would like to change the fields
> where erroneous data exist
> > into red, possbly change the font of the erroneous
> data into a different
> > font color.  When the user correct the error,  I
> want the background of
> that
> > field to be original color and font back to
> original color too.  
You can use logic:messagesPresent in the Struts
nightly builds to control formatting.

<logic:messagesPresent>
   <bean:message key="errors.header"/>
   <ul>
   <html:messages id="error">
      <li><bean:write name="error"/></li>
   </html:messages>
   </ul><hr>
</logic:messagesPresent>

or to check if there is an error for a specific field:

<logic:messagesPresent property="lastName">
   <ul>
   <html:messages id="error">
      <li><bean:write name="error"/></li>
   </html:messages>
   </ul><hr>
</logic:messagesPresent>


> I would
> > also like to focus my cursor in the first
> erroneous field, if erroneous
> data
> > exists, I would like to select that erroneous
> data.   Can I do that?  
Javascript

David

> How
> do
> > I do that?  It seems like Javascript is not
> welcomed here, so I am looking
> > for a solution in Struts.  Hopefully there is a
> nice way to do this.
> > 
> > Really appreciate all your time and help,
> 
> Yanhui
> 
> 
> 
> --
> To unsubscribe, e-mail:  
> <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>
> 


__________________________________________________
Do You Yahoo!?
Yahoo! Greetings - Send FREE e-cards for every occasion!
http://greetings.yahoo.com

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to