Results 1 to 9 of 9
  1. #1
    vector_ever is offline Senior Member
    Join Date
    Jul 2013
    Posts
    188
    Rep Power
    6

    Default JSF Internationalization (multi languages) with many pages

    Hello,

    I need to make my web pages displaying two languages (English and German).
    I prepared the properties files for both languages, and it works but still not perfect.
    I used this tutorial JSF 2 internationalization example and configure it to work with my pages

    Problems:
    1- I need to switch between the German and English via link or commandlink
    2- It works just in one page, which means if i change the default language (German) to English and redirect to another page i will return German language.
    How to make it works with all pages??

    thank you

  2. #2
    Join Date
    Apr 2014
    Location
    http://www.roytuts.com
    Posts
    51
    Rep Power
    0

    Default Re: JSF Internationalization (multi languages) with many pages

    you have got an example how to work with internationalization. Now you can hire people

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: JSF Internationalization (multi languages) with many pages

    The example is very poor IMO, it indeed changes the language of only the current view.

    This is a far better way:

    JSF locale is set per request,not for session - Stack Overflow
    Last edited by gimbal2; 06-23-2014 at 01:44 PM. Reason: English is difficult
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    vector_ever is offline Senior Member
    Join Date
    Jul 2013
    Posts
    188
    Rep Power
    6

    Default Re: JSF Internationalization (multi languages) with many pages

    Quote Originally Posted by gimbal2 View Post
    The example is very poor IMO, it indeed changes the language of only the current view.

    This is a far better way:

    JSF locale is set per request,not for session - Stack Overflow
    Thank you it is really more obvious and clear it without complication. Any way i found almost the same solution in the following link Java EE 6 – JSF 2.0 Internationalization with session scoped language switcher bean | Software Passion.

    I applied it and every thing is ok but... when i add the <f:view locale="#{localeBean.locale}"> tag in each jsf page i got internal error 500, without view tag it is working but it will be not good solution still missing linking the chosen language by navigation to another page, it will rest to the default.
    I don't know the solution of this error
    I get every time this error:
    XML Code:
    HTTP Status 500 - /anmelden.xhtml @8,49 locale="#{languageSwitcher.locale}" Cant instantiate class: de.unileipzig.wirote.control.LanguageSwitcher.
    
    
    type Exception report
    
    message /anmelden.xhtml @8,49 locale="#{languageSwitcher.locale}" Cant instantiate class: de.unileipzig.wirote.control.LanguageSwitcher.
    
    description The server encountered an internal error that prevented it from fulfilling this request.
    
    exception
    
    javax.servlet.ServletException: /anmelden.xhtml @8,49 locale="#{languageSwitcher.locale}" Cant instantiate class: de.unileipzig.wirote.control.LanguageSwitcher.
    	javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)
    	org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:70)
    	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    	org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:205)
    
    root cause
    
    javax.faces.view.facelets.TagAttributeException: /anmelden.xhtml @8,49 locale="#{languageSwitcher.locale}" Cant instantiate class: de.unileipzig.wirote.control.LanguageSwitcher.
    	com.sun.faces.facelets.tag.TagAttributeImpl.getObject(TagAttributeImpl.java:358)
    	com.sun.faces.facelets.tag.TagAttributeImpl.getObject(TagAttributeImpl.java:276)
    	com.sun.faces.facelets.tag.jsf.core.ViewHandler.apply(ViewHandler.java:211)
    	com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
    	com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:87)
    	com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:161)
    	com.sun.faces.application.view.ViewMetadataImpl.createMetadataView(ViewMetadataImpl.java:116)
    	com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:241)
    	com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    	com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:121)
    	com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    	javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
    	org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:70)
    	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    	org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:205)
    
    root cause
    
    com.sun.faces.mgbean.ManagedBeanCreationException: Cant instantiate class: de.unileipzig.wirote.control.LanguageSwitcher.
    	com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:191)
    	com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:100)
    	com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
    	com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
    	com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:257)
    	com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:117)
    	com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
    	com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
    	org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:71)
    	org.apache.el.parser.AstValue.getValue(AstValue.java:160)
    	org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
    	com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
    	com.sun.faces.facelets.tag.TagAttributeImpl.getObject(TagAttributeImpl.java:356)
    	com.sun.faces.facelets.tag.TagAttributeImpl.getObject(TagAttributeImpl.java:276)
    	com.sun.faces.facelets.tag.jsf.core.ViewHandler.apply(ViewHandler.java:211)
    	com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
    	com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:87)
    	com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:161)
    	com.sun.faces.application.view.ViewMetadataImpl.createMetadataView(ViewMetadataImpl.java:116)
    	com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:241)
    	com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    	com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:121)
    	com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    	javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
    	org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:70)
    	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    	org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:205)
    
    root cause
    
    java.lang.NullPointerException
    	de.unileipzig.wirote.control.LanguageSwitcher.<init>(LanguageSwitcher.java:24)
    	sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    	sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    	java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    	java.lang.Class.newInstance(Class.java:374)
    	com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:186)
    	com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:100)
    	com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
    	com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
    	com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:257)
    	com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:117)
    	com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
    	com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
    	org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:71)
    	org.apache.el.parser.AstValue.getValue(AstValue.java:160)
    	org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
    	com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
    	com.sun.faces.facelets.tag.TagAttributeImpl.getObject(TagAttributeImpl.java:356)
    	com.sun.faces.facelets.tag.TagAttributeImpl.getObject(TagAttributeImpl.java:276)
    	com.sun.faces.facelets.tag.jsf.core.ViewHandler.apply(ViewHandler.java:211)
    	com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
    	com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:87)
    	com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:161)
    	com.sun.faces.application.view.ViewMetadataImpl.createMetadataView(ViewMetadataImpl.java:116)
    	com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:241)
    	com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    	com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:121)
    	com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    	javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
    	org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:70)
    	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    	org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:205)

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: JSF Internationalization (multi languages) with many pages

    Well good luck solving your next problem in your own code which you of course do not post.

    de.unileipzig.wirote.control.LanguageSwitcher.<ini t>(LanguageSwitcher.java:24)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    vector_ever is offline Senior Member
    Join Date
    Jul 2013
    Posts
    188
    Rep Power
    6

    Default Re: JSF Internationalization (multi languages) with many pages

    I posted the code, but ome thing wrong...any way iam sorry

    Java Code:
    
    
    package de.unileipzig.wirote.control;
    
    import java.io.Serializable;
    import java.util.Locale;
    import javax.annotation.PostConstruct;
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.SessionScoped;
    import javax.faces.context.FacesContext;
    
    
    /**
     *Used for managing i18n in application for each user
     * @author ralmoued
     */
    
    @ManagedBean(name = "languageSwitcher")
    @SessionScoped
    public class LanguageSwitcher implements Serializable {
    
        private static final long serialVersionUID = 1L;
       
        private Locale locale;
        
        @PostConstruct
        public void init() {
            locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
        }
        
        public Locale getLocale() {
            return locale;
        }
    
        public String getLanguage() {
            return locale.getLanguage();
        }
    
        /**
         * Sets the current {@code Locale} for each user session
         *
         * @param languageCode - ISO-639 language code
         */
        public void changeLanguage(String language) {
            
            locale = new Locale(language);
            FacesContext.getCurrentInstance().getViewRoot().setLocale(locale);
            System.out.println("language is: " + locale);
        }
       
    }
    the error here :
    Java Code:
    public void init() {
            locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
        }
    Last edited by vector_ever; 06-23-2014 at 04:04 PM.

  7. #7
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: JSF Internationalization (multi languages) with many pages

    I have no idea what that means. But oh yeah, you were on my ignore list. Now I'll have to punish myself.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  8. #8
    vector_ever is offline Senior Member
    Join Date
    Jul 2013
    Posts
    188
    Rep Power
    6

    Default Re: JSF Internationalization (multi languages) with many pages

    Ok, any way thanks..

  9. #9
    vector_ever is offline Senior Member
    Join Date
    Jul 2013
    Posts
    188
    Rep Power
    6

    Default Re: JSF Internationalization (multi languages) with many pages

    Quote Originally Posted by lethuy1989love View Post
    chúc các bác mua may bán d?t ! ^-^
    What is this??!!!!

Similar Threads

  1. differentiate user pages and admin pages in struts
    By phaniyelugula in forum Struts
    Replies: 3
    Last Post: 10-19-2012, 05:51 PM
  2. Multi-Panel multi-class GUI communication
    By manji51 in forum AWT / Swing
    Replies: 4
    Last Post: 05-25-2011, 01:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •