dataTable Problem

I am very new to JSF and I have a simple problem.

I am trying to use dataTable to display a List but it is not working.

Here is my code:

<f:view>

<h:form>

<h:dataTable border="1" value="#{StudentBean.students}" var="studentlist">

<h:column>

<f:facet name="header" >

<h:outputText value="Student Name" />

<h:outputText value="#{studentlist.student.name}" />

</f:facet>

</h:column>

</h:dataTable>

<h:outputText value="#{studentlist.student.name}" />

</h:form>

</f:view

And here is my backing bean:

import java.util.ArrayList;

import java.util.List;

import org.polaris.business.logic.Student;

import org.polaris.database.DatabaseConnection;

/**

*

* @author john

*/

publicclass StudentBeanextends DatabaseConnection{

private List students =new ArrayList();

/** Creates a new instance of StudentBean */

public StudentBean(){

}

public List getStudents(){

/** @ check if data exists for students */

Student student =new Student();

student.setName("Doe, John");

students.add(student);

return this.students;

}

publicvoid setStudents(List students){

this.students = students;

}

}

As you can see the example is very very simple, but the data ("Doe, John") is not displayed in the table. Can anyone see what is my error?

Thanks>

[2561 byte] By [John27a] at [2007-10-2 16:45:52]
«« JAAS
»» login
# 1

You have two errors:

<f:view>

<h:form>

<h:dataTable border="1" value="#{StudentBean.students}" var="studentlist">

<h:column>

<f:facet name="header" >

<h:outputText value="Student Name" />

A<h:outputText value="#{studentlist.student.name}" />

</f:facet>

</h:column>

</h:dataTable>

B <h:outputText value="#{studentlist.student.name}" />

</h:form>

</f:view

In the error A you are trying to access to a property that don't exists.

Your list is already a stundent list, so you don't need to specify it.

The solution:

><h:outputText value="#{studentlist.name}" />

In the error B

You are trying to access to a var that is defined inside the datatable, but you are outside of it, so you don't have access to it.

pringia at 2007-7-13 17:56:13 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Thank you for replying. I made the changes you suggested as follows:

<f:view>

<h:form>

<h:dataTable border="1" value="#{StudentBean.students}" var="studentlist">

<h:column>

<f:facet name="header" >

<h:outputText value="Student Name" />

<h:outputText value="#{studentlist.name}" />

</f:facet>

</h:column>

</h:dataTable>

</h:form>

</f:view>

However, the student name "Doe, John" did not display.

John27a at 2007-7-13 17:56:13 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Can you show your faces-config.xml?
pringia at 2007-7-13 17:56:13 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Check your Tomcat logs. You'll likely see a detailed error message there.
bek816a at 2007-7-13 17:56:13 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Thanks pringi, I finally got it working.regardsJohn
John27a at 2007-7-13 17:56:13 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...