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"?>

<computer_parts>
<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>
</computer_parts>

and index.jsp 
<[EMAIL PROTECTED] contentType="text/html"%>
<[EMAIL PROTECTED] pageEncoding="UTF-8"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/xml"; prefix="x"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"; prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<[EMAIL PROTECTED] import="java.util.Iterator"%>
<!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" />    
</head>
<body>

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

</body>
</html>

and class:
shopingCart.java
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) {
        this.add(id_item);
    }
    
    public void setRemoveItem(String id_item) {
        this.items.remove(id_item);
    }
}
-- 
View this message in context: 
http://www.nabble.com/x%3AforEach-problem-tf3839800.html#a10871888
Sent from the Taglibs - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to