aspose file tools*
The moose likes Struts and the fly likes    ???en_US.xx.errors.yy??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "   ???en_US.xx.errors.yy???" Watch "   ???en_US.xx.errors.yy???" New topic
Author

???en_US.xx.errors.yy???

Gayatri Ganesh
Ranch Hand

Joined: Dec 23, 2003
Posts: 143
Hi Everyone,

I am trying to do validations using struts framework.
I have the validation.xml,validator-rules.xml in place.
Also I have the ApplicationResources.properties file in the/WEB-INF/classes folder.
I have configured the above in the struts-config.xml :

<message-resources null="false" parameter="/WEB-INF/classes/ApplicationResources.properties" >
</message-resources>

<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>


In ApplicationResources.properties I have :

errors.name.required=Name cannot be blank. Please enter a Name.

In validation.xml I have :


<form name="MyForm">
<field property="name"
depends="required">
<msg
name="required"
key="errors.name.required"/>
<arg0 key="errors.name.required"/>
</field>
</form>

My Form extends the org.apache.struts.validator.ValidatorForm.


public ActionErrors validate(ActionMapping mapping, HttpServletRequest request){
ActionErrors errors = super.validate(mapping, request);
return errors;
}


Alsoin the struts-config.xml
I have
validate="true" input=/WEB-INF/jsp/a.jsp"



When I submit my page I see
???en_US.errors.name.required???

I checked all the spellings. eveything seems correct.
Also the ActionErrors gets populated with the correct key ie errors.name.required, but its value is ???..errors.name.required???

Can anyone please tell me a solution for this .

Thanks,
Gayatri
Kinjal Sonpal
Ranch Hand

Joined: Jun 06, 2003
Posts: 96
Gayatri, I've seen this kind of error creeping up when the resources are not found. You can try two things and post back the results.

1) AFAIK, the name of the file should not contain the extension *.properties* in the struts-config.xml file, as given below.

2) Most app servers maintain application logs. Check your application startup logs. Those [INFO] messages will tell you which resources file is loaded.

Please post back your findings.

Thanks and regards,
Kinjal Sonpal
Gayatri Ganesh
Ranch Hand

Joined: Dec 23, 2003
Posts: 143
Thanks for replying Kinjal.

I removed the .properties extension from struts-config.xml.
Also checked the log. It says loading ApplicationResources.
But it does not work
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

parameter should be the package name,
com/mycompany/resources/ApplicationResources.properties should be
com.mycompany.resources.ApplicationResources
since yours is at top-level it should be:
<message-resources null="false" parameter="ApplicationResources" >
</message-resources>

arg0 is not necessary, as the args replace {0} {1} values in a message
<form name="MyForm">
<field property="name"
depends="required">
<msg
name="required"
key="errors.name.required"/>
<!-- No arg0 -->
</field>
</form>

Hope this helps!


A good workman is known by his tools.
Gayatri Ganesh
Ranch Hand

Joined: Dec 23, 2003
Posts: 143
Thanks Marc. It did work
But now i have a new problem.
After the form is redisplayed with the error messages,
the values which user had entered in those fields disappear.
There is no reset() in my form.
Can anyone tell me solution for this please.

Thanks,
Gayatri
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Glad it worked.

Your new problem is one I see asked around here a lot.
I rarely hear back from people with this question after offering suggestions of what might help, so it has not been much of a learning experience for me.

Anyway, some suggestions:
1) make sure you are using struts tags instead of basic html for the page components (like <html:text instead of <input type="text")

2) The reset method you say does not exist. It might be a good idea to have a reset method that does nothing, otherwise the ActionForm's parent's reset will be called - since I don't know what ActionForm you've extended it's hard to know what it is doing.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: ???en_US.xx.errors.yy???