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 16:29:23 UTC

Help with html:select multiple="true"

Hi,

Sorry about reposting this topic and forgetting to put a subject the first time.

Here is my issue.

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.

I have tried using html:select multiple="true" and I continue to
receive an output
that I am not expecting and I do not know what I need to fix to get what I need.

Problem:
When I retrieve the String [] in my servlet and I view its
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.


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

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: Help with html:select multiple="true"

Posted by john feng <jo...@gmail.com>.
Did you use ctrl or shift key and mouse to select multiple elements(less
than 5 in your case), then submit it?

On 11/21/07, Adrian Marrero <ad...@gmail.com> wrote:
>
> Hi,
>
> Sorry about reposting this topic and forgetting to put a subject the first
> time.
>
> Here is my issue.
>
> 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.
>
> I have tried using html:select multiple="true" and I continue to
> receive an output
> that I am not expecting and I do not know what I need to fix to get what I
> need.
>
> Problem:
> When I retrieve the String [] in my servlet and I view its
> 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.
>
>
> customProperties.jsp
> --------------------------------------------------------
> <html:select name="customData" property="selectedAttributes"
> multiple="true" size="5">
> <html:options name="moduleProps" property="dropDown"
> labelName="moduleProps" labelProperty="dropDown"/>
> </html:select>
>
> 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: Help with html:select multiple="true"

Posted by Paul Benedict <pb...@apache.org>.
Something totally goofy is going on in your example. You showed a form
in XML and then a form in Java. You can only do one, not both
together.

Paul

On Nov 26, 2007 12:58 PM, Dave Newton <ne...@yahoo.com> wrote:
> I thought you were defining your form in your XML
> file.
>
> Why won't you dereference it *again* and see what data
> is there?
>
>
> --- amarr003 <ad...@gmail.com> wrote:
>
> >
> > Isn't dereferencing the array equivalent to:
> > attr[0]?
> > If it is then the data I get is not what I expect,
> > it is
> > Ljava.lang.String;@57125f92. Which is the problem
> > that I am having. My form
> > is defined as follows:
> >
> > private String [] selectedAttributes;
> >
> > public String [] getSelectedAttributes()
> > { return this.selectedAttributes;}
> >
> > public void setSelectedAttributes(String []
> > selectedAttributes)
> > { this.selectedAttributes = selectedAttributes; }
> >
> > Is this wrongly defined? What else can I do to
> > retrieve the value that I am
> > expecting and not get the
> > Ljava.lang.String;@57125f92 value?
> >
> >
> > newton.dave wrote:
> > >
> > > I'd assume you've made an error defining your form
> > or
> > > the accessor in the form. If you dereference the
> > array
> > > do you get the data you expect?
> > >
> > > --- amarr003 <ad...@gmail.com> wrote:
> > >
> > >>
> > >> Thank you for responding to me both times.
> > However,
> > >> I have tried both
> > >> declarations and I get the same result.
> > >>
> > >> <form-property name="selectedAttributes"
> > >> type="java.lang.String[]" />
> > >> and
> > >> <form-property name="selectedAttributes"
> > >> type="java.lang.String" />
> > >>
> > >> I know that Ljava.lang.String is an array of
> > >> strings, however, either
> > >> it is being processed wrong, or I do not know how
> > to
> > >> process the data
> > >> correctly. Lets say that the ListBox has
> > elements:
> > >> 1, 2, 3, 4, 5; and
> > >> I select 2, 3, and 4. Given the code that I have
> > >> shown in my previous
> > >> posts I receive the output:
> > >> Ljava.lang.String;@57125f92, instead of
> > >> what I want which I believe should be the value
> > "2",
> > >> since I am
> > >> referencing attr[0]. Hopefully I have described
> > my
> > >> issue better and
> > >> that we can work together to find a solution.
> > Thank
> > >> you and anyone
> > >> else in advance.
> > >>
> > >> Adrian
> > >>
> > >
> >
> > --
> > View this message in context:
> >
> http://www.nabble.com/Help-with-html%3Aselect-multiple%3D%22true%22-tf4850865.html#a13954999
> > 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
> >
> >
>
>
> ---------------------------------------------------------------------
> 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: Help with html:select multiple="true"

Posted by Dave Newton <ne...@yahoo.com>.
I thought you were defining your form in your XML
file.

Why won't you dereference it *again* and see what data
is there?

--- amarr003 <ad...@gmail.com> wrote:

> 
> Isn't dereferencing the array equivalent to:
> attr[0]?
> If it is then the data I get is not what I expect,
> it is
> Ljava.lang.String;@57125f92. Which is the problem
> that I am having. My form
> is defined as follows:
> 
> private String [] selectedAttributes;
> 
> public String [] getSelectedAttributes()
> { return this.selectedAttributes;}
> 
> public void setSelectedAttributes(String []
> selectedAttributes)
> { this.selectedAttributes = selectedAttributes; } 
> 
> Is this wrongly defined? What else can I do to
> retrieve the value that I am
> expecting and not get the
> Ljava.lang.String;@57125f92 value?
> 
> 
> newton.dave wrote:
> > 
> > I'd assume you've made an error defining your form
> or
> > the accessor in the form. If you dereference the
> array
> > do you get the data you expect?
> > 
> > --- amarr003 <ad...@gmail.com> wrote:
> > 
> >> 
> >> Thank you for responding to me both times.
> However,
> >> I have tried both
> >> declarations and I get the same result.
> >> 
> >> <form-property name="selectedAttributes"
> >> type="java.lang.String[]" />
> >> and
> >> <form-property name="selectedAttributes"
> >> type="java.lang.String" />
> >> 
> >> I know that Ljava.lang.String is an array of
> >> strings, however, either
> >> it is being processed wrong, or I do not know how
> to
> >> process the data
> >> correctly. Lets say that the ListBox has
> elements:
> >> 1, 2, 3, 4, 5; and
> >> I select 2, 3, and 4. Given the code that I have
> >> shown in my previous
> >> posts I receive the output: 
> >> Ljava.lang.String;@57125f92, instead of
> >> what I want which I believe should be the value
> "2",
> >> since I am
> >> referencing attr[0]. Hopefully I have described
> my
> >> issue better and
> >> that we can work together to find a solution.
> Thank
> >> you and anyone
> >> else in advance.
> >> 
> >> Adrian
> >> 
> > 
> 
> -- 
> View this message in context:
>
http://www.nabble.com/Help-with-html%3Aselect-multiple%3D%22true%22-tf4850865.html#a13954999
> 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
> 
> 


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


Re: Help with html:select multiple="true"

Posted by amarr003 <ad...@gmail.com>.
Isn't dereferencing the array equivalent to: attr[0]?
If it is then the data I get is not what I expect, it is
Ljava.lang.String;@57125f92. Which is the problem that I am having. My form
is defined as follows:

private String [] selectedAttributes;

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

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

Is this wrongly defined? What else can I do to retrieve the value that I am
expecting and not get the Ljava.lang.String;@57125f92 value?


newton.dave wrote:
> 
> I'd assume you've made an error defining your form or
> the accessor in the form. If you dereference the array
> do you get the data you expect?
> 
> --- amarr003 <ad...@gmail.com> wrote:
> 
>> 
>> Thank you for responding to me both times. However,
>> I have tried both
>> declarations and I get the same result.
>> 
>> <form-property name="selectedAttributes"
>> type="java.lang.String[]" />
>> and
>> <form-property name="selectedAttributes"
>> type="java.lang.String" />
>> 
>> I know that Ljava.lang.String is an array of
>> strings, however, either
>> it is being processed wrong, or I do not know how to
>> process the data
>> correctly. Lets say that the ListBox has elements:
>> 1, 2, 3, 4, 5; and
>> I select 2, 3, and 4. Given the code that I have
>> shown in my previous
>> posts I receive the output: 
>> Ljava.lang.String;@57125f92, instead of
>> what I want which I believe should be the value "2",
>> since I am
>> referencing attr[0]. Hopefully I have described my
>> issue better and
>> that we can work together to find a solution. Thank
>> you and anyone
>> else in advance.
>> 
>> Adrian
>> 
> 

-- 
View this message in context: http://www.nabble.com/Help-with-html%3Aselect-multiple%3D%22true%22-tf4850865.html#a13954999
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: Help with html:select multiple="true"

Posted by Dave Newton <ne...@yahoo.com>.
I'd assume you've made an error defining your form or
the accessor in the form. If you dereference the array
do you get the data you expect?

--- amarr003 <ad...@gmail.com> wrote:

> 
> Thank you for responding to me both times. However,
> I have tried both
> declarations and I get the same result.
> 
> <form-property name="selectedAttributes"
> type="java.lang.String[]" />
> and
> <form-property name="selectedAttributes"
> type="java.lang.String" />
> 
> I know that Ljava.lang.String is an array of
> strings, however, either
> it is being processed wrong, or I do not know how to
> process the data
> correctly. Lets say that the ListBox has elements:
> 1, 2, 3, 4, 5; and
> I select 2, 3, and 4. Given the code that I have
> shown in my previous
> posts I receive the output: 
> Ljava.lang.String;@57125f92, instead of
> what I want which I believe should be the value "2",
> since I am
> referencing attr[0]. Hopefully I have described my
> issue better and
> that we can work together to find a solution. Thank
> you and anyone
> else in advance.
> 
> Adrian
> 
> newton.dave wrote:
> > 
> > Please see my response to your first message.
> > 
> > Ljava.lang.String *is* an array of strings, and it
> > wasn't clear to me why you didn't declare your
> dyna
> > form field to be an array of strings (you had it
> as a
> > single string).
> > 
> > d.
> > 
> > --- Adrian Marrero <ad...@gmail.com>
> wrote:
> > 
> >> Hi,
> >> 
> >> Sorry about reposting this topic and forgetting
> to
> >> put a subject the first time.
> >> 
> >> Here is my issue.
> >> 
> >> 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.
> >> 
> >> I have tried using html:select multiple="true"
> and I
> >> continue to
> >> receive an output
> >> that I am not expecting and I do not know what I
> >> need to fix to get what I need.
> >> 
> >> Problem:
> >> When I retrieve the String [] in my servlet and I
> >> view its
> >> 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.
> >> 
> >> 
> >> customProperties.jsp
> >>
> >
>
--------------------------------------------------------
> >> <html:select name="customData"
> >> property="selectedAttributes"
> >> multiple="true" size="5">
> >>  <html:options name="moduleProps"
> >> property="dropDown"
> >> labelName="moduleProps"
> labelProperty="dropDown"/>
> >> </html:select>
> >> 
> >> 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
> >> 
> >> 
> > 
> > 
> >
>
---------------------------------------------------------------------
> > 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/Help-with-html%3Aselect-multiple%3D%22true%22-tf4850865.html#a13952444
> 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
> 
> 


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


Re: Help with html:select multiple="true"

Posted by amarr003 <ad...@gmail.com>.
Thank you for responding to me both times. However, I have tried both
declarations and I get the same result.

<form-property name="selectedAttributes" type="java.lang.String[]" />
and
<form-property name="selectedAttributes" type="java.lang.String" />

I know that Ljava.lang.String is an array of strings, however, either
it is being processed wrong, or I do not know how to process the data
correctly. Lets say that the ListBox has elements: 1, 2, 3, 4, 5; and
I select 2, 3, and 4. Given the code that I have shown in my previous
posts I receive the output:  Ljava.lang.String;@57125f92, instead of
what I want which I believe should be the value "2", since I am
referencing attr[0]. Hopefully I have described my issue better and
that we can work together to find a solution. Thank you and anyone
else in advance.

Adrian

newton.dave wrote:
> 
> Please see my response to your first message.
> 
> Ljava.lang.String *is* an array of strings, and it
> wasn't clear to me why you didn't declare your dyna
> form field to be an array of strings (you had it as a
> single string).
> 
> d.
> 
> --- Adrian Marrero <ad...@gmail.com> wrote:
> 
>> Hi,
>> 
>> Sorry about reposting this topic and forgetting to
>> put a subject the first time.
>> 
>> Here is my issue.
>> 
>> 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.
>> 
>> I have tried using html:select multiple="true" and I
>> continue to
>> receive an output
>> that I am not expecting and I do not know what I
>> need to fix to get what I need.
>> 
>> Problem:
>> When I retrieve the String [] in my servlet and I
>> view its
>> 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.
>> 
>> 
>> customProperties.jsp
>>
> --------------------------------------------------------
>> <html:select name="customData"
>> property="selectedAttributes"
>> multiple="true" size="5">
>>  <html:options name="moduleProps"
>> property="dropDown"
>> labelName="moduleProps" labelProperty="dropDown"/>
>> </html:select>
>> 
>> 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
>> 
>> 
> 
> 
> ---------------------------------------------------------------------
> 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/Help-with-html%3Aselect-multiple%3D%22true%22-tf4850865.html#a13952444
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: Help with html:select multiple="true"

Posted by Dave Newton <ne...@yahoo.com>.
Please see my response to your first message.

Ljava.lang.String *is* an array of strings, and it
wasn't clear to me why you didn't declare your dyna
form field to be an array of strings (you had it as a
single string).

d.

--- Adrian Marrero <ad...@gmail.com> wrote:

> Hi,
> 
> Sorry about reposting this topic and forgetting to
> put a subject the first time.
> 
> Here is my issue.
> 
> 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.
> 
> I have tried using html:select multiple="true" and I
> continue to
> receive an output
> that I am not expecting and I do not know what I
> need to fix to get what I need.
> 
> Problem:
> When I retrieve the String [] in my servlet and I
> view its
> 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.
> 
> 
> customProperties.jsp
>
--------------------------------------------------------
> <html:select name="customData"
> property="selectedAttributes"
> multiple="true" size="5">
>  <html:options name="moduleProps"
> property="dropDown"
> labelName="moduleProps" labelProperty="dropDown"/>
> </html:select>
> 
> 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
> 
> 


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