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().getRequestServletPath());
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