Friday, December 13, 2013

Multi-Lingual JSF

The default answer to having a multilingual page when developing an application is to develop two pages. This will usually add the complexity of managing the pages by resulting in the added effort of maintaining both pages/forms when having adding/amending a function. A simple solution to the problem is by considering the language to be as a separate function and manage it accordingly.

In-line with the function of multi-lingual, let us use the terminology of Function-Oriented application (as a sub-level of OO) where the function of presentation is isolated from the function of language and, as such, is isolated from the core function of the application. Within JSF, you can easily isolate the functionality of a multi lingual application. Let us start by a bundle two bundle files (This can be in a database if you prefer). Here I will use Arabic and English





Then Create a Managed Bean with the scope set as Session Scoped (This is to ensure you maintain the selected language)

public class UserSession implements Serializable{
      private String lang;   
     FacesContext ctx;     
     public void setAr(){   
        try {  
            ExternalContext ctx = FacesContext.getCurrentInstance().getExternalContext();  
        } catch (IOException ex) {  
            Logger.getLogger(UserSession.class.getName()).log(Level.SEVERE, null, ex);  
    public void setEn(){  
        try {  
            ExternalContext ctx = FacesContext.getCurrentInstance().getExternalContext();  
        } catch (IOException ex) {  
            Logger.getLogger(UserSession.class.getName()).log(Level.SEVERE, null, ex);  
    public String getLabel(String label){  
            return ResourceBundle.getBundle("/Bundle"+lang).getString(label);  
        } catch (Exception e){  
            return "No Label for " + label;  
    public String getLang() {  
        return lang;  
    public void setLang(String lang) {  
        this.lang = lang;  

Finally, your JSF page. Depending on the label you need to retrieve, you may use the expression language in the following form:
<h:form dir="#{userSession.getLabel('dir')}">  
    <p:commandLink value="English" action="#{userSession.setEn()}" />  
    <p:commandLink value="عربي" action="#{userSession.setAr()}"  />  
    <h:outputText value="#{userSession.getLabel('next')}"/>  
    <h:outputText value="#{userSession.getLabel('Previous')}"/>  

where dir while define the orientation of the page (left to right or right to left), next and previous will refer to the label title next and Previous respectively in the bundle bundle file based on the selected language. By implementing you code in the above manner, you open the opportunity to configure new languages as you feel free and it will require minimum maintenance from a technical perspective.

Friday, May 3, 2013

Education of Trust in Saudi

Before acknowledging or denying the story, let me tell it to the end.  This is a story of how trust is educated in Saudi.  And although it may sound extreme, I myself would not have believed it if it was not for experiencing it first-hand.  Although the tale might be old, this is the case till today, and it pains me to realize that a country that claims to rule by the Islamic doctrine had failed to create a culture based on common trust between the individuals of its own public and, worse still, between the common public and the governmental.

Our story begins with the academic year of 95/96.  By "chance" our Religious Studies teacher was a fundamental Saudi traditionalist during that year, the same year in which around 75% of students in our school where failed in Religious Studies of which I escaped and my brother fell victim to.  Naturally Students and parents all complained due to the injustice that befell the students.  However, the school's headmaster refused to take a stance.  When we started to request our papers, all requests were rejected and at the start of the new academic year our papers were burnt for all to see in the school's playground.  This situation re-occurred the following year (my final year in intermediate school) in which (thankfully) both my brother and myself escaped failure.  Sadly the Ministry of Education and the school never issued any investigation into the issue.

Think of the implication the above story would have on a student as he is coming of age.  How can he grow to trust anyone?  Better yet, whether it is by chance or not, this happens to many in Saudi (maybe not to the extreme of burning the papers) especially those finalizing their education in institutes of higher education.  Students are failed due to a grudge by the educator, and the educator is rewarded while the student in question is penalized when attempting to expose the corrupt educator.  As such, students graduating into Saudi's growing job market (and new adults into the Saudi Community) are taught not in the best methods of being devious.  They are raised to lie and cheat.  Further yet, they are lectured on truth and honesty and trained on deceit and dishonesty.  Let me take this one step further.  If such tales happen in governmental educational facilities in Saudi, how do we expect to have a generation that truly trust the government official publication or, potentially, any governmental reports and claims?

So how do we fix the issue?  It all starts with the up-bringing.  Students need to be treated with trust (i.e. trust should be practiced not spoken about).  Once we have a good platform to start from, we start punishing the deceitful (regardless of rank).  So a teacher intentionally failing his students, should be punished accordingly.   This will give raise to a culture that believes and understands that lying and cheating is frowned upon by a system that is trying to build trust between its players.

It is not all lost on Saudi culture.  There is still hope to create a community based on trust and loyalty.  A culture that functions correctly and, in accordance, functions on the basis of Islamic values.  But we do need to action this now.  It is time to acknowledge that we. as a Saudi Muslim public, are flawed, that our social values need visiting and that we can potentially progress.  We need to step out of this persona that we have our unique situation (different from any other community) and are perfect in every way.  Once we step away from such arrogance and into a more modest lifestyle and by realistic with ourselves, we will have a chance to truly prevail.