You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.
| Online: | 10 Members of 4089 |
| Forum: Seam Users |
15. Feb 2008, 21:20 CET | Link |
Hi all,
I have a problem with my webapplication. I have a page where people can create some data with different types. When I use the ice:selectOneListbox to select a type I get a nullpointer. If I use a h:inputText instead to choose the id of the type it works fine.
My webcode (the h:inputText is outcommented):
<s:decorate id="typeDecorate" template="layout/edit.xhtml">
<ui:define name="label">Type:</ui:define>
<!-- <h:inputText id="typeId" required="true" converter="dataTypeConverter" value="#{data.type}"/> -->
<ice:selectOneListbox id="typedropdown" value="#{data.type}" size="1" converter="dataTypeConverter" rendered="#{not empty dataTypeList.resultList}">
<f:selectItems value="#{dataTypeHome.types}" />
</ice:selectOneListbox>
</s:decorate>
I have also tried to switch the f:selectItems with harcoded f:selectItem with values of 1, 2, 3... according to the id's of the types in the DB. The same problem here.
The dataconverter looks like this:
@Override
public Object getAsObject(FacesContext context, UIComponent ui, String s) {
DataTypeList datalist = new DataTypeList();
if (s != null) {
Integer id = Integer.parseInt(s);
List list = datalist.getResultList();
for (Object o : list) {
DataType dt = (DataType)o;
if (dt.getId().intValue() == id.intValue())
return dt;
}
}
return null;
}
@Override
public String getAsString(FacesContext context, UIComponent ui, Object o) {
if (o instanceof DataType) {
DataType dt = (DataType)o;
return String.valueOf(dt.getId());
}
return null;
}
Can anyone tell me what i'm doing wrong? :) If you need I can send you all the code, but I think the above is what you need?
Thanks and best regards Jacob
Stack trace?
Learn more about Web Beans...
22:48:37,092 ERROR [ExceptionFilter] exception root cause javax.faces.el.EvaluationException: javax.persistence.PersistenceException: org. hibernate.PropertyValueException: not-null property references a null or transie nt value: com.test.project.Data.type at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(Met hodBindingMethodExpressionAdapter.java:91) at com.sun.faces.application.ActionListenerImpl.processAction(ActionList enerImpl.java:91) at javax.faces.component.UICommand.broadcast(UICommand.java:383) at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:447) at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:7 52) at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicat ionPhase.java:97) at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117) at com.icesoft.faces.webapp.http.core.ReceiveSendUpdates.renderCycle(Rec eiveSendUpdates.java:57) at com.icesoft.faces.webapp.http.core.ReceiveSendUpdates.service(Receive SendUpdates.java:45) at com.icesoft.faces.webapp.http.core.IDVerifier.service(IDVerifier.java :25) at com.icesoft.faces.webapp.http.core.ViewBoundServer.service(ViewBoundS erver.java:52) at com.icesoft.faces.webapp.http.common.standard.PathDispatcherServer$Ma tcher.serviceOnMatch(PathDispatcherServer.java:50) at com.icesoft.faces.webapp.http.common.standard.PathDispatcherServer.se rvice(PathDispatcherServer.java:19) at com.icesoft.faces.webapp.http.servlet.ThreadBlockingAdaptingServlet.s ervice(ThreadBlockingAdaptingServlet.java:19) at com.icesoft.faces.webapp.http.servlet.EnvironmentAdaptingServlet.serv ice(EnvironmentAdaptingServlet.java:29) at com.icesoft.faces.webapp.http.servlet.MainSessionBoundServlet.service (MainSessionBoundServlet.java:109) at com.icesoft.faces.webapp.http.servlet.SessionDispatcher.service(Sessi onDispatcher.java:35) at com.icesoft.faces.webapp.http.servlet.PathDispatcher$Matcher.serviceO nMatch(PathDispatcher.java:52) at com.icesoft.faces.webapp.http.servlet.PathDispatcher.service(PathDisp atcher.java:29) at com.icesoft.faces.webapp.http.servlet.MainServlet.service(MainServlet .java:98) at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl icationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF ilterChain.java:206) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDisp atcher.java:654) at org.apache.catalina.core.ApplicationDispatcher.processRequest(Applica tionDispatcher.java:445) at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationD ispatcher.java:343) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDis patcher.java:292) at com.icesoft.faces.webapp.xmlhttp.BlockingServlet.service(BlockingServ let.java:54) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl icationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF ilterChain.java:206) at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter .java:83) 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.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.jav a:68) at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter .java:69) 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:45) at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter .java:69) at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl icationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF ilterChain.java:206) at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFi lter.java:96) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl icationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF ilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV alve.java:230) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV alve.java:175) at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(Securit yAssociationValve.java:179) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentica torBase.java:432) at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValv e.java:84) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j ava:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j ava:102) at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedC onnectionValve.java:157) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal ve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav a:262) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java :844) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce ss(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:44 6) at java.lang.Thread.run(Thread.java:619) Caused by: javax.persistence.PersistenceException: org.hibernate.PropertyValueEx ception: not-null property references a null or transient value: com.test.project.Data.type at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException (AbstractEntityManagerImpl.java:629) at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityMan agerImpl.java:218) at org.jboss.seam.persistence.EntityManagerProxy.persist(EntityManagerPr oxy.java:135) at org.jboss.seam.framework.EntityHome.persist(EntityHome.java:84) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces sorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.jboss.seam.util.Reflections.invoke(Reflections.java:21) at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocation Context.java:31) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocation Context.java:56) at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterc eptor.java:46) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocation Context.java:68) at org.jboss.seam.persistence.ManagedEntityIdentityInterceptor.aroundInv oke(ManagedEntityIdentityInterceptor.java:48) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocation Context.java:68) at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackI nterceptor.java:31) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocation Context.java:68) at org.jboss.seam.core.ConversationInterceptor.aroundInvoke(Conversation Interceptor.java:65) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocation Context.java:68) at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionI nterceptor.java:38) at org.jboss.seam.util.Work.workInTransaction(Work.java:40) at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(Transa ctionInterceptor.java:32) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocation Context.java:68) at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodConte xtInterceptor.java:42) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocation Context.java:68) at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java: 107) at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(Java BeanInterceptor.java:166) at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanIntercept or.java:102) at com.test.project.DataHome_$$_javassist_2.persist(DataHome_$$ _javassist_2.java) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces sorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:329 ) at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:342 ) at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:5 8) at org.jboss.el.parser.AstValue.invoke(AstValue.java:96) at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:27 6) at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.ja va:68) at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(Met hodBindingMethodExpressionAdapter.java:77) ... 61 more Caused by: org.hibernate.PropertyValueException: not-null property references a null or transient value: com.test.project.Data.type at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72 ) at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplic ate(AbstractSaveEventListener.java:290) at org.hibernate.event.def.AbstractSaveEventListener.performSave(Abstrac tSaveEventListener.java:181) at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId (AbstractSaveEventListener.java:107) at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient (DefaultPersistEventListener.java:131) at org.hibernate.event.def.DefaultPersistEventListener.onPersist(Default PersistEventListener.java:87) at org.hibernate.event.def.DefaultPersistEventListener.onPersist(Default PersistEventListener.java:38) at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:618) at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:592) at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:596) at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityMan agerImpl.java:212) ... 99 moreI have now tried to use h:selectOneMenu instead of icefaces. The code in the view is now:
<h:selectOneMenu id="typeId" required="true" converter="dataTypeConverter" value="#{data.type}"> <f:selectItems id="foo" value="#{dataTypeHome.types}" /> </h:selectOneMenu>Because its set to required true, I dont get any nullpointer on the server, but in the GUI I get the following:
Type:* [dropdownbox] value is required
Any idea why?
It looks like when I press the submit button in my view, that the state of my selectOneMenu is resetted. Is it because each selectItems need a unique id or am I missing something to keep the sate of the dropdown-box?
Have you tried a long-running conversation?
Could you please show the code for 'dataTypeHome.types'.
Hi Kenneth
I have not tried that yet, i'm just started using seam and jsf.
import java.util.ArrayList; import java.util.List; import javax.faces.model.SelectItem; import org.jboss.seam.ScopeType; import org.jboss.seam.annotations.Begin; import org.jboss.seam.annotations.Factory; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Out; import org.jboss.seam.annotations.Scope; import org.jboss.seam.annotations.web.RequestParameter; import org.jboss.seam.framework.EntityHome; @Name("dataTypeHome") public class DataTypeHome extends EntityHome<DataType> { @RequestParameter Integer dataTypeId; @Factory("dataType") public DataType initDataType() { return getInstance(); } private DataTypeList dataTypeList; private List<SelectItem> types; public DataTypeHome() { dataUpdated(); } @Override public Object getId() { if (dataTypeId==null) { return super.getId(); } else { return dataTypeId; } } @Override @Begin(join=true) public void create() { super.create(); } @Override public String persist() { dataUpdated(); return super.persist(); } @Override public String remove() { dataUpdated(); return super.remove(); } @Override public String update() { dataUpdated(); return super.update(); } @Out public List<SelectItem> getTypes() { if (types == null || types.size() < dataTypeList.getResultCount()) { types = new ArrayList<SelectItem>(); List list = dataTypeList.getResultList(); for (Object o : list) { DataType t = (DataType)o; types.add(new SelectItem(t.getId(), t.getName())); } } return types; } public void setTypes(List<SelectItem> types) { this.types = types; } private void dataUpdated() { dataTypeList = new DataTypeList(); } }BTW: Have you tried to debug the dataconverter? Are you sure it returns a not-null value?
If I use
<h:inputText id="typeId" required="true" converter="dataTypeConverter" value="#{data.type}"/>instead of the dropdown menu and type the number 1 for example, it works fine and the converter convert 1 to the DataType with id 1.
But I don't understand why its says that the type is undefined in the GUI, because I have selected a type in the Dropdown-menu.
Best regards /Jacob
@Override public String getAsString(FacesContext context, UIComponent ui, Object o) { if (o instanceof DataType) { DataType dt = (DataType)o; return String.valueOf(dt.getId()); } return null; }Are you sure 'o instanceof DataType' is a DataType and not a Long.
t.getId() is a Long or what?
Thanks Kenneth,
yes it was a Long :)
But I still get an error from the GUI's validation:
Type:* [Dropdown menu] value is not valid
Can you see other problems with the converter? I assume getAsObject works since its was used by h:inputText and that worked?
Best regards /Jacob
I really can't say why you're getting a validation error. But you have some kind of an invalid value in the selectOneMenu - looks like you have '*' as an invalid value in the selectOneMenu.
But again, it's hard to say why you get an error - try to debug javax.faces.component.UISelectOne.validateValue():
/** * <p>In addition to the standard validation behavior inherited from * {@link UIInput}, ensure that any specified value is equal to one of * the available options. Before comparing each option, coerce the * option value type to the type of this component's value following * the Expression Language coercion rules. If the specified value is * not equal to any of the options, enqueue an error message * and set the <code>valid</code> property to <code>false</code>.</p> * * @param context The {@link FacesContext} for the current request * * @param value The converted value to test for membership. * * @throws NullPointerException if <code>context</code> * is <code>null</code> */ protected void validateValue(FacesContext context, Object value) { // Skip validation if it is not necessary super.validateValue(context, value); if (!isValid() || (value == null)) { return; } // Ensure that the value matches one of the available options boolean found = matchValue(value, new SelectItemsIterator(this)); // Enqueue an error message if an invalid value was specified if (!found) { FacesMessage message = MessageFactory.getMessage(context, INVALID_MESSAGE_ID, MessageFactory.getLabel(context, this)); context.addMessage(getClientId(context), message); setValid(false); } }Okay I'll try to debug it.
Thanks for your time.
/Jacob