Hi Michael,
here below is the implementation of the custom tag we're using to
highlight a field in error:
HTH
Robert
-------------------------------------------------------------------
import java.util.Iterator;
import javax.servlet.jsp.JspException;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.Globals;
import org.apache.struts.util.RequestUtils;
public class TextTag extends org.apache.struts.taglib.html.TextTag {
/**
*
* Background color to use when error(s) are saved in the request.
*/
private String color = "#FF8000";
public String getColor(){
return color;
}
public void setColor(String aColor){
color = aColor;
}
/**
*
* style id to use when error(s) are saved in the request.
*/
private String errorStyleClass = null;
public String getErrorStyleClass(){
return errorStyleClass;
}
public void setErrorStyleClass(String aErrorStyleClass){
errorStyleClass = aErrorStyleClass;
}
// Tag interface
//-------------------------------------------------------------------------
public int doStartTag() throws JspException {
// Were any error messages specified?
ActionErrors errors = null;
try {
errors = RequestUtils.getActionErrors(pageContext,
Globals.ERROR_KEY);
} catch (JspException e) {
// ignores
}
if (errors != null && !errors.isEmpty()) {
Iterator iterator = null;
if (property == null)
iterator = errors.get();
else
iterator = errors.get(property);
if (iterator.hasNext()) {
if (errorStyleClass != null && errorStyleClass.length() > 0) {
setStyleClass(errorStyleClass);
}
else {
String style = getStyle();
if (style != null) {
style = style + "; background-color: " + color;
}
else {
style = "background-color: " + color;
}
setStyle(style);
}
}
}
return super.doStartTag();
}
//-------------------------------------------------------------------------
}
> -----Urspr�ngliche Nachricht-----
> Von: Michael Hanisch [mailto:[EMAIL PROTECTED]]
> Gesendet: Freitag, 14. Februar 2003 15:05
> An: Struts Users Mailing List
> Betreff: Re: Highlighting fields that failed in validation
>
>
> On Fri, 2003-02-14 at 13:37, O'Hara, Jean wrote:
> > Hi there
> >
> > A requirement for the application I'm working on is to
> highlight fields that
> > cause validation errors in red and also display an asterisk
> after the
> > offending field. This is as well as giving a list of the
> errors in a box to
> > the side. Listing the errors in the box is fine but does
> anyone know of a
> > good way of highlighting each field. I'm using the Struts Validator
> > framework and using the DynaValidatorForm. I think I might
> need to write
> > some custom tags but am not very familiar with custom JSP
> tags. Any advice
> > would be welcome!
> Umm... not sure what you mean by "highlight".
> What I usually do is to render every form widget in a table
> cell of its
> own; if there is an error for a widget, "highlight" this table cell in
> yellow (or whatever).
>
> You don't necessarily need a custom tag for that, though it would make
> things easier. Otherwise, just use one of the logic tags to
> check if an
> error for the widget is present (logic:present or something
> like that).
>
> HTH,
> Michael.
>
>
> --
> Michael Hanisch
> [EMAIL PROTECTED]
> Red Hat - RH Interchange Inc., Orleansstrasse 4, D-81669
> Munich/Germany
> phone: +49 (0)89 206058-53 fax: +49
> (0)89 206058-88
>
>
> ---------------------------------------------------------------------
> 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]