Note that there are some explanatory texts on larger screens.

plurals
  1. PO<h:selectOneMenu> NullPointerException getAsObject method
    primarykey
    data
    text
    <p>I'm using netbean 7.0.1, glassfish 3.1, primefaces 2.2.1. This is view </p> <pre><code> &lt;ui:define name="content"&gt; &lt;h:form enctype="multipart/form-data"&gt; &lt;p:wizard&gt; &lt;p:tab title="Tab 01"&gt; &lt;p:panel header="This is tab 01"&gt; &lt;h:messages errorStyle="color:red"/&gt; &lt;h:panelGrid&gt; &lt;h:selectOneMenu value="#{sellerController.currentCity}"&gt; &lt;f:selectItems value="#{cityController.listCity}" var="obj" itemLabel="#{obj.name}" itemValue="#{obj}"/&gt; &lt;/h:selectOneMenu&gt; &lt;/h:panelGrid&gt; &lt;/p:panel&gt; &lt;/p:tab&gt; &lt;p:tab title="Tab 02"&gt; &lt;p:panel header="This is tab 02"&gt; &lt;h:panelGrid&gt; &lt;p:commandButton value="Save" action="#{sellerController.addProperty()}"/&gt; &lt;/h:panelGrid&gt; &lt;/p:panel&gt; &lt;/p:tab&gt; &lt;/p:wizard&gt; &lt;/h:form&gt; &lt;/ui:define&gt; </code></pre> <p>also try with </p> <pre><code> &lt;h:selectOneMenu value="#{sellerController.currentCity}"&gt; &lt;f:selectItems value="#{cityController.itemsAvailableSelectOne}"/&gt; &lt;/h:selectOneMenu&gt; </code></pre> <p>When i click next button on tab 01 and save button on tab 02, sellerController.currentCity return null value. Save button still call : "addProperty()". I got this error </p> <pre><code> INFO: java.lang.NullPointerException java.lang.NullPointerException at my.controller.CityController$CityControllerConverter.getAsObject(CityController.java:67) at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:171) at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectOneValue(MenuRenderer.java:202) at com.sun.faces.renderkit.html_basic.MenuRenderer.getConvertedValue(MenuRenderer.java:319) at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030) at javax.faces.component.UIInput.validate(UIInput.java:960) at javax.faces.component.UIInput.executeValidate(UIInput.java:1233) at javax.faces.component.UIInput.processValidators(UIInput.java:698) at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214) at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214) at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214) at org.primefaces.component.wizard.Wizard.processValidators(Wizard.java:216) at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:508) at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1589) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600) at javax.faces.component.UIForm.visitTree(UIForm.java:344) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600) at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:376) at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:252) at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:183) at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1170) at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98) at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174) at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828) at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725) at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019) at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225) at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) at com.sun.grizzly.ContextTask.run(ContextTask.java:71) at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) at java.lang.Thread.run(Thread.java:662) </code></pre> <p>i have two controller, this is CityController :</p> <pre><code> @Named(value = "cityController") @SessionScoped public class CityController implements Serializable { @EJB CityModel cityModel; List&lt;City&gt; listCity; /** Creates a new instance of CityController */ public CityController() { } public List&lt;City&gt; getListCity(){ if (listCity==null) { listCity = new ArrayList&lt;City&gt;(); listCity = cityModel.findAll(); } return listCity; } public SelectItem[] getItemsAvailableSelectMany() { return JsfUtil.getSelectItems(cityModel.findAll(), false); } public SelectItem[] getItemsAvailableSelectOne() { return JsfUtil.getSelectItems(cityModel.findAll(), true); } @FacesConverter(forClass = City.class) public static class CityControllerConverter implements Converter { @Override public Object getAsObject(FacesContext facesContext, UIComponent component, String value) { if (value == null || value.length() == 0) { return ""; } CityController controller = (CityController) facesContext.getApplication().getELResolver(). getValue(facesContext.getELContext(), null, "customerController"); return controller.cityModel.find(getKey(value)); } java.lang.Integer getKey(String value) { java.lang.Integer key; key = Integer.valueOf(value); return key; } String getStringKey(java.lang.Integer value) { StringBuffer sb = new StringBuffer(); sb.append(value); return sb.toString(); } @Override public String getAsString(FacesContext facesContext, UIComponent component, Object object) { if (object == null) { return null; } if (object instanceof City) { City o = (City) object; return getStringKey(o.getId()); } else { throw new IllegalArgumentException("object " + object + " is of type " + object.getClass().getName() + "; expected type: " + CityController.class.getName()); } } } } </code></pre> <p>This is SellerController</p> <pre><code> @Named(value = "sellerController") @SessionScoped public class SellerController implements Serializable { @EJB CityModel cityModel; private City currentCity; /** Creates a new instance of SellerController */ public SellerController() { } public City getCurrentCity() { if (currentCity==null) { currentCity = new City(); } return currentCity; } public void setCurrentCity(City currentCity) { this.currentCity = currentCity; } public void addProperty(){ System.out.println("Call from Save button ?? "); } } </code></pre> <p>This is JsfUtil class</p> <pre><code> public class JsfUtil { public static SelectItem[] getSelectItems(List&lt;?&gt; entities, boolean selectOne) { int size = selectOne ? entities.size() + 1 : entities.size(); SelectItem[] items = new SelectItem[size]; int i = 0; if (selectOne) { items[0] = new SelectItem("", "---"); i++; } for (Object x : entities) { items[i++] = new SelectItem(x, x.toString()); } return items; } } </code></pre> <p>Because of CityController. when i use</p> <pre><code> import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; @ManagedBean(name = "cityController") @SessionScoped </code></pre> <p>It's work ! </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload