|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectfc.web.simpleforms.Errors
public final class Errors
Convenience class to store arbitrary form validation errors and messages. This class should be instantiated per request as needed (when there are form validation errors).
Note: This class is not thread-safe but that's not a concern since only each seperate user request is handled by at most 1 thread.
Constructor Summary | |
---|---|
Errors()
|
Method Summary | |
---|---|
void |
addFieldError(java.lang.String fieldName,
java.lang.Object msg)
Adds a field validation error |
void |
addFieldWarning(java.lang.String fieldname,
java.lang.Object msg)
Adds an arbitrary warning message generated as part of form processing. |
void |
addFormError(java.lang.String msg)
Adds a form level error, typically associated with the form itself and/or multiple fields as a group. |
void |
addFormWarning(java.lang.String msg)
Adds an arbitrary warning message generated as part of form processing |
java.lang.Object |
getFieldError(java.lang.String fieldName)
Returns the field error for the specified fieldname or null if no error was found. |
java.lang.Object |
getFieldWarning(java.lang.String fieldname)
Returns the warning for the specified field or null if no warning exists. |
java.util.List |
getFormErrors()
Returns a list of all form errors or null if no errors are present. |
java.util.List |
getFormWarnings()
Returns the list of all form-level warnings or null if no warnings exist for the form. |
boolean |
hasError()
Returns true if there are any form or field errors. |
boolean |
hasWarning()
Returns true if there are any warnings. |
boolean |
hasWarning(java.lang.String fieldname)
Returns true if there are any warnings for the specified field |
static void |
main(java.lang.String[] args)
|
void |
render(java.io.Writer out,
java.lang.String fieldName)
Convenience method to render a field error. |
void |
render(java.io.Writer out,
java.lang.String fieldName,
java.lang.String inside,
java.lang.String outside)
Convenience method to render a field error. |
void |
renderFormErrors(java.io.Writer out)
Convenience method to render all the form errors (if present). |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Errors()
Method Detail |
---|
public void addFormError(java.lang.String msg)
public void addFieldError(java.lang.String fieldName, java.lang.Object msg)
fieldName
- the name of the fieldmsg
- some error object, typically a string but
can be a list of strings (for example) if
there is more than 1 validation error for
this fieldpublic void addFormWarning(java.lang.String msg)
public void addFieldWarning(java.lang.String fieldname, java.lang.Object msg)
public java.util.List getFormErrors()
public java.lang.Object getFieldError(java.lang.String fieldName)
public java.util.List getFormWarnings()
public java.lang.Object getFieldWarning(java.lang.String fieldname)
public boolean hasError()
public boolean hasWarning()
public boolean hasWarning(java.lang.String fieldname)
public void renderFormErrors(java.io.Writer out) throws java.io.IOException
String after = "<br>"; List list = error.getFormErrors(); if (list != null) { out.write("<div class='form-errmsg'>"); out.write("<ul>"); for (int n = 0; n < list.size(); n++) { out.write("<li>"); out.write(String.valueOf(list.get(n))); out.write("</li>"); } out.write("</ul>"); out.write("</div>\n"); }
java.io.IOException
public void render(java.io.Writer out, java.lang.String fieldName) throws java.io.IOException
The above is the same as:Object obj = error.getFieldError("some_field_name"); if (str != null) { out.write("<span class='field-errmsg'>"); out.write (String.valueOf(obj)); out.write("</span>\n"); out.write("<br>"); }
Note: The object representing the error for the field is written as is. Typically for strings, this works fine. However, for more complex objects (like say a list holding more than 1 error for the same field), the list is printed as-is. For more formatting options for complex objects, obtain and print the error manually.error.render(out, "some_field_name");
java.io.IOException
public void render(java.io.Writer out, java.lang.String fieldName, java.lang.String inside, java.lang.String outside) throws java.io.IOException
The above is the same as (for example):Object obj = error.getFieldError("some_field_name"); if (str != null) { out.write("<span class='field-errmsg'>"); out.write (String.valueOf(obj)); out.write("inside"); out.write("</span>\n"); out.write("outside"); }
Note: The object representing the error for the field is written as is. Typically for strings, this works fine. However, for more complex objects (like say a list holding more than 1 error for the same field), the list is printed as-is. For more formatting options for complex objects, obtain and print the error manually.error.render(out, "some_field_name", "inside", "outside");
inside
- this string is written before the span tag is closedoutside
- this string is written right after the span tag is closed.
java.io.IOException
public static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |