Internationalization


You've already seen how the error messages returned from a form validation can be internationalized. The same can be done with the contents of a JSP file.

The bean:message tag looks for a value in the specified message bundle (your friend ApplicationResources.properties by default) and sends it to the browser, and can even take up to five parameterized arguments. Listing 7.9 shows minibar.jsp rewritten to support international text.

Listing 7.9 minibar.jsp Rewritten
 <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%> <%@ taglib uri="/WEB-INF/struts-template.tld" prefix="tmp"%> <%@ taglib uri="/WEB-INF/stock.tld" prefix="stock"%> <logic:present name="validatedUser" scope="session"> <font size="-2"> <bean:message key="stocktrack.minibar.welcomeback"/> <bean:write name="validatedUser" property="userFirstName"/> <bean:write name="validatedUser" property="userLastName"/> </FONT><P/> <logic:notEmpty name="validatedUser" property="holdings" scope="session"> <font size="-2"><B><bean:message key="stocktrack.minibar.yourport"/></B></font> <TABLE WIDTH="100%"><TR><TH><font size="-2">      <bean:message key="stocktrack.minibar.symbol"/></font></TH> <TH align="right"><font size="-2">       <bean:message key="stocktrack.minibar.holdings"/></font></TH> <TH align="right"><font size="-2">       <bean:message key="stocktrack.minibar.latestquote"/></font></TH> <TH align="right"><font size="-2">       <bean:message key="stocktrack.minibar.currentvalue"/></font></TH></TR> <logic:iterate id="holding" name="validatedUser" property="holdings"> <TR><TD><font size="-2">        <bean:write name="holding" property="stock.stockSymbol"/></font></TD> <TD align="right"><font size="-2">        <bean:write name="holding" property="numShares"/></font></TD> <TD align="right"><font size="-2">        <stock:lastquote holding="holding"/></font></TD> <TD align="right"><font size="-2">        <stock:lastquote holding="holding" multiply="yes"/></font></TD></TR> </logic:iterate> </TABLE> <font size="-2"> <bean:message key="stocktrack.minibar.updatemessage"/> <html:link href="addTransaction.do"/><bean:message key="stocktrack.minibar.here"/> </html:link> </font> </logic:notEmpty> <logic:empty name="validatedUser" property="holdings" scope="session"> <font size="-2"> <bean:message key="stocktrack.minibar.updatemessage"/> <html:link href="addTransaction.do"/><bean:message key="stocktrack.minibar.here"/> </html:link> </font> </logic:empty> </logic:present> <logic:notPresent name="validatedUser" scope="session"> <table>   <html:form action="/login.do">   <tr>     <td colspan="2">       <h2><bean:message key="stocktrack.minibar.loginplease"/></h2>     </td>   </tr>   <tr><td colspan="2">      <html:errors property="org.apache.struts.action.GLOBAL_ERROR"/>   </td></tr>   <tr><TD COLSPAN="2"><html:errors property="username"/></TR>     <TR><td><FONT SIZE="-2">       <bean:message key="stocktrack.minibar.username"/></FONT>     </td><td><html:text property="username"/></td></tr>   <tr><td><html:errors property="password"/></td></tr>     <tr><td><FONT SIZE="-2">        <bean:message key="stocktrack.minibar.password"/></FONT>     </td><td><html:password property="password"/></td></td>   </tr>   <tr>     <td colspan="2"><html:submit property="ok"/></td>   </tr>   </html:form>   <tr><td colspan="2">   <FONT SIZE="-2">   <bean:message key="stocktrack.minibar.noaccount1"/>    <html:link href="/newaccount.do"/>       <bean:message key="stocktrack.minibar.here"/></html:link>   <bean:message key="stocktrack.minibar.noaccount2"/> </FONT></td></tr> </table> </logic:notPresent> <CENTER> <HR> <tmp:insert template="marketupdate.jsp"/> </CENTER> <HR> <bean:message key="stocktrack.minibar.techstocks"/>:<BR> <FONT SIZE="-2">IBM: <stock:lastquote symbol="IBM"/>                (<stock:dfc symbol="IBM"/>)<BR> MSFT: <stock:lastquote symbol="MSFT"/> (<stock:dfc symbol="MSFT"/>)<BR> </FONT> 

The additions to the resource bundle to support these new messages are

 stocktrack.minibar.welcomeback=Welcome back, stocktrack.minibar.yourport=Your Portfolio stocktrack.minibar.symbol=Symbol stocktrack.minibar.holdings=Holdings stocktrack.minibar.latestquote=Lastest Quote stocktrack.minibar.currentvalue=Current Value stocktrack.minibar.updatemessage=You can update your portfolio by clicking stocktrack.minibar.loginplease=Log In Please stocktrack.minibar.username=Username stocktrack.minibar.password=Password stocktrack.minibar.noaccount1=No account? Click stocktrack.minibar.here=here stocktrack.minibar.noaccount2=to create one. stocktrack.minibar.techstocks=Selected Technology Stocks 


Struts Kick Start
Struts Kick Start
ISBN: 0672324725
EAN: 2147483647
Year: 2002
Pages: 177

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net