Comments(0) » | Add Comment » | Permalink » | Blog Home Page » Blog Post
Tags: java struts programming technical Passing Bean Message Arguments in Struts
I came across a situation with bean messages as I was working on internationalizing a Struts 1.3 application. I needed to get a value of off a properties key and pass it as an argument to another key.
Here's a sample properties file located in:
com/shahrier/akram/myapplication.properties page.name: Shahrier Akram
page.greetings: Hello {0}
Let's include this properties file into the struts configuration file, struts-config.xml, as a message resource:
<message-resources key="myapplication" parameter="com.shahrier.akram.myapplication" null="false"/>
Here's how I will pass the value of one key as an argument into another key in JSP:
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<bean:define id="myname">
<bean:message bundle="myapplication" key="page.name"/>
</bean:define>
<bean:message bundle="myapplication" key="page.greetings" arg0="<%=myname%>"/>
The following snippet above will produce
Hello Shahrier Akram!
Handy reference for the future.
Comments