0

I'm getting this "Base is null: item" jsf1.1 error in datatable that I just couldn't quite figure out. It is a two level datatable and the error is happening on the 2nd level datatable. The first level datatable is bind to the value of ArrayList deviceListDeviceReferences. In this datatable, it has a column that contains another datatable. This 2nd level datatable is bind to the value of ArrayList holderNameMasks. This value it retrived from DeviceReferenceJTO, which is basically the row item from the first datatable.

Below is what a snippet of the html:

<h:dataTable border="0" cellspacing="0"
    value="#{deviceReferenceBean.deviceListDeviceReferences" var="item"  
    rendered="#{not empty deviceReferenceBean.deviceListDeviceReferences }"  
    binding="#{deviceReferenceBean.deviceListDeviceReferencesTable}"
>
    <h:column>
        <h:outputText value="Holder Name:" />
        <!--  device heading -->
        <h:outputText value="#{item.deviceLabel }" styleClass="DeviceReferenceTitleBarBorder" style="width:100%; height:30px; background-color:#f9f9f9"/>
        <!-- holder name -->   
        <h:panelGrid columns="2" rendered="#{item.hasHolderNameMasks}" >
            <h:outputText value="Holder Name:" />
            <h:dataTable border="0" cellspacing="0" 
                value="#{item.holderNameMasks}" var="holderMaskItem"  
                rendered="#{not empty deviceReferenceBean.deviceListDeviceReferences and item.hasHolderNameMasks}"  
                binding="#{item.holderNameMasksTable}"
            >
                <h:column>
                    <h:outputText value="#{holderMaskItem.fieldLabel}" />
                </h:column>
                <h:column>
                    <h:panelGrid columns="1">
                        <h:inputText value="#{holderMaskItem.fieldValue}" />
                        <h:outputText value="#{holderMaskItem.instruction }" rendered="#{holderMaskItem.hasInstruction"/>
                    </h:panelGrid>
                </h:column>
            </h:dataTable>
        </h:panelGrid>  
    </h:column>
</h:dataTable>

Below is what the component looks like:

<HtmlForm enctype="application/x-www-form-urlencoded" id="_idJsp323" rendered="true" styleClass="MAForm" submitted="false" transient="false">

    <HtmlDataTable border="0" cellspacing="0" first="0" id="_idJsp324" rendered="#{not empty deviceReferenceBean.deviceListDeviceReferences }=true" rowIndex="-1" rows="0" transient="false" var="item" binding="#{deviceReferenceBean.deviceListDeviceReferencesTable}">

        <UIColumn id="_idJsp325" rendered="true" transient="false">

            <HtmlOutputText escape="true" id="_idJsp326" rendered="true" style="width:100%; height:30px; background-color:#f9f9f9" styleClass="DeviceReferenceTitleBarBorder" transient="false"/>

            <HtmlPanelGrid border="-2147483648" columns="2" id="_idJsp327" rendered="#{item.hasHolderNameMasks}=true" transient="false">

                <HtmlOutputText escape="true" id="_idJsp328" rendered="true" transient="false" value="Holder Name:"/>

            </HtmlPanelGrid>

        </UIColumn>

    </HtmlDataTable>

</HtmlForm>
HockChai Lim
  • 1,675
  • 2
  • 20
  • 30
  • What's the type of the `deviceListDeviceReferences` objects ? – Konstantin Yovkov May 18 '13 at 23:43
  • It is a ArrayList of DeviceReferenceJTO: private ArrayList deviceListDeviceReferences; – HockChai Lim May 19 '13 at 00:21
  • The statement `binding="#{item.holderNameMasksTable}"` means that the `DeviceReferenceJTO` should have a property of type `HtmlDataTable` with the proper accessors. – Konstantin Yovkov May 19 '13 at 00:23
  • and in DeviceReferenceJTO class, it has ==> private ArrayList holderNameMasks", which is what the 2nd datatable uses. – HockChai Lim May 19 '13 at 00:25
  • Yes, DeviceReferenceJTO has => private transient HtmlDataTable holderNameMasksTable; and its getter and setter – HockChai Lim May 19 '13 at 00:28
  • OK. `Base is null` basically means, that the `deviceListDeviceReferences` is null. Are you sure it has elements ? – Konstantin Yovkov May 19 '13 at 00:33
  • Initially, it is empty (size=0). I've a rendered condition to not display if it is empty. So, I'm not sure why that would be a problem. But, anyway, that was what I was thinking the cause problem also. So, I've tried temporary changed the code to add an element into the array, but problem persist.... – HockChai Lim May 19 '13 at 00:47

1 Answers1

1

The culprit is here:

<h:dataTable
    binding="#{item.holderNameMasksTable}"
>

The binding (and id) attributes of UI components are resolved during view build time (that moment when JSF parses the XHTML file into a component tree). However, the #{item} is only available during view render time (that moment when JSF encodes the component tree to HTML output). Thus, there where you're using binding="#{item.xxx}" would always fail because the #{item} is null. Note that this is exactly what the exception is trying to tell you.

You've 2 options:

  1. Get rid of binding attribute altogether.
  2. Bind to #{deviceReferenceBean} instead. It's available during view build time.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • right on. It works fine after I got rid of the binding (option 1 you suggested). holderNameMasks is at the item level, so, I'm not sure how I can bind to a HtmlDataTable from #{deviceReferenceBean}. Thank you for your help. I've spent two days on this error without luck. It helps to have expert giving pointer :). – HockChai Lim May 20 '13 at 14:54
  • Just use `binding="#{deviceReferenceBean.holderNameMasksTable}"`? Please note that there are no multiple `` components. There's only one. It's just that it's been reused multiple times during producing HTML output (during view render time). Reading the "JSTL in JSF2 Facelets... makes sense?" link should be enlightening as to how JSF view building/rendering works. I recommend to carefully read it. – BalusC May 20 '13 at 14:58
  • hm, interesting. So. multiple list can bind to same HtmlDataTable? Thank you. I'll try to read it up when I got sometime. – HockChai Lim May 20 '13 at 15:09