Laliwala IT Services

Laliwala IT Services
Website Development

Monday, February 21, 2011

How to pass String[] from .java to .jsp, java, jsp, string, service, request.getattribute, final solution, jspportlet.java, testing, liferay testing


Nicolas Mugnier :Hello,





I don't know if i post in the good section...





Could you tell me how can I pass a String[] from my .java to my .jsp ?





I tried to do :





.java










.jsp











but it doesn't work.





I tried with for loop but it doesn't work...





Could you help me ?





Thanks,

Best





Nicolas



Mazhar Anwar :You can set your object in java as request attribute as













and in jsp










HTH,

Regards,

Mazhar






Nicolas Mugnier :Thanks for your answer.





But I think I must be mistaken.

I wrote :





in .java :










and in .jsp :













I've got an exception at red line.





Where am I wrong ? emoticon





Thanks

Best





Nicolas



Mazhar Anwar :It seems correct only. Can you check array length in both, in java as well as jsp. One more option is you can initialize the array length in jsp as





String[] allServiceNames;





if(request.getAttribute("allServiceNames")!= null)


allServiceNames = new String[(String[])request.getAttribute("allServiceNames").length];






Nicolas Mugnier :I checked array length. Array lengths are correct but :










When I check length before getParameterValues it's ok (red line)





However, when i check length after getParameterValues, it crashes : nullpointerexception.








I think there is a problem in my .java, when i'm passing my String[] :










emoticon





Thanks



Nicolas Mugnier :It's working fine.





I post final solution, maybe it will help other developpers :





in .java:










in .jsp:










Thanks Mazhar for your help ;)





Regards



Pankaj Sinha :Hi,





If i want to pass some data from my JSPPortlet.java my to view.jsp what do i need to do???





will this soln work???In which method of .java file do i need to write this code??





Thanx & Regards,





pankaj



Pankaj Sinha :Hello Mazhar,








If i want to pass some data from my java class of portlet(JSPPortlet.java) to my jsp file(view.jsp), what do i nee dto do?? help me in just passing "testing" string???






Babu Janarthanan :Hi Pankaj,





place this code in your java class.





request.setAttribute("testing","testvalue");





in jsp.








String testValue = (String)request.getAttribute("testing");








if(testValue!=null) {

System.out.println(" Test Value.... "+testValue);

}








Thx,

Babu






Mazhar Anwar :Hi Pankaj,





You need to set parameters in doView(RenderRequest request, RenderResponse response) method of JSPPortlet.java,





and if you are using action request then in ProcessAction method of JSPPortlet.java.





HTH,

Mazhar






Pankaj Sinha:Hi Mazahar,





Thanx a lot for ur reply..

I did this, and its working for me,

In .java file

actionResponse.setRenderParameter("test",test);

And in .jsp file

var mytest = <%=renderRequest.getParameter("test") %>



Its working fine..





Thanx

Pankaj






Pankaj Sinha :Hi Mazhar,





This mite not be the correct thread for this question,

but can u plz help me in communication between a flex applicationand a portlet, how they can communicate among themselves???





Thanx,

Pankaj

No comments:

Post a Comment