jsf and datatable

hello,

i have a problem with <h:dataTable/>

i just want to give out some data in a table:

my jsf-file has such one code:

<h:dataTable id="items" value="#{xmlDatas.hotelTable}" var="hotelLocation">

<h:column>

<f:facet name="header">

<h:outputText value="Location"/>

</f:facet>

<h:outputText value="#{hotelLoc.hotelLocation}"/>

</h:column>

my xmlDatas-Bean has this code:

private DataModel hotelModel =new ListDataModel();

ArrayList<HotelLocation> tempData =new ArrayList<HotelLocation>();

public DataModel getHotelTable(){

for(int i = 0; i < getResultCount(); i++)

{

tempData.add(new HotelLocation(getResult(i).getServiceDesc()));

}

hotelModel.setWrappedData(tempData);

return hotelModel;

}

getServiceDesc() gives me information about hotels. My HotelLocation-class gets the hotels, but the output in jsf-file is empty. Where could be here the mistake?

[1577 byte] By [naekoa] at [2007-11-27 1:09:47]
# 1
Where do you think that this value comes from?<h:outputText value="#{hotelLoc.hotelLocation}"/>while the row object is definied asvar="hotelLocation"
BalusCa at 2007-7-11 23:45:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

i have one bean more (hotelLoc)

class HotelLocation()

{

public HotelLocation(String hotelLocation)

{

this.hotelLocation = hotelLocation;

}

public String getHotelLocation() {

return hotelLocation;

}

public void setHotelLocation(String hotelLocation) {

this.hotelLocation = hotelLocation;

}

}

naekoa at 2007-7-11 23:45:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

The datatable works as follows:

<h:dataTable value="#{myBean.list}" var="item">

<h:column><h:outputText value="#{item.value}" /></h:column>

</h:dataTable>

Where MyBean#getList() returns List<Item> (or for example ListDataModel(List<Item>), if you want) and the Item DTO contains a property "value" which can be retrieved by Item#getValue().

Also check http://balusc.xs4all.nl/srv/dev-jep-dat.html how to use datatables.

BalusCa at 2007-7-11 23:45:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

thanks for the link

This was my mistake:

instead of

<h:dataTable id="items" value="#{xmlDatas.hotelTable}" var="hotelTable">

<h:column>

<f:facet name="header">

<h:outputText value="Location"/>

</f:facet>

<h:outputText value="#{hotelLoc.hotelLocation}"/>

</h:column>

->

<h:dataTable id="items" value="#{xmlDatas.hotelTable}" var="hotelLocationItem">

<h:column>

<f:facet name="header">

<h:outputText value="Location"/>

</f:facet>

<h:outputText value="#{hotelLocationItem.hotelLocation}"/>

</h:column>

naekoa at 2007-7-11 23:45:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
You haven't told if your problem is solved or not :)
BalusCa at 2007-7-11 23:45:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

its solved:-)

i get all my data i want.

So i would like to split my resultlist (to show not the whole list, but only 10 of them and the rest could be chosen by link):

myData:

*1

*2

*3

*4

*5

*6

*7

*8

*9

*10

Here the links:

12345 (depending on the size of resultlist)

are there any examples for this undertaking?

naekoa at 2007-7-11 23:45:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
In the same datatable article I've linked here above a simple form of paging is also described. Adding links to specific pages requires a bit more work (you need to create a specific custom component), but you can base on the same code.
BalusCa at 2007-7-11 23:45:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

ok, thank you.

i have a very weird situation in my project.

I have a one jsf-page:

<html>

<f:view>

<head></head>

<body>

<h:panelGrid>

<h:panelGroup id="datanavi">

<jsp:include page="datanavi.jsp"></jsp:include>

</h:panelGroup>

</h:panelGrid>

</body>

</f:view>

</html>

in this page i include other one (datanavi.jsp)

this has following structure:

<h:form>

<h:panelGrid>

<h:column>

<h:outputText/>

</h:column>

..........

</h:panelGrid>

<h:commandButton id="dbconnect1" action="#{xmlDatas.buildXML}" value = "Send"></h:commandButton>

<h:panelGroup id="navi2" rendered="#{xmlDatas.showHotelDetails == true}">

<jsp:include flush="true" page="datanavi_hotels.jsp"></jsp:include>

</h:panelGroup>

</h:form>

as one can see i include other site, which is only shown if a flag is set. This flag will be set in buildXML-function.

The datanavi_hotels.jsp looks like:

<h:form>

<h:dataTable value="#{xmlDatas.hotelTable}">

...****here the data of hotelTable***

</h:dataTable>

</h:form>

so.....whatever i do in datanavi.jsp i always come in hotelTable() function, although i expect to get into buildXML() method.

What could be a problem?

naekoa at 2007-7-11 23:45:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9
As stated in the W3C HTML spec, you may not nest forms. So put the jsp:include to datanavi_hotels.jsp outside the form.Or remove the form around the datatable.
BalusCa at 2007-7-11 23:45:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...