[jboss-user] [JBoss Seam] - Re: Step-by-step localization guide

nhpvti do-not-reply at jboss.com
Fri Sep 15 04:14:51 EDT 2006


"nhpvti" wrote : 
  | I've tried custom navigation handler for adding language suffix at the end of an action,  for example: register_en, register_de
  | 

My custom view handler works seamless with JSF navigation and Seam pageflow and forces templates names in the form of name_loc.xhtml, for example register_en.xhtml, register_de.xhtml Etc.

Hope that this won't cause any complications in future versions of Faces or Seam.

Here the details:

1) In faces-config.xml (for example):

<application>
  |   <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
  |   <view-handler>com.mycompany.util.LocaleViewHandler</view-handler>
  |   <message-bundle>messages</message-bundle>
  | 		<locale-config>
  | 			<default-locale>en</default-locale>
  | 			<supported-locale>en</supported-locale>
  | 			<supported-locale>de</supported-locale>	
  | 			<supported-locale>ru</supported-locale>		
  | 		</locale-config>
  | </application>

2) Implement LocaleViewHandler class (some additional methods have to be implemented, but they should simply wrap the base class functionality)


import javax.faces.application.ViewHandler;
  | ...
  | public class LocaleViewHandler extends ViewHandler
  | {
  |     private ViewHandler         base;
  |     private static final String separator             = "_";
  |     private static final String actionExtension       = ".seam";
  | 
  |     public LocaleViewHandler(ViewHandler base)
  |     {
  |         super();
  |         this.base = base;
  |     }
  | 
  |     public String getActionURL(FacesContext context, String viewId)
  |     {
  |         StringBuilder newActionURL = null;
  |         String actionURL = this.base.getActionURL(context, viewId);
  |         StringBuilder localeSuffix = new StringBuilder(separator);
  |         localeSuffix.append(LocaleSelector.instance().getLocaleString());
  |         StringBuilder localizedEnd = new StringBuilder(localeSuffix);
  |         localizedEnd.append(actionExtension);
  |         int pointPosition = actionURL.indexOf(actionExtension);
  |         if (pointPosition != -1 && actionURL.indexOf(localizedEnd.toString()) == -1)
  |         {
  |             newActionURL = new StringBuilder(actionURL.substring(0, pointPosition));
  |             newActionURL.append(localizedEnd);
  |             return newActionURL.toString();
  |         } else
  |         {
  |             return actionURL;
  |         }
  |     }
  | ...
  | }

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3971869#3971869

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3971869



More information about the jboss-user mailing list