'Adding a value to an empty dataTable results in javax.el.PropertyNotFoundException

I got a dataTable and I am trying to add entries to the backing ArrayList of the given table. SelectedStep is null after the component is loaded. All Getters and Setters are provided. Code below:

<p:dataTable 
    id="selectedStepsTable" 
    var="step" 
    value="#{cc.attrs.compBean.componentData[cc.clientId].selectedElement.getData().getSteps()}" 
    selectionMode="single" 
    selection="#{cc.attrs.compBean.componentData[cc.clientId].selectedStep}"
    rowKey="#{step.name}" 
    editable="true" >
      <p:column headerText="Step">
        <p:cellEditor>
            <f:facet name="output"><h:outputText value="#{step.name}" /></f:facet>
          <f:facet name="input"><p:inputText id="stepnameinput" value="#{step.name}" style="width:100%"/></f:facet>
        </p:cellEditor>
      </p:column>
      <p:column headerText="Einheit">
        <p:cellEditor>
            <f:facet name="output"><h:outputText value="#{step.unit.name}" /></f:facet>
          <f:facet name="input">
            <p:autoComplete 
                dropdown="true" 
                value="#{step.unit}" 
                var="stepunit"
                itemLabel="#{stepunit.name}"
                itemValue="#{stepunit}"
                completeMethod="#{cc.attrs.compBean.componentData[cc.clientId].completeUnitName}"
                converter="unitConverter"
                forceSelection="false" />
                            </f:facet>
        </p:cellEditor>
      </p:column>
      <p:column style="width:64px;">
          <f:facet name="header">
            <p:commandLink 
                id="addStepLink" 
                styleClass="ui-icon ui-icon-plus"
                style="display: inline-block" 
                action="#{cc.attrs.compBean.componentData[cc.clientId].addStep}" 
                update=":#{p:component('schrittfrm')}" />
      <p:rowEditor />
      </p:column>
      <p:ajax event="rowSelect" update=":#{p:component('unitdetailgrid')} :#{p:component('stepParamTable')} :#{p:component('unitParamTable')}" />
          <p:ajax event="rowEdit" update=":#{p:component('unitdetailgrid')}" />    
</p:dataTable>

If a step is selected Details about it's unit are shown in the HTML below:

<h:panelGrid id="unitdetailgrid" columns="2" columnClasses="column" cellpadding="5">
    <h:outputLabel for="unitNameInput" value="Name:" />
    <p:inplace id="unitNameInput" effect="none" editor="true">
      <f:facet name="output">
        <h:outputText value="#{empty cc.attrs.compBean.componentData[cc.clientId].selectedStep.unit.name ? 'Einheitsname' : cc.attrs.compBean.componentData[cc.clientId].selectedStep.unit.name}" />
      </f:facet>
      <f:facet name="input">
        <p:autoComplete 
          dropdown="true" 
          value="#{cc.attrs.compBean.componentData[cc.clientId].selectedStep.unit}" 
          var="unitvar"
          itemLabel="#{unitvar.name}"
          itemValue="#{unitvar}"
          completeMethod="#{cc.attrs.compBean.componentData[cc.clientId].completeUnitName}"
          converter="unitConverter"
          forceSelection="false" />
       </f:facet>
    </p:inplace>

    <h:outputLabel for="unitDescriptionInput" value="UnitDescription:" />
    <p:inplace id="unitDescriptionInput" effect="none" editor="true" emptyLabel="UnitDescription">
        <p:inputText value="#{cc.attrs.compBean.componentData[cc.clientId].selectedStep.unit.description}" style="width:100%"/>
    </p:inplace>

Now if getSteps() returns an empty Array/List and I press the commandLink for addStep it crashes and I get the following Stacktrace:

javax.el.PropertyNotFoundException: Target Unreachable, 'selectedStep' returned null at org.apache.el.parser.AstValue.getTarget(AstValue.java:122) at org.apache.el.parser.AstValue.setValue(AstValue.java:194) at org.apache.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:260) at org.jboss.weld.el.WeldValueExpression.setValue(WeldValueExpression.java:64) at com.sun.faces.facelets.el.ContextualCompositeValueExpression.setValue(ContextualCompositeValueExpression.java:172) at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:131) at javax.faces.component.UIInput.updateModel(UIInput.java:832) at javax.faces.component.UIInput.processUpdates(UIInput.java:749) at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291) at org.primefaces.component.inplace.Inplace.processUpdates(Inplace.java:237) at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291) at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291) at org.primefaces.util.ComponentUtils.processUpdatesOfFacetsAndChilds(ComponentUtils.java:284) at org.primefaces.component.api.UITabPanel.processUpdates(UITabPanel.java:1108) at org.primefaces.component.tabview.TabView.processUpdates(TabView.java:336) at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291) at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291) at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291) at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291) at org.primefaces.component.wizard.Wizard.processUpdates(Wizard.java:192) at javax.faces.component.UIForm.processUpdates(UIForm.java:281) at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291) at org.primefaces.component.dialog.Dialog.processUpdates(Dialog.java:430) at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291) at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291) at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291) at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291) at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291) at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291) at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291) at org.primefaces.component.layout.Layout.processUpdates(Layout.java:254) at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291) at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291) at org.primefaces.component.layout.Layout.processUpdates(Layout.java:254) at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291) at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291) at javax.faces.component.UIViewRoot.processUpdates(UIViewRoot.java:1254) at com.sun.faces.lifecycle.UpdateModelValuesPhase.execute(UpdateModelValuesPhase.java:78) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at de.istec.pls.client.ui.filter.AuthenticationFilter.doFilter(AuthenticationFilter.java:137) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1081) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658) at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)

In case of a populated array I get the same exception of I add 2 Steps in a row. If a Step is added I call:

public void addStep() {
    Step newStep = new Step();
    Unit newUnit = new Unit();
    newStep.setName("Neuer Schritt");
    newStep.setParameters(new ArrayList<StepParameter>());
    newStep.setUnit(newUnit);
    ((DiagramElement) selectedElement.getData()).getSteps().add(newStep);
}

Maybe it is helpful to know that I am using the Primefaces Diagram. So the Steps are inside the Data of an Elementobject from Primefaces'.



Solution 1:[1]

You must verify that this sentence cc.attrs.compBean.componentData[cc.clientId].selectedStep is not null. Because you are using this object to retrieve other attributes. For me, the problem is there.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 martosfre