Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
xavi c o
can't get an array thorugh getAttribute()
February 19, 2009 8:05 AM
Answer

xavi c o

Rank: Junior Member

Posts: 40

Join Date: January 5, 2009

Recent Posts

Hi everybody,

I'm having problems trying to receive an array thorugh getAttribute() method...

The array is set by processAction() this way:

actionRequest.setAttribute("CBSectors", actionRequest.getParameter("checkboxes"));


where "checkboxes" are checkboxes form elements, all with the same name.

The thing is that when I try to receive this array in my jsp by

String arraySectors[] = (String[]) renderRequest.getAttribute("CBSectors");

I get the following console error:

java.lang.ClassCastException: java.lang.String cannot be cast to [Ljava.lang.String;

So I don't know how to receive arrays in jsp correctly...
Any idea, please ??

Thanks in advance!!
Best regards,
Xavi
Manish Kumar Gupta
RE: can't get an array thorugh getAttribute()
February 19, 2009 8:57 AM
Answer

Manish Kumar Gupta

LIFERAY STAFF

Rank: Liferay Master

Posts: 535

Join Date: May 15, 2008

Recent Posts

actionRequest.getParameter return a String and not String[].

You should use actionRequest.getParameterValues().
xavi c o
RE: can't get an array thorugh getAttribute()
February 19, 2009 12:34 PM
Answer

xavi c o

Rank: Junior Member

Posts: 40

Join Date: January 5, 2009

Recent Posts

Hi Manish

Yes, you're right. I just got mistaken when writing the thread. I can perform this in processAction():


String[] MyArray= actionRequest.getParameterValues("MyArray");

for(int i=0; i<MyArray.length;i++){

System.out.println(MyArray);

}


The thing is I need to do the same thing in my jsp... and as I have to send the form data from processAction to the receiver jsp, and there's no a "setParameter" function, I don't know how to do it...

Xavi
Manish Kumar Gupta
RE: can't get an array thorugh getAttribute()
February 19, 2009 5:39 PM
Answer

Manish Kumar Gupta

LIFERAY STAFF

Rank: Liferay Master

Posts: 535

Join Date: May 15, 2008

Recent Posts

In processAction, use actionResponse.setRenderParameter(java.lang.String key, java.lang.String[] values)

in receiving JSP, use renderRequest.getParameterValues(java.lang.String name)
xavi c o
RE: can't get an array thorugh getAttribute()
February 19, 2009 11:38 PM
Answer

xavi c o

Rank: Junior Member

Posts: 40

Join Date: January 5, 2009

Recent Posts

Thank you very much Manish.
It works perfectly well ;-)

Best regards,
Xavi