View Javadoc

1   package org.musicontroller.gui;
2   
3   import org.apache.tapestry.IMarkupWriter;
4   import org.apache.tapestry.IRequestCycle;
5   import org.apache.tapestry.form.IFormComponent;
6   import org.apache.tapestry.valid.IFieldTracking;
7   import org.apache.tapestry.valid.IValidator;
8   import org.apache.tapestry.valid.ValidationDelegate;
9   
10  /**
11   * Displays validation errors in the add user form.
12   * @author Hans Drexler
13   * @version $Id: NextToFieldErrorDisplayDelegate.java,v 1.1 2010/03/16 18:55:42 varienaja Exp $
14   */
15  public class NextToFieldErrorDisplayDelegate extends ValidationDelegate {
16  
17  	/**
18  	 * 
19  	 */
20  	private static final long serialVersionUID = 3795689193527576416L;
21  
22  	/**
23  	 * This method is overwritten so that the error message generated during 
24  	 * server-side validation actually appears next to the field in question.
25  	 *
26  	 * Don't be confused by the method names, there is a complimenting writeSuffix
27  	 * for fields, as well as a pair of writeLabelSuffix/writeLabelPrefix methods to
28  	 * do the same to labels.
29  	 * {@inheritDoc}
30  	 */
31  	 public void writePrefix(IMarkupWriter writer, IRequestCycle cycle, 
32  	         IFormComponent component, IValidator validator)
33  	 {
34  	     IFieldTracking ft = getCurrentFieldTracking();
35  	     
36  	     // There is a default error renderer for fields 
37  	     // which simply writes the message, which is what 
38  	     // we want to have happen in this case.
39  	     
40  	     if (ft != null && ft.getErrorRenderer() != null) 
41  	         ft.getErrorRenderer().render(writer, cycle);
42  	 }
43  	 
44  	 /**
45  	  * Adds a class style attribute to the label if in error
46  	  * {@inheritDoc}
47  	  */
48  	 public void writeLabelAttributes(IMarkupWriter writer, IRequestCycle cycle, 
49  	  IFormComponent component) 
50  	 {
51  	      if (isInError(component))
52  	      {
53  	         writer.attribute("class", "labelError");
54  	      }
55  	 }
56  	 
57  }