tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From out <>
Subject x:forEach problem
Date Wed, 30 May 2007 11:36:24 GMT

Could anybody tell me what's wrong with the line  <x:forEach
select="$result//part" var="currentPart"> ??
(used jstl 1.1)
or maybe the error occures somewhere else

i noticed that if i add c:foreach above x:foreach there are no errors but
the page doesn't
view any data from xml file

here's code of items_data.xml file:
<?xml version="1.0" encoding="UTF-8"?>

<part ID="10"><name>Procesor 3.8 GHz</name><price>450.50</price></part>
<part ID="25"><name>Mysz laserowa</name><price>65.20</price></part>
<part ID="40"><name>Klawiatura multimedialna</name><price>12</price></part>
<part ID="50"><name>Monitor LCD 19</name><price>960</price></part>
<part ID="50"><name>Monitor CRT 17</name><price>360</price></part>

and index.jsp 
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@ taglib uri="" prefix="x"%>
<%@ taglib uri="" prefix="c"%>
<%@ taglib prefix="fmt" uri=""%>

<%@page import="java.util.Iterator"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />    

<jsp:useBean id="cart" class="beans.shoppingCart" scope="session"/>
<fmt:setBundle basename="properties.language" />
    <h1><fmt:message key="title" /></h1>
    <c:import var="xmlfile" url="items_data.xml"/>
    <x:parse var="result" doc="${xmlfile}"  />
        <table border="1">
                <td><fmt:message key="name"/></td>
                <td><fmt:message key="price"/></td>
         <x:forEach select="$result//part" var="currentPart">
 <!-- end="5"
var="result" xml="$ {xmlfile}"
                <td><x:out select="$currentPart/name" /></td>
                <td><x:out select="$currentPart/price" /></td>
                <c:set var="id_part">
                    <x:out select="currentPart/@ID" />
                <c:url value="/change_cart.jsp" var="addURL">
                    <c:param name="action" value="add"/>
                    <c:param name="id_part" value="${id_part}"/>
                <td> '<c:out value="${addURL}" ' 
                           <fmt:message key="add_to_cart"/> 
    <br> <fmt:message key="num_of_items"/>
    <c:out value="${cart.size}" /><br>
     show_cart.jsp <fmt:message key="show_cart"/> 


and class:
package beans;

import java.util.Hashtable;
 * @author Szeryf
public class shoppingCart {
    private Hashtable items;
    /** Creates a new instance of shoppingCart */
    public shoppingCart() {
        this.items = new Hashtable();
    public void add(String id_item){
        if (this.items.containsKey(id_item)){
            Integer quantity = (Integer)this.items.get(id_item);
            int newQuantity = quantity.intValue() + 1;
            this.items.put(id_item, new Integer(newQuantity));
        else {
            this.items.put(id_item, new Integer(1));
    public Hashtable getItems() {
        return this.items;
    public int getSize() {
        return items.size();
    public void setNewItem(String id_item) {
    public void setRemoveItem(String id_item) {
View this message in context:
Sent from the Taglibs - User mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message