[JBoss Seam] - Enum Internationalised
by tony.herstell@gmail.com
This is probably obvious to all of you, but taken me days to get this working (and still not sure how!).
Inside an Entity I have an internationalised enum (as I am hoping to persist a value of its kind with the Entity):
| @SuppressWarnings("serial")
| @Entity // Defines this as an Entity that is a class mapped toDate the Datastore.
| @Name("booking") // Name used within SEAM for an instance of this class.
| public class Booking implements Serializable {
|
| public enum OrganisationKind {
| PRIVATE_BOOKING ("booking_private"),
| PRIVATE_BOOKING_OPEN ("booking_private_open"),
| NON_PROFIT_ORG ("booking_non_profit_org"),
| COMMERCIAL ("booking_commercial_org"),
| OPEN_EVENT ("booking_open_event"); // Only booked by Selwyn Equestrian Staff
| private final String inlLabel;
| OrganisationKind(String inlLabel) {
| this.inlLabel = inlLabel;
| }
| public String getInlLabel() { return inlLabel; }
| }
|
| ...
| private OrganisationKind organisationKind;
| ...
|
I have a controller that requires this enum to be displayed as selectOneRadio... these routines handle the selection:
| public Map getOrganisationKindList();
|
| public Booking.OrganisationKind getSelectedOrganisationKind();
|
| public void setSelectedOrganisationKind(Booking.OrganisationKind orgKind); not use I need this one as the Change fires ok
|
| public void selectedOrganisationKindChanged(ValueChangeEvent event);
|
The Impl:
| ...
| /**
| * The currently selected Booking Type
| */
| private Booking.OrganisationKind selectedOrganisationKind;
|
| ...
|
| public Map getOrganisationKindList() {
| Map<String,Booking.OrganisationKind> choices = new HashMap<String,Booking.OrganisationKind>();
| for (Booking.OrganisationKind type : Booking.OrganisationKind.values()) {
| choices.put(messages.get(type.getInlLabel()), type);
| }
| return choices;
| }
|
| public Booking.OrganisationKind getSelectedOrganisationKind() {
| return selectedOrganisationKind;
| }
|
| public void setSelectedOrganisationKind(Booking.OrganisationKind orgKind) {
| this.selectedOrganisationKind = orgKind;
| }
|
| public void selectedOrganisationKindChanged(ValueChangeEvent event) {
| if (event.getNewValue() != null) {
| Booking.OrganisationKind theOrganisationKind = Booking.OrganisationKind.valueOf(event.getNewValue().toString());
| selectedOrganisationKind = theOrganisationKind;
| } else {
| log.error("null new event passed in. Error!");
| }
| }
|
|
The screen shows all this using:
| <ice:panelGrid columns="1" styleClass="center">
| <ice:selectOneRadio
| value="#{availabilityController.selectedOrganisationKind}"
| valueChangeListener="#{availabilityController.selectedOrganisationKindChanged}"
| partialSubmit="true"
| layout="pageDirection"
| converter="#{enumTypeConverter}">
| <f:selectItems value="#{availabilityController.organisationKindList}"/>
| </ice:selectOneRadio>
| </ice:panelGrid>
|
Now... I have to provide a Converter (no idea if this is right.. and the screen seems to find this without outjecting it to the view at all!!):
| @Intercept(InterceptionType.NEVER)
| @SuppressWarnings("serial")
| @Stateless // A new component is created or re-initialised and re-used each time it is called.
| @Name("enumTypeConverter") // Name used within SEAM for an instance of this class.
| // All stateless session beans belong to the Stateless Context Scope
| public class EnumTypeConverterImpl implements EnumTypeConverter {
|
| @SuppressWarnings("unchecked")
| public Object getAsObject(FacesContext context, UIComponent comp, String value) throws ConverterException {
| Class enumType = comp.getValueBinding("value").getType(context);
| return Enum.valueOf(enumType, value);
| }
|
| public String getAsString(FacesContext context, UIComponent component, Object object) throws ConverterException {
| if (object == null) {
| return null;
| }
| Enum type = (Enum) object;
| return type.toString();
| }
|
| }
|
Anyhow, it may help some poor sap in the future!
FINALLY GOT TO USE INTERNATIONALISED ENUMS!!!
>From the screen:
| O open booking (Selwyn Equestrian Centre staff only)
| O commercial booking (e.g. NZ Elite Horse Auctions Ltd.)
| O private booking but open to anyone (cost is per horse - max of 4 places)
| O non profit booking (Dressage Canterbury etc.)
| O private booking (cost is for Arena) <<---Selected
|
|
| Result (on screen and in controller) = PRIVATE_BOOKING
|
:)
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4048838#4048838
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4048838
18 years, 11 months
[JBoss Seam] - Re: JBoss AS 4.2.0, seam 1.2.1 and seamgen
by ge0ffrey
Now I have this exception though:
| 11:59:03,359 INFO [TomcatDeployer] deploy, ctxPath=/bbaseamgen, warUrl=.../tmp/deploy/tmp19512bbaseamgen.ear-contents/bbaseamgen-exp.war/
| 11:59:03,593 INFO [ContextConfig] WARNING: Security role name NONE used in an <auth-constraint> without being defined in a <security-role>
| 11:59:03,875 ERROR [STDERR] java.lang.UnsupportedOperationException
| 11:59:03,875 ERROR [STDERR] at com.sun.faces.config.ConfigureListener$InitFacesContext.getViewRoot(ConfigureListener.java:1690)
| 11:59:03,875 ERROR [STDERR] at com.sun.faces.util.MessageFactory.getMessage(MessageFactory.java:113)
| 11:59:03,875 ERROR [STDERR] at com.sun.faces.util.MessageUtils.getExceptionMessageString(MessageUtils.java:277)
| 11:59:03,875 ERROR [STDERR] at com.sun.faces.util.Util.createInstance(Util.java:477)
| 11:59:03,875 ERROR [STDERR] at com.sun.faces.util.Util.createInstance(Util.java:436)
| 11:59:03,875 ERROR [STDERR] at com.sun.faces.config.ConfigureListener.configure(ConfigureListener.java:617)
| 11:59:03,875 ERROR [STDERR] at com.sun.faces.config.ConfigureListener.configure(ConfigureListener.java:503)
| 11:59:03,875 ERROR [STDERR] at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:402)
| 11:59:03,875 ERROR [STDERR] at org.jboss.web.jsf.integration.config.JBossJSFConfigureListener.contextInitialized(JBossJSFConfigureListener.java:69)
| 11:59:03,875 ERROR [STDERR] at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3854)
| 11:59:03,875 ERROR [STDERR] at org.apache.catalina.core.StandardContext.start(StandardContext.java:4359)
| 11:59:03,875 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:761)
| 11:59:03,875 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:741)
| 11:59:03,875 ERROR [STDERR] at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:553)
| 11:59:03,875 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| 11:59:03,875 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| 11:59:03,875 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| 11:59:03,875 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
| 11:59:03,875 ERROR [STDERR] at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:297)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
| 11:59:03,875 ERROR [STDERR] at org.apache.catalina.core.StandardContext.init(StandardContext.java:5310)
| 11:59:03,875 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| 11:59:03,875 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| 11:59:03,875 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| 11:59:03,875 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
| 11:59:03,875 ERROR [STDERR] at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:297)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
| 11:59:03,875 ERROR [STDERR] at org.jboss.web.tomcat.service.TomcatDeployer.performDeployInternal(TomcatDeployer.java:301)
| 11:59:03,875 ERROR [STDERR] at org.jboss.web.tomcat.service.TomcatDeployer.performDeploy(TomcatDeployer.java:104)
| 11:59:03,875 ERROR [STDERR] at org.jboss.web.AbstractWebDeployer.start(AbstractWebDeployer.java:375)
| 11:59:03,875 ERROR [STDERR] at org.jboss.web.WebModule.startModule(WebModule.java:83)
| 11:59:03,875 ERROR [STDERR] at org.jboss.web.WebModule.startService(WebModule.java:61)
| 11:59:03,875 ERROR [STDERR] at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
| 11:59:03,875 ERROR [STDERR] at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
| 11:59:03,875 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
| 11:59:03,875 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| 11:59:03,875 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
| 11:59:03,875 ERROR [STDERR] at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
| 11:59:03,875 ERROR [STDERR] at $Proxy0.start(Unknown Source)
| 11:59:03,875 ERROR [STDERR] at org.jboss.system.ServiceController.start(ServiceController.java:417)
| 11:59:03,875 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
| 11:59:03,875 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| 11:59:03,875 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
| 11:59:03,875 ERROR [STDERR] at $Proxy45.start(Unknown Source)
| 11:59:03,875 ERROR [STDERR] at org.jboss.web.AbstractWebContainer.start(AbstractWebContainer.java:466)
| 11:59:03,875 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| 11:59:03,875 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| 11:59:03,875 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| 11:59:03,875 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:97)
| 11:59:03,875 ERROR [STDERR] at org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServiceMBeanSupport.java:238)
| 11:59:03,875 ERROR [STDERR] at org.jboss.ws.integration.jboss42.DeployerInterceptor.start(DeployerInterceptor.java:93)
| 11:59:03,875 ERROR [STDERR] at org.jboss.deployment.SubDeployerInterceptorSupport$XMBeanInterceptor.start(SubDeployerInterceptorSupport.java:188)
| 11:59:03,875 ERROR [STDERR] at org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:95)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
| 11:59:03,875 ERROR [STDERR] at $Proxy46.start(Unknown Source)
| 11:59:03,875 ERROR [STDERR] at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
| 11:59:03,875 ERROR [STDERR] at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1015)
| 11:59:03,875 ERROR [STDERR] at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
| 11:59:03,875 ERROR [STDERR] at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
| 11:59:03,875 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor22.invoke(Unknown Source)
| 11:59:03,875 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| 11:59:03,875 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
| 11:59:03,875 ERROR [STDERR] at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
| 11:59:03,875 ERROR [STDERR] at $Proxy9.deploy(Unknown Source)
| 11:59:03,875 ERROR [STDERR] at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:421)
| 11:59:03,875 ERROR [STDERR] at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:634)
| 11:59:03,875 ERROR [STDERR] at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:263)
| 11:59:03,875 ERROR [STDERR] at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:274)
| 11:59:03,875 ERROR [STDERR] at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:225)
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4048834#4048834
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4048834
18 years, 11 months