You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Adrian Marrero <ad...@gmail.com> on 2007/11/21 00:56:39 UTC

Re: user Digest 20 Nov 2007 22:05:01 -0000 Issue 7714

Hi,

I am having difficulty using struts:
<html:select property="attributes" multiple="true">

Goal:
I would like to be able to select multiple fields from the drop down
box, retrieve them in my servlet, and use them elsewhere.

Problem:
When I retrieve the String [] in my servlet and I view its contained
information; what I have is a String [] of length = 1 and of type
Ljava.lang.String, regardless of how many selections I make in the
drop down box.

Code:

customProperties.jsp
---------------------------------------------
<nested:select name="customData" property="selectedAttributes"
multiple="true" size="5">
 <nested:options name="moduleProps" property="dropDown"
labelName="moduleProps" labelProperty="dropDown"/> </nested:select>
---------------------------------------------


struts-config.xml
---------------------------------------------
<form-property name="selectedAttributes" type="java.lang.String" />
---------------------------------------------

CustomData.java (Bean in use)
---------------------------------------------
private String [] selectedAttributes;

public String [] getSelectedAttributes()
{ return this.selectedAttributes;}

public void setSelectedAttributes(String [] selectedAttributes)
{ this.selectedAttributes = selectedAttributes; }
----------------------------------------------

CustomizeAction.java (Servlet)
----------------------------------------------
CustomData cd = (CustomData)form;
String [] attr = cd.getSelectedAttributes();
out.println("Selected attributes size: " + attr.length);
out.println("Selected attributes data: " + attr[0]);
----------------------------------------------

output
----------------------------------------------
Selected attributes size: 1
Selected attributes data: [Ljava.lang.String;@18170f98
----------------------------------------------

Does anyone have an idea of what I can do to retrieve in the servlet
the values that I selected from the drop down menu on the jsp page?
Any suggestions would be really appreciated. Thank you in advance for
you help.

Adrian

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


Re: user Digest 20 Nov 2007 22:05:01 -0000 Issue 7714

Posted by Dave Newton <ne...@yahoo.com>.
Consider creating a more descriptive subject line.

--- Adrian Marrero <ad...@gmail.com> wrote:
> struts-config.xml
> <form-property name="selectedAttributes"
> type="java.lang.String" />

I thought you wanted an array?

> CustomData cd = (CustomData)form;
> String [] attr = cd.getSelectedAttributes();
> out.println("Selected attributes size: " +
> attr.length);
> out.println("Selected attributes data: " + attr[0]);
> ----------------------------------------------
> 
> output
> ----------------------------------------------
> Selected attributes size: 1
> Selected attributes data:
> [Ljava.lang.String;@18170f98

Ljava.langString *is* an array of String.

d.


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