• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Gayatri Ganesh
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic