Wenn Sie im Internet suchen, werden Sie diverse Lösungen zur Umschaltung der Anzeigesprache einer Web-Applikation (JSF) finden. Ich möchte die vielleicht kürzeste beitragen 😉
Wenn Sie die angebotenen Sprachen in ihrer Muttersprache aneigen, so ist keine Übersetung erforderlich. Die Sprachcodes übergeben Sie nun einfach als Parameter. In Ihrer JSF-Seite reicht dann dieser Code-Schnipsel (Ersetzen Sie den commandBotton bei Bedarf durch commandLink oder anderes):
<h:commandButton action="#{tool.changeLang('de')}" immediate="true" value="Deutsch"/> <h:commandButton action="#{tool.changeLang('en')}" immediate="true" value="English"/> <h:commandButton action="#{tool.changeLang('fr')}" immediate="true" value="Français"/>
Und in Tool.java benötigen Sie diese kurze Methode:
public String changeLang(String langCode) { FacesContext.getCurrentInstance().getViewRoot().setLocale(new Locale (langCode)); return null; }
Das war’s.
Do you want to support this blog? You may help to finance the needed hardware.
Want to read more about software development? Purchase one of my books:
Start application development with Java. Learn development foundation, quality control and more.
A Journey through Java EE Technologies whilst developing Web Applications with JavaServer Faces.
Java Lambdas and Parallel Streams
The compact starter: Foundation, supporting structures, parallel processing
No software development, just nature:
A photographic image book. Get it for free. Or pay whatever you like.
No Comments Yet