I am sure this is a very silly problem, however I have been struggling
with this for a while now. I am trying to iterate over a collection using
JSF and JSTL's forEach which is apparently supported in JSP2.1 (2.0) and
Tomcat 6.

I have the version number in web.xml set to 2.5 and the faces-config.xml
file set to 1.2 (see below).

I checked the version of JARS included in the WAR file and they are :

standard.jar : Implementation-Version: 1.1.2
jstl.jar : Implementation-Version: 1.1.2
jsf-impl.jar : Implementation-Version: 1.2_04-b20-p03
jsf-api.jar : Implementation-Version: 1.2_04-b20-p03

Below are the configuration files included with my WAR. I am using Tomcat
apache-tomcat-6.0.16. I have found some older examples where I got this
working, however I can't see why it doesn't work for me anymore.

Any suggestions on this would really help me out a lot.

Thanks in advance.
Alex

web.xml
=======
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd";>
...


faces-config.xml
================
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="1.2"
    xmlns="http://java.sun.com/xml/ns/javaee";
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd";>
    <managed-bean>
        <managed-bean-name>Controller</managed-bean-name>
        <managed-bean-class>com.simple.Controller</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>
</faces-config>

jsp file
========
<[EMAIL PROTECTED] contentType="text/html"%>
<[EMAIL PROTECTED] pageEncoding="UTF-8"%>
<[EMAIL PROTECTED] prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<[EMAIL PROTECTED] prefix="f" uri="http://java.sun.com/jsf/core"%>
<[EMAIL PROTECTED] prefix="h" uri="http://java.sun.com/jsf/html"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd";>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
  </head>
  <body>
    <f:view>
      <h1>Hallo : <h:outputText value="#{Controller.message}"/></h1>
      <h1><h:outputText value="JavaServer Faces" /></h1>
      <c:forEach var="item" items="#{Controller.messages}">
        <h1>Hallo</h1>
        <h:outputText id="value" value="#{item}"/>
      </c:forEach>
    </f:view>
  </body>
</html>


jspx file
=========
<?xml version="1.0" encoding="UTF-8"?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page";
          xmlns:h="http://java.sun.com/jsf/html";
          xmlns:f="http://java.sun.com/jsf/core";
          xmlns:c="http://java.sun.com/jsp/jstl/core";
          xmlns="http://www.w3.org/1999/xhtml";
          version="2.1">
  <jsp:directive.page contentType="text/html"/>
  <jsp:output doctype-root-element="html"
              doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
              
doctype-system="http://www.w3c.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>

    <jsp:directive.page contentType="text/html" pageEncoding="UTF-8"/>

    <!-- any content can be specified here, e.g.: -->
    <jsp:element name="text">
        <jsp:attribute name="lang">EN</jsp:attribute>
        <jsp:body>Hello World!</jsp:body>
    </jsp:element>
  <f:view>
    <h1>Hallo 2 : <h:outputText value="#{Controller.message}"/></h1>
    <h1><h:outputText value="JavaServer Faces" /></h1>
    <c:forEach var="item" items="#{Controller.messages}">
      <h1>Hallo</h1>
      <h:outputText id="value" value="#{item}"/>
    </c:forEach>
  </f:view>
</jsp:root>


Controller.java
===============
package com.simple;
import java.util.ArrayList;
import java.util.List;
public class Controller
{
  private ArrayList<String> stuff = new ArrayList<String>();
  public Controller()
  {
    System.out.println("Creating Controller");
    stuff.add("A1");
    stuff.add("A2");
    stuff.add("A3");
    stuff.add("A4");
    stuff.add("A5");
  }
  public String getMessage()
  {
    return "This is a message";
  }
  public ArrayList<String> getMessages()
  {
    System.out.println("Getting Stuff");
    return stuff;
  }
  public void setMessage(ArrayList<String> stuff)
  {
    System.out.println("Setting Stuff");
    this.stuff = stuff;
  }
}




---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to