Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

unable to use more than 2 <bean:message. tags in jsp

 
kiran kumar Mateti
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Problem: Unable to use more than 2 <bean:message> tags in jsp's.

I am using struts 1.1 version. I deployed a ear file( in weblogic8.1) which contains a war file in it. And this war contains multiple strus-config.xmls.

They are well defined in web.xml
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/login_struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>config/abc</param-name>
<param-value>/WEB-INF/abc_struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>config/xyz</param-name>
<param-value>/WEB-INF/xyz_struts-config.xml</param-value>
</init-param>
...
</servlet>

Each struts-config.xml contain its own respected applicationResource.properties like login_struts-config.xml contain loginApplicationResources.properties.....

Using <bean:message> tag I want to achieve i18N-internalization.

Strangely

It is working fine for my login module(login_struts-config.xml,loginApplicationResource.properties). It successfully accepting more than 2 <bean:message> tags in my login.jsp, but when i am logged in and accessing other jsp's of other modules, only first <bean:messge key="abc" > is taking and for another <bean:message key="xyz" > tag it giving and exception in console saying the key 'xyz' is not found in application resources.

Every module has its own application resources and placed at WEB-INF/classes folder.

But when i used the key names from loginApplicationResources.properties in jsp's of other module's, it accepting more than 2 <bean:messages >, but it is not taking from other resources properties of respected modules.

I think each time its loading loginApplicatioResource.properties only.

I tried with struts 1.2.0, 1.3.10 jars also, and problem is not solved.

Please any body help in this regard.

Thnaks in Advance.

Regards,
Kiran Kumar.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64980
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to ask Struts questions in the Struts forum. I have moved this post there for you.
 
kiran kumar Mateti
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank Q Bear,

I am new to this forum.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd assume that the root-level config param is application-wide. The other config params are per-module.

Application-wide resources would be available across the entire application, which is why you can use those resources in other modules. Module-specific resources, however, would be available only in that specific module.

The problem description, "Problem: Unable to use more than 2 <bean:message> tags in jsp's" isn't really accurate or descriptive--you can use as many bean:message tags as you want. The *real* problem is that you're unable to access module-specific resources from other modules, correct?

Perhaps re-phrasing the problem description would help someone more familiar with modules; I never used them as they seemed far more trouble than they were worth.
 
KiranKumar Mateti
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Than Q David ,

Yes, You are correct, I am unable to access module-specific resources from respected modules . I will chnage the subject as per your suggestion.

Please provide me any information to resolvethe problem.

Regards,
Kiran
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Delcare all module specific properties file in the struts-config with different name and access with 'bundle' attribute. Though this is dumb solution.. but can workout if dint get any other ..
 
KiranKumar Mateti
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Balu,

can you give me some more specific information about how to use 'bundle' attribute. Is that attribute is there in struts 1.1 version?
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Yes its available in Struts 1.1. Simple search "Multiple resources file in Struts " will lead you to tutorials..

You are welcome.
 
KiranKumar Mateti
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Balu,

As per your suggestion, i implemented bundle attribute in my jsp's.

Problem:
in login_struts-config.xml i written like this.
<message-resources
parameter="LoginApplicationResources" key="loginResource" id="message-resources_1"/>
in my login.jsp
<bean:message key="login.test.text" bundle="loginResource"/>
and its working fine.

but

in xyz_struts-config.xml i written like
<message-resources
parameter="XYZApplicationResources" key="XYZResource" id="XYZ_message-resources_1"/>
in xyz.jsp
<bean:message key="xyz.loginId" bundle="XYZResource" />

But iam getting error like
javax.servlet.jsp.JspException: Cannot find message resources under key XYZResource

For login module it is working properly, but my xyz module its not working.

Any solution for this?
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi Kiran ,

I have given the solution to define all message resources in the same 'struts-config.xml" ? and use it as 'bundle" in different modules. dint work that way.
 
Lei Guoguo
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tracked the struts 1.2.9's source

you can see these class:
org.apache.struts.util.MessageResources
org.apache.struts.util.MessageResourcesFactory
org.apache.struts.util.PropertyMessageResources
org.apache.struts.util.PropertyMessageResourcesFactory

the breakpoint can set in org.apache.struts.action.ActionServlet's method "init"
in ActionServlet's method "init()", the primary code is
"initModuleMessageResources(moduleConfig);" about on line 348;

you can step into this method what name is "initModuleMessageResources(ModuleConfig config)"
see this method's last code:
getServletContext().setAttribute(
mrcs[i].getKey() + config.getPrefix(),
resources);

do you understand?

for example:
in web.xml


in struts-config.xml


in struts-config-one.xml


in struts-config-two.xml


we can use in jsp like this:


hope can help you!

I'm chinese, my english is so bad. could you hep me?
my e-mail is :lgg860911@yahoo.com.cn
 
KiranKumar Mateti
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Thank you for splendid responses/solutions.

I solved this problem by deploying the same ear in weblogic9.1. I didn't modified any code, and its working fine in weblogic 9.1 and websphere 6.1.

I tried defining multiple resources in struts-config.xml but , only the last resource loading in weblogic 8.1.

Even without key attribute , its working fine in weblogic 9.1 and websphere 6.1.

I guess is there any bug in loading multiple resource bundles inweblogic 8.1?

But Thank you once agin to you All!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic