Struts2 - problema al recuperar atributo

331 views
Skip to first unread message

Cristian Ayala

unread,
Feb 28, 2011, 2:01:04 PM2/28/11
to jav...@googlegroups.com
disculpen lo extenso del mail, pero estoy empesando a ver un poco de struts 2 y tengo un problema que me impide continuar
estoy siguiendo un ejemplo del libro "struts 2 in action"

este es el jsp HelloWorld.jsp

<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
    <head>
    <title>HelloWorld</title>
    </head>

    <body>
   
      <!-- The property struts tag reads the value off the value stack.  In our case
           the Struts 2 framework has automatically made the Java bean properties of
           our action available to the result.  We just need to match the nomenclature
           of our value paramater below with the Java Beans attribute name of our
           HelloWorld action. 
      -->
      <hr>
        <h3>Custom Greeting Page</h3>     
        <h4><s:property value="customGreeting"/></h4><br>
        <h4><s:property value="customEdad"/></h4>
      <hr>
    </body>
   
</html>
----------------------------------------------------------------------------------

el atributo customGreetin lo muestra sin problemas pero customEdad no, tira el siguiente error:
GRAVE: ParametersInterceptor - [setParameters]: Unexpected Exception caught setting 'edad' on 'class manning.chapterTwo.HelloWorld: Error setting expression 'edad' with value '[Ljava.lang.String;@146e381'

les paso los siguientes archivos


NameCollector.jsp
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>

    <head>
    <title>Name Collector</title>
    </head>

    <body>
        <hr>
        <h4>Enter your name so that we can customize a greeting just for you!</h4>    
        <s:form action="HelloWorld">
        <s:textfield name="name" label="Your name"/>
        <s:textfield name="edad" label="Your age"/>
        <s:submit/>
        </s:form>
        <hr>   
    </body>
   
</html>
-----------------------------------------------------------------------------------

HelloWorld.java
package manning.chapterTwo;


public class HelloWorld {
   
   
    private static final String GREETING = "Hello ";

   
   
    public String execute()  {
                       
        setCustomGreeting( GREETING + getName() );
        setCustomEdad ( "Edad: " + getEdad());
       
        return "SUCCESS";
    }


       
    private String name;
   
 
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
   
    private String edad;
   
   
    public String getEdad() {
        return edad;
    }

    public void setEdad(String edad) {
        this.edad = edad;
    }
   
    private String customGreeting;
   
    public String getCustomGreeting()
    {
        return customGreeting;
    }
   
    public void setCustomGreeting( String customGreeting ){
        this.customGreeting = customGreeting;
    }
   
    private String customEdad;
   
    public String getCustomEdad()
    {
        return customEdad;
    }
   
    public void setCustomEdad( String customEdad ){
        this.customEdad = customEdad;
    }


   
}
---------------------------------------------------------------------------------------------

chapterTwo.xml
  ?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="chapterTwo" namespace="/chapterTwo" extends="struts-default">

               
                <action name="Name">
                       <result>/chapterTwo/NameCollector.jsp</result>
                </action>   


                <action name="HelloWorld" class="manning.chapterTwo.HelloWorld">
                    <result name="SUCCESS">/chapterTwo/HelloWorld.jsp</result>
            </action>
               
     </package>

</struts>

---------------------------------------------------------------------------------------------
struts.xml
<?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>

  
   <constant name="struts.devMode" value="true" />
        
        <package name="default" namespace="/" extends="struts-default">
            <action name="Menu">
                <result>/menu/Menu.jsp</result>
            </action>
        </package>   
       
    <include file="manning/chapterTwo/chapterTwo.xml"/>
 
</struts>


------------------------------------------------------------

cualquier ayuda sera bienvenida!
Saludos


Marcelo Velazquez

unread,
Mar 1, 2011, 9:24:08 AM3/1/11
to jav...@googlegroups.com
Hola,

Este tipo de error tiene que ver con el valor que posee el parametro al momento de
devolver la salida, valor null que no lo puede interpretar. Podes probar asignandole un valor como 0 desde la clase.

ayuda de referencia:
http://www.forosdelweb.com/f67/problema-campo-int-j2ee-859966/




--
www.JavaSOS.com
Grupo de colaboración Java/J2ee para desarrolladores de habla hispana.

Reply all
Reply to author
Forward
0 new messages