Ver Mensaje Individual
  #1 (permalink)  
Antiguo 27/09/2009, 17:36
ssh
 
Fecha de Ingreso: agosto-2009
Mensajes: 85
Antigüedad: 15 años, 5 meses
Puntos: 0
Combobox con Struts 2 desde BD

Hola, estoy intentando implementar un combobox siguiendo las indicaciones que entrega apache (creadores de Struts 2) para leer un ArrayList desde mi código java, Apache propone este código:

Código:
<s:bean name="struts.util.Counter" var="year">
  <s:param name="first" value="text('firstBirthYear')"/>
  <s:param name="last" value="2000"/>

  <s:combobox label="Birth year" size="6" maxlength="4" name="birthYear" list="#year"/>
</s:bean>
Desde la web: http://struts.apache.org/2.1.6/docs/combobox.html

Mi código es el siguiente, tengo dos clases:

package.Customer.java
Código:
 public class Customer {

     private String name;
     private int age;
     private String email;

    public String getName() {
         return name;
     }
     public void setName(String name) {
         this.name = name;
     }
     public int getAge() {
         return age;
     }
     public void setAge(int age) {
         this.age = age;
     }
     public String getEmail() {
         return email;
     }
     public void setEmail(String email) {
         this.email = email;
     }
 }
package.Combo.java
Código:
import com.opensymphony.xwork2.ActionSupport;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
import package.Customer;

public class Combo extends ActionSupport implements java.util.Iterator, java.io.Serializable {
    @Override
    public boolean hasNext() {
        return false;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public Object next() {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public void remove() {
        //To change body of implemented methods use File | Settings | File Templates.
    }

 List<Customer> customers;

       public String execute()  {

           customers = new ArrayList<Customer>();

           tags.dto.Customer c = new Customer();
           c.setName("George Joseph");
           c.setAge(45);
           c.setEmail("[email protected]");
           customers.add(c);

           System.out.println("Crea Customer c:" + c.getName());


           c = new Customer();
           c.setName("Mary Philip");
           c.setAge(22);
           c.setEmail("[email protected]");
           customers.add(c);

           System.out.println("Crea Customer c:" + c.getName());
           customers.iterator();

           return SUCCESS;
       }
       public List<Customer> getCustomers() {
           return customers;
       }
       public void setCustomers(List<Customer> customers) {
           this.customers = customers;
       }      

}
Mi config en struts.xml
Código:
<?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE struts PUBLIC
     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
     "http://struts.apache.org/dtds/struts-2.0.dtd">
 <struts>
     <package name="tags" extends="struts-default">

         <action name="IterateDemo"
             class="package.Combo">
             <param name="customers"/>
             <result>/tags/iteratedemo.jsp</result>
         </action>    

     </package>
 </struts>
Mi pagina.jsp:
Código:
<%@ taglib prefix="s" uri="/struts-tags"%>
 <html>
 <head>
<title>COMBOBOX con Struts 2</title>
 </head>
 <body>
 <s:form>
    <s:action name="IterateDemo" var="customers" >
     Comienza Combo
        <s:bean name="tags.iterate.action.Combo" var="customers">
            <s:param name="customers" value="text{'name'}"/>
            <s:combobox label="Lenguajes" size="6" maxlength="4" name="name" list="#customers"/>
        </s:bean>
     Fin Combo
    </s:action>
 </s:form>

 </body>
 </html>
Archivo web.xml
Código:
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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"
           version="2.5">

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

Ese es el proyecto completo, adjunté todos los archivos para alguien que le pueda servir, el único problema es que no me muestra los valores de "customers" sino que sólo muestra un combo vacío.

Ayuda por favor!! He seguido esta web: http://struts.apache.org/2.1.6/docs/combobox.html

(La guía de apache, pero aún así no me resulta! Qué hago mal??)
Ayudaaaa!!!!