• 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

can't make ui:repeat work

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Khalid Alghamdi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Put the moon back where you found it! We need it for tides and poetry and stuff. Like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic