>i wrote a class which should handle all exceptions and error message
>in form of FacesMessage:
>
>package de.fhb.ShaleTest.view;
>
>import javax.faces.application.FacesMessage;
>
>import org.apache.commons.logging.Log;
>import org.apache.commons.logging.LogFactory;
>import org.apache.shale.util.Messages;
>
>import de.fhb.ShaleTest.general.BaseViewController;
>import de.fhb.ShaleTest.general.Properties;
>
>public class MessageLang extends BaseViewController {
>
> private final Log log = LogFactory.getLog(this.getClass());
> 
> Messages messagesRessouce = null;

private static Messages messages =
      new Messages("org.apache.shale.resources.Bundle",
                   MyManagedBean.class.getClassLoader());


This constructor will use the default VM Locale but you can pass in a override.

For example:
String message = messages.getMessage("some_key", 
getFacesContext().getViewRoot().getLocale());


The java.util.ResourceBundle will figure out what properties file to load using
the base bundle name.

>
> public MessageLang() {
>
[snippet]

>
>it works with the login like in mailreader...
>
>problem if a have a myfaces component, which get its info from a
>function - i get nullpointer...
>
>how is this handles: if a swap from one page to another on which is
>something like the myfaces datatable...
>
>the table is defined like this
>
> <component jsfid="collage:dataTable" extends="t:dataTable">
>  <attributes>
>   ...
>   <set name="value" value="#{pagedSort.cars}" />
>....
>get its values from managed bean pagedSort and list cars...
>
>but how i can maybe create language defined error messages... other
>standard solutions available?
>
>i have the list working and can swap but without error messages -
>everything shit


:-) There are probably to many ways to handle this.  You can use the JSF
loadBundle component.  Clay also has a LoadBundle component that simulates
the JSF LoadBundle tag 
(http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/LoadBundle.java?view=markup)

The shale-clay-usecases show examples of how to use this.  

<span jsfid="loadBundle" basename="org.apache.shale.usecases.view.Bundle" 
var="messages" />
<title>#{messages['usecases.rolodex2']}</title>

Another option is to use the core shale LoadBundle that is a managed bean.  The 
shale-mailreader uses this method.  The bundle can be loaded as a managed bean. 
 The LoadBundle JSF Tag and Clay Component stores the bundle in session scope.  
The managed bean bundle allows you to load it once in application scope.

<managed-bean>
    <description>Localized resources for this application.</description>
    <managed-bean-name>messages</managed-bean-name>
    <managed-bean-class>
      org.apache.shale.util.LoadBundle
    </managed-bean-class>
    <managed-bean-scope>application</managed-bean-scope>
    <managed-property>
      <property-name>basename</property-name>
      <value>org.apache.shale.examples.mailreader.ApplicationResources</value>
    </managed-property>
</managed-bean>

Be sure to configure the locales in the faces-config.xml.  You need to specify 
the
default and the supported.

 <application>
    <locale-config>
      <default-locale>en</default-locale>
      <supported-locale>en</supported-locale>
      <supported-locale>fr</supported-locale>
      <supported-locale>de</supported-locale>
      <supported-locale>es</supported-locale>
    </locale-config>
  </application>


The shale-usecases example app has a good example that allows you to select a 
locale from a select list.  The content is changed depending on the selected 
locale.


Gary

Reply via email to