Back to life

Ok, I not only survived a horrible breakdown. I need to be a bit patient and hopefully I’ll be fully restored. Time to talk about life cycle. Lifecycle of JSF. Not a full-fledged article yet, but a tutorial to find out by yourself. Continue reading “Back to life”

JSF: Quick way to switch language

If you search the web, you’ll find a couple of solutions to change the language of your web application. I like to contribute an other one, which might be the shortest ūüėČ

Suppose, you want to display all supported languages in their native tongue.  Thus, you need no translation for the language names. The language codes are simply passed as parameter to your action.

Here is what you need in your JSF page (feel free to replace commandBotton by commandLink or something else):

<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"/>

And in Tool.java you need this short method:

public String changeLang(String langCode) {
    FacesContext.getCurrentInstance().getViewRoot().setLocale(new Locale (langCode));
    return null;
}

That’s all.

 

To web development content.

Tutorial web development (with JSF): Application “BookReview”, Part I

In my blog, I publish a list of those books, I wrote a review for. Every book will be displayed in a table with this information:

  • Title
  • Subtitle
  • Author(s)
  • Publisher
  • Year
  • Language
  • ISBN
  • Short text
  • Reference to my rewiew

These information is written manually and has to be maintained for every category and language. Changing the layout (if more than just CSS) will be a huge effort.

Now, I want to develop a multiligual application for publishing my booklist in an easy manner. One goal is to publish this information from a single soure in diverse categories and / or languages. Every book should be listet in the appropriate category just by assigning this category. The layout may change and should be maintained at a central place to be used for all books.
Continue reading “Tutorial web development (with JSF): Application “BookReview”, Part I”

GlassFish behind Apache HTTP Server

You may have developed a web application using JSF or other techniques, wich runs on an application server and should be reachable from the internet. You might configure your AppServer, e.g. GlassFish, listening on port 80 directly. Usually it is better to run this behind a HTTP server, which serves static content or provides load balancing. The folowing configuration is an example how to run GlassFish behind an Apach WebServer.

Its using this scenario:

  • The application runs on localhost:8080/myapp
  • The site is reachable on http://mydomain.net
  • The site is hosted on a virtual server
  • The complete site is forwared to the AppServer
  • The modules mod_proxy.so and mod_proxy_http.so are loaded
<VirtualHost *:80>
  ServerName mydomain.net
  ServerAlias www.mydomain.net

  ServerAdmin webmaster@mydomain.net
  DocumentRoot /var/htdocs/mydomain/

  <Directory /var/htdocs/mydomain/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
  </Directory>

  ProxyRequests Off

  <Proxy *>
    Order deny,allow
    Allow from all
  </Proxy>

  ProxyPass /myapp http://localhost:8080/myapp/
  ProxyPassReverse /myapp http://localhost:8080/myapp/

</VirtualHost>

Essential is the config of ProxyPass(Reverse), which forwards the directory (“/myapp”) to the adress of your AppServer (“http://localhost:8080/myapp/”). Please treat this only as an example. For security reasons you may run Apache within your dmz and GlassFish on a different machine behind your firewall.

Maybe I provide a full commented description later on in an future article of my JSF tutorial.

 

To web development content.

Tutorial web development (with JSF) VI: Templates

Templates

In the last part of this series, we created a second page, which looked similar to the first one. Now, we will put the common parts into a central place. To do this, we’ll create a template, which acts as kind of container for the shared part, which contains some individual information.

As a reminder, here is the souce of tese two pages:

Continue reading “Tutorial web development (with JSF) VI: Templates”