This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes JSF and the fly likes can't make ui:repeat work Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "can Watch "can New topic
Author

can't make ui:repeat work

Khalid Alghamdi
Greenhorn

Joined: Sep 26, 2010
Posts: 2
Hello

I have a web app with ui:repeat and h:dataTable tags. the repeat tag does not work while dataTable works. what did I do wrong in here. see code below

My index.xhtml has the following contens:

= Start ============================
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"<br/> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"<br/> xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">


<h1>Repeat Tag</h1>
<ul>
<ui:repeat var="color1" value="#{colorsBean.colors}">
<li>#{color1}</li>
</ui:repeat>
</ul>

<hr/>

<h1>DataTable Tag</h1>
<ul>
<h:dataTable var="color2" value="#{colorsBean.colors}">
<h:column>
<f:facet name="header">
<h:outputText value="Color" />
</f:facet>
<h:outputText value="#{color2}"/>
</h:column>
</h:dataTable>
</ul>
</html>

= End ============================



ColorsBean is as follows:

== Start ===========================
public class ColorsBean {
String []colors = new String[] {"White","Black","Freen","Blue","Red","Yellow","Cyan"};

public String[] getColors() {
return colors;
}

public void setColors(String[] colors) {
this.colors = colors;
}
}
= End ============================

the libraries I have under WEB-INF/lib are:
- jsf-api.jar
- jsf-facelets-1.1.11.jar
- jsf-impl.jar

==============================

here is the page output:

Repeat Tag
--------------------------------------------------------------------------------
DataTable Tag
Color
White
Black
Freen
Blue
Red
Yellow
Cyan
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15629
    
  15

Welcome to the JavaRanch, Khalid!

We're having a special on that question this week.

I'll give the same response as I have to everyone else: Why not simply use a dataTable?


Customer surveys are for companies who didn't pay proper attention to begin with.
Khalid Alghamdi
Greenhorn

Joined: Sep 26, 2010
Posts: 2
Tim Holloway wrote:Welcome to the JavaRanch, Khalid!

We're having a special on that question this week.

I'll give the same response as I have to everyone else: Why not simply use a dataTable?


I would like to use ui:repeat within a <h:selectOneMenu> tag
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15629
    
  15

Khalid Alghamdi wrote:
Tim Holloway wrote:Welcome to the JavaRanch, Khalid!

We're having a special on that question this week.

I'll give the same response as I have to everyone else: Why not simply use a dataTable?


I would like to use ui:repeat within a <h:selectOneMenu> tag


Ah. Today is my day to be completely and stupidly blind. Speaking of going blind, there's a "Code" button on our message editor. You can use it to wrap java code, xml and other things that the normal text editor won't display well.

I don't think you're going to be able to use ui:repeat there.

A JSF page is not a program like a normal JSP is. It's a declaration. So trying to do program-like things on a JSF view often fails, as can be seen by all the people who are asking questions like yours.

Beyond that, the JSF tags have very specifically-defined interrelationships. You can't validly insert a textInput control within a textOutput control for example.

For a DataTable, you need a DataModel to serve as the UI sub-model in the JSF Model/View/Controller setup. In most cases your table itself will be an array or List of elements of some sort of class, with the properties of the class serving as column names. In your case, for example:



You could then create a List of ColorItems, wrap them with a ListDataModel object and return that object to the dataTable in the View as the dataTable's "value" attribute.

All this is awkward, if not impossible to do in a JSF view. But then, that's what Backing Beans are for.
 
 
subject: can't make ui:repeat work
 
Similar Threads
DataTable datas are not actual
commandLink not working in datatable+jsf2.0
Problem trying to send file to browser in JSF
Sorting is not working in my JSF PrimeFaces Datatable and blank (empty) rows are displayed filtering
JSF form problems