dcsimg
Struts usage in a JSP to display a list - new to struts
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Bharat_G
Posted On:   Saturday, February 26, 2005 09:37 AM

Hi, I'm new to Struts and am trying to get the hang of it. Here's what I am trying to do. In my action class: Collection b_list = DM.findAllById(); request.setAttribute("fields1", b_list); Here, DM is a java class and the findAllById method returns an ArrayList. Each item in the array list is lets say of the type: abc(String id, String value) with getId() and getValue() implemented in that class. Now in my JSP: I do not have a form bean asssociated with it. Infact, I do not want to submit any data from this. I simply want to show a drop down menu box with all items from the collection. But I presume I need to create a bean using the object I have add   More>>

Hi,
I'm new to Struts and am trying to get the hang of it.

Here's what I am trying to do.

In my action class:

Collection b_list = DM.findAllById();
request.setAttribute("fields1", b_list);

Here, DM is a java class and the findAllById method returns an ArrayList. Each item in the array list is lets say of the type: abc(String id, String value) with getId() and getValue() implemented in that class.

Now in my JSP:

I do not have a form bean asssociated with it. Infact, I do not want to submit any data from this. I simply want to show a drop down menu box with all items from the collection.

But I presume I need to create a bean using the object I have added to the request object.

So, I'm trying to do this: (i dont know if I need property="id" for html:select tag as I dont want to submit anything.

			










OR

			




instead of html:optionsCollections

Is this correct? I cant get it to work. Am I missing something?

I do not want to submit any info from this jsp. My jsp (a popup actually) simply uses a javascript function to update something in the previous JSP.

Also, please note that I am NOT using LabelValueBean and am passing the Collection in the request object and TRYING to create a bean on the fly using the Collection of objects in the JSP.    <<Less

Re: Struts usage in a JSP to display a list - new to struts

Posted By:   Anonymous  
Posted On:   Monday, February 28, 2005 03:32 AM

I was having trouble with html:option, too. I've managed to get it working, but I don't know if there is a better way than this. For my app, I did the following thing:

<%
java.util.ArrayList arr = new java.util.ArrayList();
int i = itime+1;
while(i < 21) {
if(i<10) arr.add(new org.apache.struts.util.LabelValueBean("0" + i + ":00","0" + i + ":00"));
else arr.add(new org.apache.struts.util.LabelValueBean("" + i + ":00","" + i + ":00"));
i++;
}
request.setAttribute("selectData", arr);
%>


After that, I created the html:options tag:





This code works, but I read that you are not using LabelValueBean. If you strictly want to not use that for your ArrayList, I cannot help you, but maybe this helps you to solve the problem. Please report back if you find another way.
About | Sitemap | Contact