Recommended approach for multi language with ReWrite

Splash Forums Rewrite Users Recommended approach for multi language with ReWrite

This topic contains 2 replies, has 2 voices, and was last updated by  icordoba 1 year, 11 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #26317

    icordoba
    Participant

    Hi,
    I’d like to know which is the recommended approach for multi language in ReWrite. I’m migrating from PrettyFaces configuration and I cannot set the language in Faces session as I do in pretty faces:

    ConfigurationBuilder.begin().addRule(Join.path(“/”).to(“/index.xhtml”)).perform(Invoke.binding(El.retrievalMethod(“#{userSessionView.setLanguage(‘es’)}”)))

    (I also have the corresponding for english language):

    .addRule(Join.path(“/en”).to(“/index.xhtml”)).perform(Invoke.binding(El.retrievalMethod(“#{userSessionView.setLanguage(‘en’)}”)));

    This will return NPE in FacesContext.getCurrentInstance(). It does not seem to be available when retrieved from the HttpConfigurationProvider. It does if using the PrettyFaces configuration module but if I remove that and use the ConfigurationProvider, I’ll get the NPE in this setLanguage() method.

    setLanguage() just invokes:

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

    Am I missing something? Thanks.

    • This topic was modified 2 years, 1 month ago by  icordoba. Reason: Add information of the issue
    #26321

    Rewrite rules are evaluated before the JSF lifecycle starts. So if you want to call a method on a JSF bean, you have to defer the invocation using PhaseOperation. See the migration guide for details:

    http://ocpsoft.org/rewrite/docs/migration/prettyfaces3#_page_actions

    Regarding i18n and Rewrite: This depends on what you exactly want to achieve. I recommend to search the forums for this topic. There are quite some approaches for different usecases described in some posts.

    #26370

    icordoba
    Participant

    Note: I found the silly mistake in the wrong parenthesis placement. I leave the post in case someone else gets to the same error. Thanks.

    Hello,
    I’m trying to implement the example in the document you refer but I’m getting the following error:

    ConfigurationBuilder.begin().addRule(Join.path("/").to("/index.xhtml").perform(Invoke.binding(El.retrievalMethod("userSessionView.setLanguage('en')"))))
    

    The method perform(Rewrite, EvaluationContext) in the type Join is not applicable for the arguments (DefaultOperationBuilder)

    And if I do:

    ConfigurationBuilder.begin().addRule(Join.path("/").to("/index.xhtml").perform(PhaseOperation.enqueue(Invoke.binding(El.retrievalMethod("userSessionView.setLanguage('en')"))).after(PhaseId.RESTORE_VIEW)));

    I get:

    The method perform(Rewrite, EvaluationContext) in the type Join is not applicable for the arguments (capture#1-of ?)

    thanks for any directions,
    Ignacio

    • This reply was modified 1 year, 11 months ago by  icordoba.
    • This reply was modified 1 year, 11 months ago by  icordoba.
    • This reply was modified 1 year, 11 months ago by  icordoba.
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

Comments are closed.