h:datatable not populated

梦想与她 提交于 2021-02-10 17:26:44

问题


This is a related (and or follow up) issue to :

Event Function called before Setter

So Given i have :

<Td>
<h:selectOneMenu id="combocarList" 
value="#{customerBean.selectedcar}"
styleClass="comboStyle"
valueChangeListener="#{customerBean.loadothercombos}"
onchange="document.forms[0].submit()"
>
<f:selectItem
    itemLabel="-----------Select--------------"
    itemValue="None" />
<f:selectItems value="#{customerBean.carsList}" />
</h:selectOneMenu>
</Td>

the event is called when user selects an item from dropdown list and the backbean does the processing to retrieve values of other dropdown list which works ok , BUT i also have a h:datatable which is the problem. The values won't show.

the datatable is defined as:

<h:dataTable
    id="calDetails" rowClasses="oddrow,evenrow"
    headerClass="thHeading" var="car"
    value="#{cardetails.allinfo}">
    <h:column>
        <f:facet name="header">
            <h:outputText id="lblCode" value="Code"></h:outputText>
        </f:facet>
        <h:inputHidden value="#{car.code}"></h:inputHidden>
        <h:outputText id="carcodeid"
            value="#{car.code}"></h:outputText>
    </h:column>
    <h:column>
        <f:facet name="header">
            <h:outputText id="lblCode" value="Sold"></h:outputText>
        </f:facet>
        <h:inputHidden value="#{car.sales}"></h:inputHidden>
        <h:outputText id="carsalesid"
            value="#{car.sales}"></h:outputText>
    </h:column>
</h:dataTable>

i have setter and getters for cardetails.allinfo and i know when document.forms[0].submit() is called cardetails.allinfo is not null since as i tested it using

 <h:outputText value="#{cardetails.allinfo eq null}" />

which returned false. I've been starring at it for hours and can't see my fault. would appreciate any input. Thanks


回答1:


Apparently the list is just empty. A better debug is

<h:outputText value="#{not empty cardetails.allinfo}" />

This will show true whenever the allinfo is not null and not empty. You could also do

<h:outputText value="#{cardetails.allinfo}" />

to see all list items in plain text as represented by ArrayList#toString(). If you see [] then it's indeed empty. Otherwise if you see [com.example.Car@1234,com.example.Car@5678], then it has 2 Car items (assuming that you didn't override its toString() method to return a more human readable String representation as many starters do ;) ).

In case of an empty list, you'd need to debug and fix your list loading logic from the DB.



来源:https://stackoverflow.com/questions/7727432/hdatatable-not-populated

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!