aspose file tools*
The moose likes Struts and the fly likes Error with validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Error with validation" Watch "Error with validation" New topic
Author

Error with validation

Nicola Guy
Ranch Hand

Joined: Jun 23, 2004
Posts: 91
Hi all

Ok I just implemented validation using the struts validator and all was going well, the errors were appearing. Until I changed something and then the following:

There was an unknown error performing the operation.

appeared where my error messages should be. It was working before so my question is does any one know of a small change I may have made that caused this?

Thanx for any help you can provide

Nicola
Nicola Guy
Ranch Hand

Joined: Jun 23, 2004
Posts: 91
Can anyone help
Nicola Guy
Ranch Hand

Joined: Jun 23, 2004
Posts: 91
Ok I figured out thtat the validator isn't running .

I have a validate method in my assetForm and put in test cases there that run but I declared the following:

ActionErrors errors = super.validate(mapping, request);

at the start of the method, does anyone know why this then wouldn't access the validation.xml???

plz help me

Thanx
J Haley
Ranch Hand

Joined: Jul 22, 2004
Posts: 66
Check to see what assetForm is extending. It needs to be ValidatorForm.
Nicola Guy
Ranch Hand

Joined: Jun 23, 2004
Posts: 91
Yes it is any other ideas
J Haley
Ranch Hand

Joined: Jul 22, 2004
Posts: 66
post you entire validate() method
Nicola Guy
Ranch Hand

Joined: Jun 23, 2004
Posts: 91
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
{
ActionErrors errors = super.validate(mapping, request);
if (errors == null)
errors = new ActionErrors();

/*ActionErrors errors = new ActionErrors();

if (id == null || id.equals(""))
{
errors.add("id", new ActionError("error.idblank"));

}

if (desc == null || desc.equals(""))
{
errors.add("desc", new ActionError("error.descriptionblank"));

}

if (startDate == null || startDate.equals(""))
{
errors.add("startDate", new ActionError("error.startdateblank"));

}*/

if (duration != null && duration.length() > 0)
{
try {
int i = Integer.parseInt(duration);
}
catch (NumberFormatException e){
errors.add("duration", new ActionError("error.durationnotint"));
}
}

if (this.ftv != null && this.ftv.length() > 0)
{
if (ftvGrade == null || ftvGrade.length() == 0)
errors.add("ftvGrade", new ActionError("error.ftvgraderequired"));
}

return errors;
}
}
J Haley
Ranch Hand

Joined: Jul 22, 2004
Posts: 66
What you posted looks good. I've got a couple of thoughts listed below.

o Have you added the validator plugin to struts-config.xml?

o Is validation turned on in struts-config.xml, if not are you calling manually

o If you put a breakpoint or System.out.println in you validate method do you ever hit it.

o create case that will fail validation and display errors right after ActionErrors errors = super.validate(mapping, request) does any thing show up.

o after making changes in struts-config.xml and validation.xml are you restarting your server.

o Is validation.xml built corretly. Does the form name align with assetForm?
Nicola Guy
Ranch Hand

Joined: Jun 23, 2004
Posts: 91
Yep I've done all that just not sure on this point.

I thought the super.validate started it manually??


o Is validation turned on in struts-config.xml, if not are you calling manually
J Haley
Ranch Hand

Joined: Jul 22, 2004
Posts: 66
By turned on in struts-config.xml I mean. Is the validate attribute tag set to "true".

<action name="assetForm" validate="true">

The super.validate will only be called if the validate() method that its in is called. This method can be run one of two ways. By setting you struts-config (see above) or you can run it as indicated below. This could occur from you execute() method.

errors = assetForm.validate(mapping, request);

I don't think I have any other ideas beyond this. Good Luck
Nicola Guy
Ranch Hand

Joined: Jun 23, 2004
Posts: 91
The validate method is called because other validation that is held in it is displayed.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error with validation