• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with simple datatable

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

I'm new to JSF and to experiment with JSF, and Rich Datatables I tried to create a dumb, simple project to output a simple datable with only one column.

Its so simple that it should work but its not, I cant get my datatable to iterate over my collection.

I have 2 classes :

<blockquote>code:
<pre name="code" class="core">
package test;

import java.util.ArrayList;
import java.util.Collection;

public class TestBean {

private String nomTableau;
private Collection<Detail> listeDetails;

public TestBean(){
this.nomTableau = "Commmmoonn!!!";

this.listeDetails = new ArrayList<Detail>();

this.listeDetails.add(new Detail("detail 1"));
this.listeDetails.add(new Detail("detail 2"));
this.listeDetails.add(new Detail("detail 3"));
}

public Collection<Detail> getListeDetails() {

return listeDetails;
}

public void setListeDetails(Collection<Detail> listeDetails) {
this.listeDetails = listeDetails;
}

public String getNomTableau() {
return nomTableau;
}

public void setNomTableau(String nomTableau) {
this.nomTableau = nomTableau;
}


}
</pre>
</blockquote>

And :

<blockquote>code:
<pre name="code" class="core">
package test;

public class Detail {

private String detail;

public Detail(){
this.detail = "bidon";
}

public Detail(String detail){
this.detail = detail;
}

public String getDetail() {
return detail;
}

public void setDetail(String detail) {
this.detail = detail;
}
}
</pre>
</blockquote>

In faces-config.xml I put my TestBean class as bein managed :

<blockquote>code:
<pre name="code" class="core">
<faces-config>
<managed-bean>
<managed-bean-name>testBean</managed-bean-name>
<managed-bean-class>test.TestBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
</faces-config>
</pre>
</blockquote>


And finaly, I try to output the result in a jsp file :

<blockquote>code:
<pre name="code" class="core">
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<html>
<head>
<title>Simple Data Table</title>
</head>
<body>

<rich:dataTable id="laTable" var="item" value="#{testBean.listeDetails}" >
<rich:column>
<f:facet name="header">
<h:outputText value="#{testBean.nomTableau}" />
</f:facet>
<h:outputText value="#{item.nomDetail}" />
</rich:column>
</rich:dataTable>

</body>
</html>
</pre>
</blockquote>


The value of "testBean.nomTableau" is displayed but thats all. When I check the logs I always get the following output when I try to print the value of "item.nomDetail" :

<blockquote>code:
<pre name="code" class="core">
(DEBUG) ValueBindingImpl : getValue(ref=item.nomDetail)
(DEBUG) ApplicationImpl : Couldn't find a factory for item
(DEBUG) VariableResolverImpl : resolveVariable: Resolved variable:null
(DEBUG) ValueBindingImpl : getValue Result:null
(DEBUG) ValueBindingImpl : -->Returning null
(DEBUG) HtmlBasicInputRenderer : component.getValue() returned null
(DEBUG) HtmlBasicRenderer : Value to be rendered null
</pre>
</blockquote>

Anybody have an idea of what I'm doing wrong?

Thank you!

Maxime
 
Max Duval
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, my problem is solved.

I added <f:view> tags and it fixed my problem. Are those tags mandatory when you want to display dynamic data in JSF?

Maxime
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Max the problem I found is that <h:outputText value="#{item.nomDetail}" /> should be <h:outputText value="#{item.detail}" />, because the attribute for the class Detail is detail and the getDetail() method is the one that will return the value. Otherwise you should have a method named getNomDetail() for your actual code to work.

Also don't forget the <f:view> and <h:form> tags for the page.

Hope this helps.
 
Max Duval
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Andres for your awnser.

When I sent this post, I was in the middle of changing the name in Detail to "nomDetail" but I forgot to do it before putting the code snippet.

As for the <f:view> and <h:form>, it started working when I added the <f:view> tag. I still dont have a <h:form> one.

Are those tags always mandatory? If I'm only displaying data, is <h:form> necessary?

Thansk!

Maxime
 
Andres Quinones
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The <h:form> is only when you need to do requests to the server, otherwise you only need the <f:view>.

Good to hear that now is working. Any other questions don't hesitate to post.
 
reply
    Bookmark Topic Watch Topic
  • New Topic