aspose file tools*
The moose likes Struts and the fly likes unable to use more than 2 <bean:message. tags in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "unable to use more than 2 <bean:message. tags in jsp" Watch "unable to use more than 2 <bean:message. tags in jsp" New topic
Author

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

kiran kumar Mateti
Greenhorn

Joined: Nov 11, 2005
Posts: 2

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

Joined: Jan 10, 2002
Posts: 61661
    
  67

Please be sure to ask Struts questions in the Struts forum. I have moved this post there for you.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
kiran kumar Mateti
Greenhorn

Joined: Nov 11, 2005
Posts: 2
Thank Q Bear,

I am new to this forum.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Mar 28, 2009
Posts: 7
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


Thanks & Regard,
Kiran Kumar Mateti.
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874



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

Joined: Mar 28, 2009
Posts: 7
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

Joined: Jan 01, 2009
Posts: 874



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

Joined: Mar 28, 2009
Posts: 7
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

Joined: Jan 01, 2009
Posts: 874


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

Joined: Mar 31, 2009
Posts: 26
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


I'm a chinese, my english is so bad, I need help. If you want to help me, you can send your question to my e-mail: lgg860911@yahoo.com.cn, I will help you, and improve my english. Thanks everyone.
KiranKumar Mateti
Greenhorn

Joined: Mar 28, 2009
Posts: 7
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!!!
 
wood burning stoves
 
subject: unable to use more than 2 <bean:message. tags in jsp