Topic
  • 5 replies
  • Latest Post - ‏2010-12-06T12:18:55Z by mathandos
kaghamdi
kaghamdi
3 Posts

Pinned topic can't make ui:repeat work

‏2010-09-26T17:09:33Z |
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
Updated on 2010-12-06T12:18:55Z at 2010-12-06T12:18:55Z by mathandos
  • phalgunkumar
    phalgunkumar
    4 Posts

    Re: can't make ui:repeat work

    ‏2010-09-27T06:46:28Z  
    try replacing the code
    • #{color1}
    • with
    • <h:outputText value="#{color1}"/>
    • in ui:repeat tag.
  • kaghamdi
    kaghamdi
    3 Posts

    Re: can't make ui:repeat work

    ‏2010-09-27T18:12:24Z  
    try replacing the code
    • #{color1}
    • with
    • <h:outputText value="#{color1}"/>
    • in ui:repeat tag.
    I replaced it with <h:outputText value="#{color1}"/> and I got the same result.
  • phalgunkumar
    phalgunkumar
    4 Posts

    Re: can't make ui:repeat work

    ‏2010-09-28T08:40:44Z  
    • kaghamdi
    • ‏2010-09-27T18:12:24Z
    I replaced it with <h:outputText value="#{color1}"/> and I got the same result.
    As far as i know ui:repeat tag should be used in the follwing way.
    <ui:decorate template="/pages/repeat/indextemplate.xhtml">
    <ui:define name="color">
    • <ui:repeat var="color1" value="#{colorsBean.colors}">
    • <h:outputText value="#{color1}"/>
    • </ui:repeat>
    </ui:define>
    </ui:decorate>

    Can u plz try with above code and let me know.
  • kaghamdi
    kaghamdi
    3 Posts

    Re: can't make ui:repeat work

    ‏2010-09-28T15:28:48Z  
    As far as i know ui:repeat tag should be used in the follwing way.
    <ui:decorate template="/pages/repeat/indextemplate.xhtml">
    <ui:define name="color">
    • <ui:repeat var="color1" value="#{colorsBean.colors}">
    • <h:outputText value="#{color1}"/>
    • </ui:repeat>
    </ui:define>
    </ui:decorate>

    Can u plz try with above code and let me know.
    I tried this but nothing showed up:

    <ui:decorate>
    <ui:define name="color">

    <ui:repeat var="color1" value="#{colorsBean.colors}">
    <h:outputText value="#{color1}"/>
    </ui:repeat>

    </ui:define>
    </ui:decorate>

    Then I tried this and it worked:
    <h:selectOneMenu id="selectedcolor">
    <f:selectItems value="#{colorsBean.colors}" var="i"/>
    </h:selectOneMenu>
    Now, I want to get the colors from the database where a table has tow columns color_id and color_name as follows:

    color_id color_name
    1 White
    2 Black
    3 Green
    4 Blue
    5 Red
    6 Yellow
    7 Cyan

    and I want to display a select list like:

    <select name='colors'>
    <option value='1'>White </option>
    <option value='2'>Black </option>
    <option value='3'>Freen </option>
    <option value='4'>Blue </option>
    <option value='5'>Red </option>
    <option value='6'>Yellow </option>
    <option value='7'>Cyan </option>
    </select>

    I does not work if I pass a ResultSet to f:selectItems and also does not work if I pass String[] for example:

    <h:selectOneMenu id="colors">
    <f:selectItems value="#{colorsBean.colorList}" var="i2" itemValue="#{i2[1]}" itemLabel="#{i2[2]}"/>
    </h:selectOneMenu>

    where colorsBean.colorList returns:

    String][colorList = new String][ {
    {"1", "White"},
    {"2", "Black"},
    {"3", "Freen"},
    {"4", "Blue"},
    {"5", "Red"},
    {"6", "Yellow"},
    {"7", "Cyan"}};
  • mathandos
    mathandos
    1 Post

    Re: can't make ui:repeat work

    ‏2010-12-06T12:18:55Z  
    • kaghamdi
    • ‏2010-09-28T15:28:48Z
    I tried this but nothing showed up:

    <ui:decorate>
    <ui:define name="color">

    <ui:repeat var="color1" value="#{colorsBean.colors}">
    <h:outputText value="#{color1}"/>
    </ui:repeat>

    </ui:define>
    </ui:decorate>

    Then I tried this and it worked:
    <h:selectOneMenu id="selectedcolor">
    <f:selectItems value="#{colorsBean.colors}" var="i"/>
    </h:selectOneMenu>
    Now, I want to get the colors from the database where a table has tow columns color_id and color_name as follows:

    color_id color_name
    1 White
    2 Black
    3 Green
    4 Blue
    5 Red
    6 Yellow
    7 Cyan

    and I want to display a select list like:

    <select name='colors'>
    <option value='1'>White </option>
    <option value='2'>Black </option>
    <option value='3'>Freen </option>
    <option value='4'>Blue </option>
    <option value='5'>Red </option>
    <option value='6'>Yellow </option>
    <option value='7'>Cyan </option>
    </select>

    I does not work if I pass a ResultSet to f:selectItems and also does not work if I pass String[] for example:

    <h:selectOneMenu id="colors">
    <f:selectItems value="#{colorsBean.colorList}" var="i2" itemValue="#{i2[1]}" itemLabel="#{i2[2]}"/>
    </h:selectOneMenu>

    where colorsBean.colorList returns:

    String][colorList = new String][ {
    {"1", "White"},
    {"2", "Black"},
    {"3", "Freen"},
    {"4", "Blue"},
    {"5", "Red"},
    {"6", "Yellow"},
    {"7", "Cyan"}};
    Hi,

    I'm experiencing a similar problem, but in my case it shows an empty list.

    Hopefully someone will be able to assist.
    Here's a snippet of both my bean and jsf.
    Bean
    ----
    @Begin(join=true)
    public ArrayList<HashMap<String, Object>> getCourseList() throws Exception
    {
    Integration ig = (Integration)Component.getInstance("integration");
    if (ig != null)
    {
    HashMap localHashMap;
    ArrayList resList = ig.getList("CourseDetails", "select ed from CourseDetails ed");
    System.out.println("The length of the List is " + resList.size() + " Elements");
    for (Iterator localIterator = resList.iterator(); localIterator.hasNext(); localHashMap = (HashMap)localIterator.next());

    return resList;
    }
    else
    {
    System.out.println("!Unable to get integration component!");
    }
    return null;
    }

    jsf
    ---

    <h:selectOneMenu value="#{studentHome.instance.fkCourseDetails}">

    <a4j:repeat id="courseList" value="#{studentList.courseList}" var="course">

    <f:selectItems itemValue="#{course.get('fkCourse')}" itemLabel="#course.get('courseName')}" />
    </a4j:repeat>

    </h:selectOneMenu>

    is there a workaround this so my list shows some value?

    Thanking you in advance
    Thandos