Yet another I18N approach

Splash Forums PrettyFaces Users Yet another I18N approach

This topic contains 19 replies, has 4 voices, and was last updated by  Lincoln Baxter III 2 years, 2 months ago.

Viewing 15 posts - 1 through 15 (of 20 total)
  • Author
    Posts
  • #19739

    Anonymous

    I’m trying to map localized URLs to JSF views like this

    /en/Search   <-->   /search.jsf with Locale.ENGLISH
    /de/Suche <--> /search.jsf with Locale.GERMAN

    such that <h:link> tags in my views get mapped automatically to the localized URLs without adding any additional parameters.

    I read all recent threads on similar topics and did not find any simple approach that really matched this requirement. I tried in vain to come up with a DSL-style solution, but here is a programmatic one that seems to work:

    public class MyConfigurationProvider extends HttpConfigurationProvider {
    @Inject
    private LocaleBean localeBean;
    @Override
    public Configuration getConfiguration(ServletContext context) {
    return ConfigurationBuilder
    .begin()
    .defineRule()
    .when(Direction.isInbound().and(Path.matches("/{lang}/{path}")))
    .perform(new HttpOperation() {
    @Override
    public void performHttp(HttpServletRewrite event, EvaluationContext context) {
    String lang = (String) Evaluation.property("lang").retrieve(event, context);
    String path = (String) Evaluation.property("path").retrieve(event, context);
    String view = getView(lang, path);
    localeBean.setLang(lang);
    Forward.to(view).perform(event, context);
    }
    })
    .defineRule()
    .when(Direction.isOutbound().and(Path.matches("/{view}.jsf")))
    .perform(new HttpOperation() {
    @Override
    public void performHttp(HttpServletRewrite event, EvaluationContext context) {
    String lang = localeBean.getLocale().getLanguage();
    String view = (String) Evaluation.property("view").retrieve(event, context);
    String path = getPath(lang, view);
    Substitute.with(path).perform(event, context);
    }
    });
    }
    }

    @Named
    @RequestScoped
    public class LocaleBean {
    private String lang;
    // getter and setter omitted
    public Locale getLocale() {
    Locale locale;
    FacesContext context = FacesContext.getCurrentInstance();
    if (lang != null) {
    locale = new Locale(lang);
    context.getViewRoot().setLocale(locale);
    }
    else {
    if (context == null) {
    locale = Locale.GERMAN;
    }
    else {
    locale = context.getViewRoot().getLocale();
    if (locale == null) {
    locale = Locale.GERMAN;
    }
    }
    }
    return locale;
    }
    }

    The getView() and getPath() methods read the view-to-path mappings from property files.

    Does this make sense? Is there a way to replace the perform() methods by equivalent Rewrite DSL? The Rewrite examples on this site are not very comprehensive, so it’s a bit difficult to find out how things are supposed to work by trial and error…

    Best regards,

    Harald

    #23472

    Hey Harald,

    that’s very impressive. It actually looks very similar to what I would have done for implementing such an requirement.

    We know that there is currently no enough documentation. But we will address this as soon as we got 2.0.0.Final out, which will hopefully be very soon.

    We already started some discussion regarding the I18N in our development meetings some months ago. Unfortunately we didn’t find a solution that would fit all the needs people may have. Therefore it is very interesting to see how you implemented it using the existing API.

    I think it is OK to use custom HttpOperations in such an special usecase. IMHO it is one of the strength of Rewrite that you can always implement custom conditions or operations for special requirements.

    One of our ideas was to support some kind of pseudo parameter that could be used in rules and would represent an internationalized text (something as “search” vs “suche”). The would allow something like /de/kategorie/13 and /en/category/13:

    .defineRule()
    .when(Path.matches(“/{lang}/{lang:category}/{param}/”)
    .where(“lang”).bindsTo(LocaleBinding.bundle(“languages_bundle”))
    .where(“param”).matches(“\d+”))

    But we didn’t follow this idea further as we were not sure if this is something people would like to have in the API. I think it’s interesting that you are using a property-based approach for this too.

    @lincoln: Any thoughts on this?

    #23473

    Anonymous

    Hi Christian,

    thanks for your feedback, I’m glad to hear I wasn’t totally off the mark :-)

    I rather like your idea with the pseudo-parameter, whatever the exact syntax might be, hopefully allowing for EL expressions.

    Actually, I was using properties files in this quick proof-of-concept only, in a production system, I would store the text resources in a database and use a MessageBean to look up a resource, e.g. #{msg.lookup(lang, key)}, which can be simplified to #{msg[key]} if the MessageBean implements the Map interface and injects the LocaleBean to obtain the required language code.

    So there’d have to be a way to set key in the EL expression from a path parameter defined in the Rewrite rule.

    Your example mainly addresses the inbound direction. Actually, I was struggling with the outbound direction most of the time.

    More precisely, I tried to use out-of-the-box Join rules with suitable conditions, but none of these attempts would work, apparently because Join rules are always birectional, whereas in my case

    /en/Search --> /search.jsf with Locale.ENGLISH

    /de/Suche --> /search.jsf with Locale.GERMAN

    the mapping is not invertible, at least not without the additional Locale context information.

    It seems a Join.path("/foo").to("/bar") rule always generates an unconditional outbound mapping of /bar to /foo, so in my scenario, the second rule would never catch, i.e. /search.jsf was always mapped to /en/Search in the outbound case.

    That’s why I ended up with separate rules per direction and programmatic login in perform() methods.

    It would be very helpful to have some kind of DSL shortcut for this scenario.

    Best regards,

    Harald

    #23474

    Hey Harald,

    This is Interesting… I need to think about this when it’s not 1:32 AM, but what you’ve done here is actually an excellent use-case. I think as Christian mentioned, one of our ideas was to use property files, similar to what you’ve done.

    I’d actually like to see your getPath() and getView() implementations, with samples of your property files, if that’s possible. It would be helpful to see the end-to-end picture, even though I pretty much get what is happening there.

    Due to the work in Rewrite 2 to centralize parameterization, I think it would actually be pretty doable to implement basic i18n support that should simplify what you’ve done (which is by no means complex if you ask me! I actually like your solution!)

    More soon,

    ~Lincoln

    #23475

    Anonymous

    Hi Lincoln,

    the property stuff is just what you’d expect:

    private static Map<String, Properties> langToViews = new HashMap<String, Properties>();
    private static Map<String, Properties> langToPaths = new HashMap<String, Properties>();
    private String getView(String lang, String path) {
    Properties viewMap = getViewMap(lang);
    String view = viewMap.getProperty(path);
    return String.format("/%s.jsf", view);
    }
    private Properties getViewMap(String lang) {
    Properties props = langToViews.get(lang);
    if (props == null) {
    props = new Properties();
    try {
    props.load(getClass().getResourceAsStream(String.format("PathToView_%s.properties", lang)));
    langToViews.put(lang, props);
    }
    catch (IOException e) {
    throw new RuntimeException(e);
    }
    }
    return props;
    }
    private String getPath(String lang, String view) {
    Properties pathMap = getPathMap(lang);
    String path = pathMap.getProperty(view);
    // NOTE: context path is prepended automatically
    return String.format("/%s/%s", lang, path);
    }
    private Properties getPathMap(String lang) {
    Properties props = langToPaths.get(lang);
    if (props == null) {
    props = new Properties();
    try {
    props.load(getClass().getResourceAsStream(String.format("ViewToPath_%s.properties", lang)));
    langToPaths.put(lang, props);
    }
    catch (IOException e) {
    throw new RuntimeException(e);
    }
    }
    return props;
    }

    And here are the property files:

    PathToView_de.properties:

    Suchen = search
    Aktualisieren = update

    PathToView_en.properties:

    Search = search
    Update = update

    ViewToPath_xx.properties are just the reversed maps (of course this is redundant and you’d better reverse the maps on the fly).

    Best regards,

    Harald

    #26169

    naska.om
    Participant

    When I used this approach view params didn’t work.

    #26170

    Check out the LocaleTransposition class –> org.ocpsoft.rewrite.transposition.LocaleTransposition –> https://github.com/ocpsoft/rewrite/blob/master/api-tests/src/test/java/org/ocpsoft/rewrite/transposition/LocaleTranspositionConfigurationProvider.java#L47

    #26173

    naska.om
    Participant

    Thanks @lincoln for the link and improvements to i18n in this amazing library. I tried it and ran into the following problems:
    I get NPE with join but not with path and forward.
    This is the exception:

    SEVERE:   Error Rendering View[/Home.xhtml]
    java.lang.NullPointerException
    	at java.util.concurrent.ConcurrentHashMap.hash(ConcurrentHashMap.java:333)
    	at java.util.concurrent.ConcurrentHashMap.containsKey(ConcurrentHashMap.java:1016)
    	at org.ocpsoft.rewrite.transposition.LocaleTransposition.translate(LocaleTransposition.java:82)
    	at org.ocpsoft.rewrite.transposition.LocaleTransposition.isSatisfiedBy(LocaleTransposition.java:184)
    	at org.ocpsoft.rewrite.transposition.LocaleTransposition.isSatisfiedBy(LocaleTransposition.java:47)
    	at org.ocpsoft.rewrite.param.DefaultParameterValueStore.submit(DefaultParameterValueStore.java:59)
    	at org.ocpsoft.rewrite.param.RegexParameterizedPatternParser.matches(RegexParameterizedPatternParser.java:145)
    	at org.ocpsoft.rewrite.servlet.config.Path.evaluateHttp(Path.java:124)
    	at org.ocpsoft.rewrite.servlet.config.HttpCondition.evaluate(HttpCondition.java:44)
    	at org.ocpsoft.rewrite.config.And.evaluate(And.java:77)
    	at org.ocpsoft.rewrite.servlet.config.rule.Join.evaluate(Join.java:222)
    	at org.ocpsoft.rewrite.config.And.evaluate(And.java:77)
    	at org.ocpsoft.rewrite.config.RuleBuilder.evaluate(RuleBuilder.java:129)
    	at org.ocpsoft.rewrite.config.And.evaluate(And.java:77)
    	at org.ocpsoft.rewrite.config.RuleBuilder.evaluate(RuleBuilder.java:129)
    	at org.ocpsoft.rewrite.servlet.impl.DefaultHttpRewriteProvider.rewriteHttp(DefaultHttpRewriteProvider.java:165)
    	at org.ocpsoft.rewrite.servlet.http.HttpRewriteProvider.rewrite(HttpRewriteProvider.java:43)
    	at org.ocpsoft.rewrite.servlet.impl.HttpRewriteWrappedResponse.rewrite(HttpRewriteWrappedResponse.java:432)
    	at org.ocpsoft.rewrite.servlet.impl.HttpRewriteWrappedResponse.encodeURL(HttpRewriteWrappedResponse.java:391)
    	at com.sun.faces.context.ExternalContextImpl.encodeActionURL(ExternalContextImpl.java:592)
    	at com.sun.faces.application.view.MultiViewHandler.getBookmarkableURL(MultiViewHandler.java:405)
    	at org.ocpsoft.rewrite.faces.RewriteViewHandler.getBookmarkableURL(RewriteViewHandler.java:164)
    	at javax.faces.application.ViewHandlerWrapper.getBookmarkableURL(ViewHandlerWrapper.java:272)
    	at org.jboss.weld.jsf.ConversationAwareViewHandler.getBookmarkableURL(ConversationAwareViewHandler.java:124)
    	at com.sun.faces.renderkit.html_basic.OutcomeTargetRenderer.getEncodedTargetURL(OutcomeTargetRenderer.java:194)
    	at com.sun.faces.renderkit.html_basic.OutcomeTargetLinkRenderer.renderAsActive(OutcomeTargetLinkRenderer.java:158)
    	at com.sun.faces.renderkit.html_basic.OutcomeTargetLinkRenderer.encodeBegin(OutcomeTargetLinkRenderer.java:96)
    	at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:869)
    	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1854)
    	at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
    	at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:894)
    	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
    	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
    	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
    	at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:443)
    	at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
    	at org.ocpsoft.rewrite.faces.RewriteViewHandler.renderView(RewriteViewHandler.java:186)
    	at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
    	at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
    	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    	at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
    	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
    	at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    	at org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:205)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    	at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:873)
    	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:739)
    	at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:575)
    	at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:546)
    	at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:428)
    	at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:378)
    	at org.ocpsoft.rewrite.servlet.impl.HttpRewriteResultHandler.handleResult(HttpRewriteResultHandler.java:41)
    	at org.ocpsoft.rewrite.servlet.RewriteFilter.rewrite(RewriteFilter.java:268)
    	at org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:188)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
    	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
    	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
    	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
    	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
    	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
    	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
    	at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
    	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
    	at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
    	at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
    	at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
    	at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
    	at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
    	at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
    	at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    	at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
    	at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
    	at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
    	at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
    	at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    	at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
    	at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
    	at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
    	at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
    	at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
    	at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
    	at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
    	at java.lang.Thread.run(Thread.java:744)
    
    WARNING:   Servlet.service() for servlet Faces Servlet threw exception
    java.lang.NullPointerException
    	at java.util.concurrent.ConcurrentHashMap.hash(ConcurrentHashMap.java:333)
    	at java.util.concurrent.ConcurrentHashMap.containsKey(ConcurrentHashMap.java:1016)
    	at org.ocpsoft.rewrite.transposition.LocaleTransposition.translate(LocaleTransposition.java:82)
    	at org.ocpsoft.rewrite.transposition.LocaleTransposition.isSatisfiedBy(LocaleTransposition.java:184)
    	at org.ocpsoft.rewrite.transposition.LocaleTransposition.isSatisfiedBy(LocaleTransposition.java:47)
    	at org.ocpsoft.rewrite.param.DefaultParameterValueStore.submit(DefaultParameterValueStore.java:59)
    	at org.ocpsoft.rewrite.param.RegexParameterizedPatternParser.matches(RegexParameterizedPatternParser.java:145)
    	at org.ocpsoft.rewrite.servlet.config.Path.evaluateHttp(Path.java:124)
    	at org.ocpsoft.rewrite.servlet.config.HttpCondition.evaluate(HttpCondition.java:44)
    	at org.ocpsoft.rewrite.config.And.evaluate(And.java:77)
    	at org.ocpsoft.rewrite.servlet.config.rule.Join.evaluate(Join.java:222)
    	at org.ocpsoft.rewrite.config.And.evaluate(And.java:77)
    	at org.ocpsoft.rewrite.config.RuleBuilder.evaluate(RuleBuilder.java:129)
    	at org.ocpsoft.rewrite.config.And.evaluate(And.java:77)
    	at org.ocpsoft.rewrite.config.RuleBuilder.evaluate(RuleBuilder.java:129)
    	at org.ocpsoft.rewrite.servlet.impl.DefaultHttpRewriteProvider.rewriteHttp(DefaultHttpRewriteProvider.java:165)
    	at org.ocpsoft.rewrite.servlet.http.HttpRewriteProvider.rewrite(HttpRewriteProvider.java:43)
    	at org.ocpsoft.rewrite.servlet.impl.HttpRewriteWrappedResponse.rewrite(HttpRewriteWrappedResponse.java:432)
    	at org.ocpsoft.rewrite.servlet.impl.HttpRewriteWrappedResponse.encodeURL(HttpRewriteWrappedResponse.java:391)
    	at com.sun.faces.context.ExternalContextImpl.encodeActionURL(ExternalContextImpl.java:592)
    	at com.sun.faces.application.view.MultiViewHandler.getBookmarkableURL(MultiViewHandler.java:405)
    	at org.ocpsoft.rewrite.faces.RewriteViewHandler.getBookmarkableURL(RewriteViewHandler.java:164)
    	at javax.faces.application.ViewHandlerWrapper.getBookmarkableURL(ViewHandlerWrapper.java:272)
    	at org.jboss.weld.jsf.ConversationAwareViewHandler.getBookmarkableURL(ConversationAwareViewHandler.java:124)
    	at com.sun.faces.renderkit.html_basic.OutcomeTargetRenderer.getEncodedTargetURL(OutcomeTargetRenderer.java:194)
    	at com.sun.faces.renderkit.html_basic.OutcomeTargetLinkRenderer.renderAsActive(OutcomeTargetLinkRenderer.java:158)
    	at com.sun.faces.renderkit.html_basic.OutcomeTargetLinkRenderer.encodeBegin(OutcomeTargetLinkRenderer.java:96)
    	at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:869)
    	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1854)
    	at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
    	at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:894)
    	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
    	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
    	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
    	at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:443)
    	at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
    	at org.ocpsoft.rewrite.faces.RewriteViewHandler.renderView(RewriteViewHandler.java:186)
    	at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
    	at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
    	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    	at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
    	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
    	at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    	at org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:205)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    	at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:873)
    	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:739)
    	at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:575)
    	at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:546)
    	at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:428)
    	at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:378)
    	at org.ocpsoft.rewrite.servlet.impl.HttpRewriteResultHandler.handleResult(HttpRewriteResultHandler.java:41)
    	at org.ocpsoft.rewrite.servlet.RewriteFilter.rewrite(RewriteFilter.java:268)
    	at org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:188)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
    	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
    	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
    	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
    	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
    	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
    	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
    	at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
    	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
    	at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
    	at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
    	at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
    	at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
    	at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
    	at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
    	at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    	at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
    	at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
    	at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
    	at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
    	at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    	at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
    	at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
    	at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
    	at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
    	at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
    	at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
    	at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
    	at java.lang.Thread.run(Thread.java:744)
    #26174

    Hmm, could you upload a sample maven app project that reproduces this?

    #26175

    naska.om
    Participant

    Unfortunately I cannot at the moment. But I’ve got four questions regarding the locale transposition’s function:
    1- With this method can I type into the address bar example.com/lang/path and get the path page in lang language?
    2- Does it work for h:link tags?
    3- When I change language using selectOneMenu value="localeBean.language", Does it redirect too to example.com/lang/path?
    4- What’s the difference between using Join.path and Path Forward?

    #26176

    naska.om
    Participant

    And I guess my fifth question is:
    5- How should LocaleBean look like and handle language for rewrite i18n to work? Anything special there?

    #26177

    Can you paste your configuration for the LocaleTransposition at least? 🙂

    1. Yes.
    2. It should, yes.
    3. No, you’d have to do that yourself.
    4. Forward is an operation that does an HTTP forward. Join is a rule that forwards inbound requests and also rewrites outbound URLs.
    5. Our i18n functionality does not depend on a bean. It only requires property files.

    #26178

    naska.om
    Participant

    Thanks for your answers @lincoln 🙂
    Here is my configuration file:

    public class TeshtRewriteConfigurationProvider extends HttpConfigurationProvider{                                 
        
        @Inject
        LocaleBean localeBean;   
        
        private Cookie getCookie(HttpServletRequest request, String name){
            if(request.getCookies() != null){
                for(Cookie cookie:request.getCookies()){
                    if(cookie.getName().equalsIgnoreCase(name)){
                        return cookie;
                    }
                }            
            }
            return null;
        }    
    
       @Override
       public Configuration getConfiguration(final ServletContext context)
       {              
         return ConfigurationBuilder.begin()                          
                 
                 
                .addRule()             
                .when(Path.matches("/"))
                 .perform(new HttpOperation(){
                    @Override
                    public void performHttp(HttpServletRewrite event, EvaluationContext context){
                        HttpServletRequest request =   (HttpServletRequest) event.getRequest();                      
                        if (request !=null){
                            Cookie langCookie = getCookie(request, "language");                        
                            if(langCookie != null){                                   
                                    Redirect.temporary(event.getContextPath() + "/"+ langCookie.getValue() + "/Home").perform(event, context);                             
                                }else{                                   
                                    Redirect.temporary(event.getContextPath() + "/Select_Language").perform(event, context);
                                }                    
                            }else{                                 
                                Redirect.temporary(event.getContextPath() + "/Select_Language").perform(event, context);
                        }
                    }
                 })
                 
                 .addRule(Join.path("/{lang}/{path}").to("/{path}.xhtml"))
                 .where("path").configuredBy(LocaleTransposition.bundle("com.tesht.bundles.text", "lang"))
    //             .where("lang").bindsTo(PhaseBinding.to(El.property(localeBean.getLanguage())))
                 
    
    //             .addRule()
    //             .when(Path.matches("/{lang}/{path}").withRequestBinding())
    //             .perform(Forward.to("/{path}.xhtml"))      
    //             .where("path").configuredBy(LocaleTransposition.bundle("com.tesht.bundles.text", "lang"))                            
                 
                 .addRule(Join.path("/Select_Language")
                 .to("/Select_Language.xhtml")
                 .withInboundCorrection())
                              
                 .addRule(Join.path("/Login")
                 .to("/Login.xhtml")
                 .withInboundCorrection())                                        
         
                 .addRule(Join.path("/admin/home")
                 .to("/admin/index.xhtml")
                 .withInboundCorrection());          
       }    
       @Override
       public int priority()
       {
         return 10;
       }
        
    }
    #26179

    naska.om
    Participant

    This is a sample NetBeans project. I used the same configuration, I got no NPE, but when I type into address bar lang/path/ I don’t get path page in lang language. I attached the war file.

    • This reply was modified 2 years, 2 months ago by  naska.om.
    Attachments:
    1. Testg.war
    #26182

    naska.om
    Participant

    It seems that when I use ui:composition in jsf pages it throws NPE.

    • This reply was modified 2 years, 2 months ago by  naska.om.
Viewing 15 posts - 1 through 15 (of 20 total)

You must be logged in to reply to this topic.

Comments are closed.