You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Riccardo Mollame <rm...@yahoo.it> on 2007/08/22 15:21:33 UTC

Struts2 - troubles with ParameterAware

file set:

Launch JSP page: TestActionParam.jsp
Action: ActionParam.java
Response JSP page: ActionParam.jsp
Struts config file: struts.xml

source code:

******** TestActionParame.jsp ******

<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
  <head>
    <meta http-equiv="Content-Type"
content="text/html; charset=windows-1252"/>
    <title>TestActionParam</title>
  </head>
  <body>
    <br>
    <center><a
href='actionparam.action?par=YES'>test</a></center>  
  </body>
</html>

******** ActionParam.java ********

package test;

import com.opensymphony.xwork2.ActionSupport;
import java.util.Map;
import org.apache.struts2.interceptor.ParameterAware;

public class ActionParam extends ActionSupport
implements ParameterAware {
    public static final String MESSAGE = "Test passed:
";
    private String message;
    private Map parameters;
    public String execute() throws Exception {
        String[] par =
(String[])parameters.get("par");
        String parVal=((par!=null)?par[0]:"NO");
        setMessage(MESSAGE + " " + parVal);        
        return "success";
    }
    public void setMessage(String message){
        this.message = message;
    }
    public String getMessage(){
        return message;
    }    
    public void setParameters(Map parameters) {
     this.parameters=parameters;
    }
    public Map getParameters() {
     return parameters;
    }
}

********** ActionParam.jsp ***********

<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
  <head>
    <meta http-equiv="Content-Type"
content="text/html; charset=windows-1252"/>
    <title>ActionParam</title>
  </head>
  <body>
  <h2><s:property value="message"/></h2>
 </body>
</html>

*********** struts.xml ***********

<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts
Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
    <package name="default"
extends="struts-default"></package>
    <package name="test" extends="struts-default">
        <action name="actionparam"
class="test.ActionParam">
            <result>/ActionParam.jsp</result>
            <interceptor-ref name="servlet-config" />
            <interceptor-ref name="params"/>
        </action>
    </package>
</struts>

**********************

Result: passed "par" parameter always null ... (though
it is actually present in the URL)

******** WHERE'S THE DAMN PROBLEM?!? ********

A very discouraged Struts 2 newbie...

Thanks in advance.

              Ric



      ___________________________________ 
L'email della prossima generazione? Puoi averla con la nuova Yahoo! Mail: http://it.docs.yahoo.com/nowyoucan.html

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts2 - troubles with ParameterAware

Posted by Riccardo Mollame <rm...@yahoo.it>.
Thanks anyway, I'll try it immediately...

All my best
 
                 Riccardo






      ___________________________________ 
L'email della prossima generazione? Puoi averla con la nuova Yahoo! Mail: http://it.docs.yahoo.com/nowyoucan.html

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts2 - troubles with ParameterAware

Posted by meeboo <de...@gmail.com>.
I think that you'll need to declare the param, something in the likes of...

<action name="actionparam"
class="test.ActionParam">
            <result>/ActionParam.jsp</result>
            {1} <!-- added this -->
            <interceptor-ref name="servlet-config" />
            <interceptor-ref name="params"/>
        </action>

not sure though since I don't have the time to thoroughly look through the
code :p


Riccardo Mollame wrote:
> 
> file set:
> 
> Launch JSP page: TestActionParam.jsp
> Action: ActionParam.java
> Response JSP page: ActionParam.jsp
> Struts config file: struts.xml
> 
> source code:
> 
> ******** TestActionParame.jsp ******
> 
> <%@ taglib prefix="s" uri="/struts-tags" %>
> <html>
>   <head>
>     <meta http-equiv="Content-Type"
> content="text/html; charset=windows-1252"/>
>     <title>TestActionParam</title>
>   </head>
>   <body>
>     <br>
>     <center> actionparam.action?par=YES test </center>  
>   </body>
> </html>
> 
> ******** ActionParam.java ********
> 
> package test;
> 
> import com.opensymphony.xwork2.ActionSupport;
> import java.util.Map;
> import org.apache.struts2.interceptor.ParameterAware;
> 
> public class ActionParam extends ActionSupport
> implements ParameterAware {
>     public static final String MESSAGE = "Test passed:
> ";
>     private String message;
>     private Map parameters;
>     public String execute() throws Exception {
>         String[] par =
> (String[])parameters.get("par");
>         String parVal=((par!=null)?par[0]:"NO");
>         setMessage(MESSAGE + " " + parVal);        
>         return "success";
>     }
>     public void setMessage(String message){
>         this.message = message;
>     }
>     public String getMessage(){
>         return message;
>     }    
>     public void setParameters(Map parameters) {
>      this.parameters=parameters;
>     }
>     public Map getParameters() {
>      return parameters;
>     }
> }
> 
> ********** ActionParam.jsp ***********
> 
> <%@ taglib prefix="s" uri="/struts-tags" %>
> <html>
>   <head>
>     <meta http-equiv="Content-Type"
> content="text/html; charset=windows-1252"/>
>     <title>ActionParam</title>
>   </head>
>   <body>
>   <h2><s:property value="message"/></h2>
>  </body>
> </html>
> 
> *********** struts.xml ***********
> 
> <!DOCTYPE struts PUBLIC
>     "-//Apache Software Foundation//DTD Struts
> Configuration 2.0//EN"
>     "http://struts.apache.org/dtds/struts-2.0.dtd">
> <struts>
>     <package name="default"
> extends="struts-default"></package>
>     <package name="test" extends="struts-default">
>         <action name="actionparam"
> class="test.ActionParam">
>             <result>/ActionParam.jsp</result>
>             <interceptor-ref name="servlet-config" />
>             <interceptor-ref name="params"/>
>         </action>
>     </package>
> </struts>
> 
> **********************
> 
> Result: passed "par" parameter always null ... (though
> it is actually present in the URL)
> 
> ******** WHERE'S THE DAMN PROBLEM?!? ********
> 
> A very discouraged Struts 2 newbie...
> 
> Thanks in advance.
> 
>               Ric
> 
> 
> 
>       ___________________________________ 
> L'email della prossima generazione? Puoi averla con la nuova Yahoo! Mail:
> http://it.docs.yahoo.com/nowyoucan.html
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Struts2---troubles-with-ParameterAware-tf4311574.html#a12274681
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts2 - troubles with ParameterAware

Posted by Zoran Avtarovski <zo...@sparecreative.com>.
Sorry about the late reply, but better ate than never.

All you need to do is have a setPar(String par) method in your action and
it's automagically invoked when extending parameteraware (t may even be
invoked generally, I can't remember).

Z.

> file set:
> 
> Launch JSP page: TestActionParam.jsp
> Action: ActionParam.java
> Response JSP page: ActionParam.jsp
> Struts config file: struts.xml
> 
> source code:
> 
> ******** TestActionParame.jsp ******
> 
> <%@ taglib prefix="s" uri="/struts-tags" %>
> <html>
>   <head>
>     <meta http-equiv="Content-Type"
> content="text/html; charset=windows-1252"/>
>     <title>TestActionParam</title>
>   </head>
>   <body>
>     <br>
>     <center><a
> href='actionparam.action?par=YES'>test</a></center>
>   </body>
> </html>
> 
> ******** ActionParam.java ********
> 
> package test;
> 
> import com.opensymphony.xwork2.ActionSupport;
> import java.util.Map;
> import org.apache.struts2.interceptor.ParameterAware;
> 
> public class ActionParam extends ActionSupport
> implements ParameterAware {
>     public static final String MESSAGE = "Test passed:
> ";
>     private String message;
>     private Map parameters;
>     public String execute() throws Exception {
>         String[] par =
> (String[])parameters.get("par");
>         String parVal=((par!=null)?par[0]:"NO");
>         setMessage(MESSAGE + " " + parVal);
>         return "success";
>     }
>     public void setMessage(String message){
>         this.message = message;
>     }
>     public String getMessage(){
>         return message;
>     }    
>     public void setParameters(Map parameters) {
>      this.parameters=parameters;
>     }
>     public Map getParameters() {
>      return parameters;
>     }
> }
> 
> ********** ActionParam.jsp ***********
> 
> <%@ taglib prefix="s" uri="/struts-tags" %>
> <html>
>   <head>
>     <meta http-equiv="Content-Type"
> content="text/html; charset=windows-1252"/>
>     <title>ActionParam</title>
>   </head>
>   <body>
>   <h2><s:property value="message"/></h2>
>  </body>
> </html>
> 
> *********** struts.xml ***********
> 
> <!DOCTYPE struts PUBLIC
>     "-//Apache Software Foundation//DTD Struts
> Configuration 2.0//EN"
>     "http://struts.apache.org/dtds/struts-2.0.dtd">
> <struts>
>     <package name="default"
> extends="struts-default"></package>
>     <package name="test" extends="struts-default">
>         <action name="actionparam"
> class="test.ActionParam">
>             <result>/ActionParam.jsp</result>
>             <interceptor-ref name="servlet-config" />
>             <interceptor-ref name="params"/>
>         </action>
>     </package>
> </struts>
> 
> **********************
> 
> Result: passed "par" parameter always null ... (though
> it is actually present in the URL)
> 
> ******** WHERE'S THE DAMN PROBLEM?!? ********
> 
> A very discouraged Struts 2 newbie...
> 
> Thanks in advance.
> 
>               Ric
> 
> 
> 
>       ___________________________________
> L'email della prossima generazione? Puoi averla con la nuova Yahoo! Mail:
> http://it.docs.yahoo.com/nowyoucan.html
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts2 - troubles with ParameterAware

Posted by Dave Newton <ne...@yahoo.com>.
--- Riccardo Mollame <rm...@yahoo.it> wrote:
> ******** WHERE'S THE DAMN PROBLEM?!? ********

The "params" interceptor [1] does not do what you
think it does. You are assuming you have implemented
ParameterAware [2, sorta], which is different.

d.

[1]
http://struts.apache.org/2.x/docs/parameters-interceptor.html
[2]
http://struts.apache.org/2.x/docs/how-can-we-access-request-parameters-passed-into-an-action.html


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org