Hi, I'm a new subscriber to this mailing list, so if this issue has been 
brought up before, I apologize.

I am having trouble retrieving request parameters in my action class, using the 
recommended method described in 
http://struts.apache.org/2.x/docs/how-can-we-access-request-parameters-passed-into-an-action.html.
  The objects contained in the parameter Map appear to be corrupted in some 
way, and cannot be cast to any meaningful class (such as String).

To be more precise, my JSP contains the following code:

    ...
    <s:iterator value="%{#session.folders}" id="folder">
      <s:url id="folderUrl" action="folder" method="display">
        <s:param name="id" value="%{#folder.id}"/>
      </s:url>
      ...
      <s:a href="%{folderUrl}">
        <s:property value="name"/>
      </s:a>
      ...
    </s:iterator>

There is a collection of "Folder" objects stored as a session attribute under 
key "folders".  Each Folder object has a propert called "id" of type Long.  
This code correctly iterates over this collection and prints out the properly 
formulated hyperlink with "id" request parameter, without any problems.

My action class properly implements the ParameterAware interface, and the 
servlet-config interceptor is properly registered to the action, as per the 
instructions linked above.  However, when I attempt to access the request 
parameter using the following action code, I get a ClassCastException:

    String folderId = (String)getParameters().get("id");

I understand that according to documentation found at 
http://struts.apache.org/2.x/docs/param.html, the "param" tag's value might 
evaluate to an Object rather than a String if I use the above tag syntax, so I 
tried changing my JSP code to

    <s:url id="folderUrl" action="folder" method="display">
      <s:param name="id">
        <s:property value="id"/>
      </s:param>
    </s:url>

to force evaluation as a String, but the same problem occurs.  After some 
investigation, I found that no matter how I code the request parameter, if I 
test the resulting Map value for its class type with code such as

    System.err.println(getParameters().get("id").getClass().getName());

I receive the following value:

    [Ljava.lang.String;

Apparently it's like some altered form of String, that cannot be cast to a true 
String without causing a ClassCastException, and cannot have its String value 
printed out with toString() because doing so yields some gibberish like

    [Ljava.lang.String;@898587

rather than the desired value.  However, I am quite sure that the object being 
retrieved does represent the request parameter I attempted to send, because 
using the Eclipse debugger I see a single value in the parameter Map under key 
"id", which contains the value I wanted it to.  I just can't get at that value 
because the object's type is corrupted in the manner explained above.  So, I do 
not know how to properly retrieve the parameter's value in the action class.

I apologize for the length of this email, I just wanted to be sure to include 
all potentially relevant information.  If anyone is familiar with this issue or 
could point me toward some documentation that addresses it, I would greatly 
appreciate it.  Thank you very much for your time.

Jeremy Carver

Reply via email to