[jboss-user] [JBoss Seam] - Re: selectItems - Is it possible?

Kragoth do-not-reply at jboss.com
Sun Oct 28 23:08:55 EDT 2007


Ok, I've tried using IGx89's converter but moving the store outside of the converter. And it *almost* works!

I'm running into a small problem though.

My code is as follows:

ObjectConverter.java 
  | package gekko.web.converter;
  | 
  | import static org.jboss.seam.ScopeType.CONVERSATION;
  | import gekko.util.StringUtils;
  | 
  | import javax.faces.component.UIComponent;
  | import javax.faces.context.FacesContext;
  | import javax.faces.convert.ConverterException;
  | 
  | import org.jboss.seam.Seam;
  | import org.jboss.seam.annotations.Create;
  | import org.jboss.seam.annotations.Install;
  | import org.jboss.seam.annotations.Name;
  | import org.jboss.seam.annotations.Scope;
  | import org.jboss.seam.annotations.faces.Converter;
  | import org.jboss.seam.annotations.intercept.BypassInterceptors;
  | 
  | @Name("GenericObjectConverter")
  | @Scope(CONVERSATION)
  | @Install(precedence = Install.APPLICATION)
  | @Converter
  | @BypassInterceptors
  | public class ObjectConverter implements javax.faces.convert.Converter {
  | 
  | 	private ObjectConverterStore objectStore;
  | 
  | 	@Create
  | 	public void create() {
  | 		objectStore = ObjectConverterStore.instance();
  | 	}
  | 
  | 	@Override
  | 	public Object getAsObject(FacesContext context, UIComponent component,
  | 			String value) throws ConverterException {
  | 		
  | 		if (value == null) {
  | 			return null;
  | 		}
  | 		return objectStore.get(value);
  | 	}
  | 
  | 	@Override
  | 	public String getAsString(FacesContext context, UIComponent component,
  | 			Object value) throws ConverterException {
  | 
  | 		if (value == null) {
  | 			return null;
  | 		}
  | 		
  | 		String key = objectStore.contains(value);
  | 		if (! StringUtils.isBlank(key)) { 
  | 			return key;
  | 		}
  | 		
  | 		if(context.getApplication().getStateManager().isSavingStateInClient(context)
  | 				&& Seam.isEntityClass(value.getClass()))
  | 			throw new ConverterException("ObjectConverter is unable to handle entity classes when client-side " +
  | 					"state saving is enabled. Please use EntityConverter instead, or enable server-side state saving");
  | 
  | 		return objectStore.put(value).toString();
  | 
  | 	}
  | 
  | }
  | 

ObjectConverterStore.java 
  | package gekko.web.converter;
  | 
  | import static org.jboss.seam.ScopeType.PAGE;
  | import static org.jboss.seam.annotations.Install.APPLICATION;
  | 
  | import java.rmi.server.UID;
  | import java.util.HashMap;
  | import java.util.Map;
  | 
  | import org.jboss.seam.Component;
  | import org.jboss.seam.annotations.Install;
  | import org.jboss.seam.annotations.Name;
  | import org.jboss.seam.annotations.Scope;
  | import org.jboss.seam.contexts.Contexts;
  | 
  | @Name("ObjectConverterStore")
  | @Install(precedence = APPLICATION)
  | @Scope(PAGE)
  | public class ObjectConverterStore {
  | 
  | 	private Map<String, Object> objects = new HashMap<String, Object>();
  | 
  | 	// Add an object to the store
  | 	public String put(Object entity) {
  | 		String key = new UID().toString();
  | 		objects.put(key, entity);
  | 		return key;
  | 	}
  | 
  | 	// Get an object from the store
  | 	public Object get(String key) {
  | 		return objects.get(key);
  | 	}
  | 	
  | 	// Check if store contains the object already.
  | 	public String contains(Object object) {
  | 		for (Map.Entry<String, Object> entry : objects.entrySet()) {
  | 			if (entry.getValue() == object) {
  | 				entry.getKey();
  | 			}
  | 		}
  | 		return null;
  | 	}
  | 
  | 	
  | 	public static ObjectConverterStore instance() {
  | 		if (!Contexts.isPageContextActive()) {
  | 			throw new IllegalArgumentException("Page scope not active");
  | 		}
  | 		return (ObjectConverterStore) Component
  | 				.getInstance(ObjectConverterStore.class);
  | 	}
  | }
  | 

And finally my faces-config.xml

  | <?xml version="1.0" encoding="UTF-8"?>
  | <faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
  | 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  | 	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
  | 
  | 	<!-- Facelets support -->
  | 	<application>
  | 		<variable-resolver>
  | 			org.springframework.web.jsf.DelegatingVariableResolver
  | 		</variable-resolver>
  | 		<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
  | 		<message-bundle>messages</message-bundle>
  | 	</application>
  | 
  | 	<!-- The gekko project's Date Converter -->
  | 	<converter>
  | 		<converter-id>gekkoDateConverter</converter-id>
  | 		<converter-class>
  | 			gekko.web.converter.DateConverter
  | 		</converter-class>
  | 	</converter>
  | 	
  | 	<!-- The gekko project's Persistent Entity Converter: Only to be used with the h:selectMenus -->
  | 	<converter>
  | 		<converter-id>SelectItemsPersistentEntityConverter</converter-id>
  | 		<converter-class>
  | 			gekko.web.converter.SelectItemsPersistentEntityConverter
  | 		</converter-class>
  | 	</converter>
  | 	
  | 	<!-- The generic object converter -->
  | 	<converter>
  | 		<converter-id>GenericObjectConverter</converter-id>
  | 		<converter-class>
  | 			gekko.web.converter.ObjectConverter
  | 		</converter-class>
  | 	</converter>
  | 	
  | 	<!-- This is the gekko:defaultAction tag to use for when a user presses the enter key to submit a form -->
  | 	<component>
  | 		<component-type>gekko.web.defaultAction</component-type>
  | 		<component-class>
  | 			gekko.web.components.UIDefaultAction
  | 		</component-class>
  | 	</component>
  | 
  | </faces-config>
  | 


OK, now for the problem.

The converter works fine when it comes to the getAsString method, everything does exactly what it should do.

But when I do the getAsObject my objectStore variable is null!????!!??

Can someone please tell me why?
I have tried to copy the entityManagerStore but I must be missing something!

I'll keep looking into it but... so far I've not made any progress, changing scopes does not help either.

Thanks for any input!

Just in case the stack trace is as follows:

  | WARNING: executePhase(PROCESS_VALIDATIONS 3,com.sun.faces.context.FacesContextImpl at 14563aa) threw exception
  | javax.faces.FacesException
  | 	at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:108)
  | 	at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
  | 	at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
  | 	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
  | 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
  | 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  | 	at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:307)
  | 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
  | 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  | 	at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
  | 	at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
  | 	at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
  | 	at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
  | 	at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
  | 	at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:44)
  | 	at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
  | 	at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
  | 	at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
  | 	at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
  | 	at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
  | 	at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
  | 	at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
  | 	at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:150)
  | 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
  | 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  | 	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
  | 	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
  | 	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
  | 	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
  | 	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
  | 	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
  | 	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
  | 	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
  | 	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
  | 	at java.lang.Thread.run(Thread.java:619)
  | Caused by: java.lang.NullPointerException
  | 	at gekko.web.converter.ObjectConverter.getAsObject(ObjectConverter.java:39)
  | 	at org.jboss.seam.ui.converter.PrioritizableConverter.getAsObject(PrioritizableConverter.java:61)
  | 	at org.jboss.seam.ui.converter.ConverterChain.getAsObject(ConverterChain.java:107)
  | 	at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:152)
  | 	at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectOneValue(MenuRenderer.java:197)
  | 	at com.sun.faces.renderkit.html_basic.MenuRenderer.getConvertedValue(MenuRenderer.java:359)
  | 	at javax.faces.component.UIInput.getConvertedValue(UIInput.java:934)
  | 	at javax.faces.component.UIInput.validate(UIInput.java:860)
  | 	at javax.faces.component.UIInput.executeValidate(UIInput.java:1065)
  | 	at javax.faces.component.UIInput.processValidators(UIInput.java:666)
  | 	at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1033)
  | 	at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1033)
  | 	at javax.faces.component.UIForm.processValidators(UIForm.java:229)
  | 	at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1033)
  | 	at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:662)
  | 	at org.ajax4jsf.component.AjaxViewRoot.access$201(AjaxViewRoot.java:57)
  | 	at org.ajax4jsf.component.AjaxViewRoot$3.invokeRoot(AjaxViewRoot.java:319)
  | 	at org.ajax4jsf.context.JsfOneOneInvoker.invokeOnRegionOrRoot(JsfOneOneInvoker.java:56)
  | 	at org.ajax4jsf.context.AjaxContextImpl.invokeOnRegionOrRoot(AjaxContextImpl.java:173)
  | 	at org.ajax4jsf.component.AjaxViewRoot.processValidators(AjaxViewRoot.java:333)
  | 	at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:100)
  | 	... 34 more
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4099715#4099715

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4099715



More information about the jboss-user mailing list