in my testapp the change already work...
problem are the function which where called like tree2 (get tree) or
datalist (get listelements)
i tried yours:
String message = messages.getMessage("some_key",
getFacesContext().getViewRoot().getLocale());
but this already throws exception - without locale it works
but only this worked at all:
treeData.getChildren().addAll(collection);
String locale =
getFacesContext().getViewRoot().getLocale().toString();
String actMessagesRessoucePath =
Properties.MessagesRessoucePath;
if (locale.equals("de") == false) {
actMessagesRessoucePath += "_" + locale;
}
Messages messagesRessouce = new
Messages(Properties.MessagesRessoucePath, this
.getClass().getClassLoader());
String message = messagesRessouce.getMessage("error.ejb");
getFacesContext().addMessage(null, new FacesMessage(message));
unfortunately i cant exclude it in a class...
when destroy method will be called? before oder after my datalist gets
infos from function...
2006/7/24, Gary VanMatre <[EMAIL PROTECTED]>:
>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