Hi,

I used a while ago the same technique and it seems to be working fine.

Try using: <s:loadBundle>.

 

Guy.

 

From: Julien Martin [mailto:[EMAIL PROTECTED] 
Sent: Thursday, July 10, 2008 8:32 AM
To: MyFaces Discussion
Subject: PhaseListener: before or after which phase should I set the locale?

 

Hello,
I use restfaces an I have UrLs such as mydomain.com/fr/book/etc
where /fr/ is the desired locale. I have tried retrieving the locale string
from the URL and setting the locale from a PhaseListener before the
renderResponse phase but it does not work i.e. when I change the locale in
the address bar to /en/book/etc it will not change the locale. Any clue?
Thanks in advance,
JUlien.

Here is the phase listener:

code:

  _____  




public class DebugPhaseListener implements PhaseListener {






 


private static transient Logger log =
Logger.getLogger("com.jeanbaptistemartin.util");


 


public DebugPhaseListener() {


log.debug("DebugPhaseListener constructor");


}


 


public void afterPhase(PhaseEvent phaseEvent) {






log.debug("after---> " + phaseEvent.getPhaseId());


}


 


public void beforePhase(PhaseEvent phaseEvent) {


Locale locale =
extractLocale(FacesContext.getCurrentInstance().getExternalContext().getRequ
estServletPath());






FacesContext.getCurrentInstance().getViewRoot().setLocale(locale);


}


 


public PhaseId getPhaseId() {


return PhaseId.RENDER_RESPONSE;


}


 


private Locale extractLocale(String servletPath) {


String[] array = servletPath.split("/");






return new Locale(array[0]);


 


}


}


 
  _____  




Here is the managed bean (I actually use spring):

code:

  _____  








@Component("sculptureView")


@Scope("request")


public class SculptureView {


 


private Logger log = Logger.getLogger("com.jeanbaptistemartin.view");


private JbmService service;






private Sculpture sculpture;


 


public SculptureView() {


log.info("Sculpture()");


}


 


@Autowired


public SculptureView(JbmService service) {


log.info("Sculpture(JbmService service)");






this.service = service;


}


 


@Instance("#{sculptureView}")


@HttpAction(value = "sculptureAction", pattern = "{locale}/sculpture/{id}")


public String getBookById(@Param("id") int id, @Param("locale")String
locale) {






this.sculpture = service.findByID(id);


log.debug("Locale: "+ locale);


return "/sculpture.jsp";


}


 


public Sculpture getSculpture() {


return sculpture;


}


 


public void setSculpture(Sculpture sculpture) {






this.sculpture = sculpture;


}


 


}
  _____  




The problem I get is that the jsp page still display today's date in
french...
Julien. 

Reply via email to