• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using html:options tags - novice to struts

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

<logic resent parameter="field1">
<bean arameter id="mylist" name="field1"/>
<html:select property="id">
<html ptionsCollection label="id" name="myList" value="value"/>
</html:select>
</logic resent>

OR

<html ptions collection="myList" property="value" labelProperty="id"/>

instead of html ptionsCollections

Is this correct? I cant get it to work. Am I missing something?
 
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is what I've coded which is working for something similar to yours:



And in my Action class's execute method that prepares the collection:



Originally posted by bharat bharat:
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.

<logic :p resent parameter="field1">
<bean :p arameter id="mylist" name="field1"/>
<html:select property="id">
<html ptionsCollection label="id" name="myList" value="value"/>
</html:select>
</logic :p resent>

OR

<html ptions collection="myList" property="value" labelProperty="id"/>

instead of html ptionsCollections

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



[ February 26, 2005: Message edited by: Ken Loh ]
[ February 26, 2005: Message edited by: Ken Loh ]
 
bharat bharat
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thnaks for your reply:

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

Also, cant I simply fdo away with LabelValueBean and pass the Collection in the request object and create a bean on the fly using the Collection of objects in the JSP and use it?
 
Ken Loh
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kindly find my response inline...

Originally posted by bharat bharat:
Thnaks for your reply:

However, I do not want to submit any info from the jsp.


You can of course remove the html:form tag.


Also, cant I simply fdo away with LabelValueBean and pass the Collection in the request object and create a bean on the fly using the Collection of objects in the JSP and use it?



You can use your own bean class as you wish.
 
bharat bharat
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do not have a bean associated with this JSP. So, am I correctly creating a bean on the fly for Struts to use using the tags and theCollection from the request object?
 
Ken Loh
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I understand what you mean correctly, yes.

Why don't you try it out yourself to see if it works ? It's definitey more productive than just waiting for answers that may or may not be concise to what your question means. It shouldn't take more than a few line of codes anyway.

Good luck ! Appreciate if you could post the outcome.

Originally posted by bharat bharat:
I do not have a bean associated with this JSP. So, am I correctly creating a bean on the fly for Struts to use using the tags and theCollection from the request object?


[ February 27, 2005: Message edited by: Ken Loh ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic