Hi Melinda,
ValidationErrors is simply
[1]HashMap<[2]String,[3]List<[4]ValidationError>> so you can
iterate through the keys and have the list of corresponding
ValidationError, each of which has a getFieldName() method.
For the duplication, I would remove mapError from your exception
classes. You are already adding the validation error to the list
in your catch block.
Cheers,
Freddy
On Tue, 22 Mar 2011 12:03 -0500, "Savoy, Melinda"
<melindasa...@texashealth.org> wrote:
One thing I forgot to explain is that I am trying to tie the
fieldName to the error that I am displaying so that the field
value is highlighted for the user. I cannot get at the fieldName
in the ValidationErrors. If there is a way to do that again, any
help is appreciated.
If there is a better way to do this, any help is appreciated.
Thanks.
From: Savoy, Melinda
Sent: Tuesday, March 22, 2011 10:33 AM
To: 'Ben Gunter'; 'Stripes Users List'
Subject: Re: [Stripes-users] Question on why stripes error is
displayed duplicated in JSP page
Thanks, Ben. I appreciate the quick response.
My SCMISActionBeanContext which extends the ActionBeanContext has
the addError(final String msg) method which is called from the
getContext().addError method below:
public void addError(final String msg) {
this.getValidationErrors().addGlobalError(new
SimpleError(msg, new Object[] {}));
}
>From the ValidationErrors class this is the method that I’m
calling:
public void addGlobalError(ValidationError error) {
add(GLOBAL_ERROR, error);
}
So it’s in the addError method above where it’s getting
duplicated?
From: Ben Gunter [mailto:gunter...@gmail.com]
Sent: Tuesday, March 22, 2011 10:20 AM
To: Stripes Users List
Cc: Savoy, Melinda
Subject: Re: [Stripes-users] Question on why stripes error is
displayed duplicated in JSP page
In your catch block, I see this:
validationExc.mapError(errors);
getContext().addError(validationExc.getMessage());
The definition for ValidationException#mapError(ValidationErrors)
shows that it adds the error to the ValidationErrors. I don't
know what YourActionBeanContext#addError(String) does, but based
on the name I would guess it also adds an error to the
ValidationErrors.
-Ben
On Tue, Mar 22, 2011 at 10:53 AM, Savoy, Melinda
<[5]melindasa...@texashealth.org> wrote:
In my validator class I am throwing a ValidationError here:
[code]
if (valueAdd.hasNEC(req.getNecCode())) {
throw new ValidationException("nonStockReq.necCode",
"necExclusion");
}
[/code]
In my AbstractRequisitionActionBean I am catching the error:
[code]
catch (ApplicationException e) {
ValidationException validationExc = (ValidationException)
e;
validationExc.mapError(errors);
getContext().addError(validationExc.getMessage());
log.warn("FAILED APPROVE VALIDATION - {P}",
e.getMessage());
}
[/code]
In my ValidationException:
[code]
public class ValidationException extends ApplicationException {
private static final long serialVersionUID =
8320536340453121195L;
private final String fieldName;
public ValidationException(final String fieldName, final
String message) {
super(message);
this.fieldName = fieldName;
}
public ValidationException(final String fieldName, final
String msgId, final Object... msgParams) {
super(msgId, msgParams);
this.fieldName = fieldName;
}
@Override
public void mapError(final ValidationErrors errors) {
errors.add(fieldName, new
SimpleError(getMessage()));
}
}
[/code]
And in the ApplicationException that is the superclass for
ValidationException:
[code]
public void mapError(final ValidationErrors errors) {
errors.addGlobalError(new SimpleError(getMessage()));
}
[/code]
I am not all sure WHY the error is being duplicated in my JSP
page. I’m sure it’s something stupid I’m doing I just can see
it. Any suggestions/direction would be appreciated.
Thanks.
Melinda Savoy
Sr. Programmer Analyst, ERP Systems
Innovative Technology Solutions
Texas Health Resources
600 E. Lamar Blvd, Ste 301, Arlington TX 76011
[6]melindasa...@texashealth.org
Texas Health Resources: Arlington Memorial,
Harris Methodist and Presbyterian Hospitals
A shared mission and now a shared name.
The information contained in this message and any attachments is
intended only for the use of the individual or entity to which it
is addressed, and may contain information that is PRIVILEGED,
CONFIDENTIAL, and exempt from disclosure under applicable law. If
you are not the intended recipient, you are prohibited from
copying, distributing, or using the information. Please contact
the sender immediately by return e-mail and delete the original
message from your system.
-----------------------------------------------------------------
-------------
Enable your software for Intel(R) Active Management Technology to
meet the
growing manageability and security demands of your customers.
Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your
software
be a part of the solution? Download the Intel(R) Manageability
Checker
today! [7]http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
Stripes-users mailing list
[8]Stripes-users@lists.sourceforge.net
[9]https://lists.sourceforge.net/lists/listinfo/stripes-users
The information contained in this message and any attachments is
intended only for the use of the individual or entity to which it
is addressed, and may contain information that is PRIVILEGED,
CONFIDENTIAL, and exempt from disclosure under applicable law. If
you are not the intended recipient, you are prohibited from
copying, distributing, or using the information. Please contact
the sender immediately by return e-mail and delete the original
message from your system.
The information contained in this message and any attachments
is intended only for the use of the individual or entity to
which it is addressed, and may contain information that is
PRIVILEGED, CONFIDENTIAL, and exempt from disclosure under
applicable law. If you are not the intended recipient, you are
prohibited from copying, distributing, or using the
information. Please contact the sender immediately by return
e-mail and delete the original message from your system.
--------------------------------------------------------------------------
----
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software
be a part of the solution? Download the Intel(R) Manageability Checker
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users
References
1. http://download.oracle.com/javase/1.5.0/docs/api/java/util/HashMap.html
2. http://download.oracle.com/javase/1.5.0/docs/api/java/lang/String.html
3. http://download.oracle.com/javase/1.5.0/docs/api/java/util/List.html
4.
http://stripes.sourceforge.net/docs/current/javadoc/net/sourceforge/stripes/validation/ValidationError.html
5. mailto:melindasa...@texashealth.org
6. mailto:melindasa...@texashealth.org
7. http://p.sf.net/sfu/intel-dev2devmar
8. mailto:Stripes-users@lists.sourceforge.net
9. https://lists.sourceforge.net/lists/listinfo/stripes-users
------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software
be a part of the solution? Download the Intel(R) Manageability Checker
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users