• 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 ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Frits Walraven
  • Himai Minh

new to Struts

Ranch Hand
Posts: 40
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I am new to Struts. I need your help.

I need to display a list of values in selected tag. The values are from a Form Bean. I am able to display two other columns correctly, but i am getting confused using the selected field. I am adding the coding part here. Please help me in correcly using the Selected tag.

Action Form class
package code;

import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

public final class LoginForm extends ActionForm {
private String name = null;
private String pwd = null;
private ArrayList coll1 = null;

private String action = "Set";

public void setName(String name) {
System.out.println("form setName " + name);
this.name = name;

public String getName() {
System.out.println("form getName " + name);
return name;

public void setPwd(String pwd) {
System.out.println("form setPwd " + pwd);
this.pwd = pwd;

public String getPwd() {
System.out.println("form getPwd " + this.pwd);
return pwd;

public void setColl(ArrayList coll) {
this.coll1 = coll;

public ArrayList getColl() {
return coll1;

Out Put JSP:
<%@ taglib uri="/WEB-INF/app.tld" prefix="app"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ page import="code.LoginForm"%>
<font color="blue">
<bean:write name="loginForm" property="name"/>
<bean:write name="loginForm" property="pwd"/>
<html:select name="loginForm" property="coll">
<html ptions collection="coll1" property="coll" labelProperty="coll"/>

Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need a property on your form to hold the value of the selected item. Depending on your list, this could be about any type. I would typically use a long but some cases might be a String or other type. Since I don't know what you are getting at with the name "coll" I picked a name that made sense to me. Say the user needs to select a server, then you would add these properties to your form.

private long serverId;
private List serverValuesList;

The JSP code would then look like this. I really like using html:optionsCollection. This is mostly because the names of the properties matches up with the other html tags.

<html:select property="serverId">
<html:optionsCollection property="serverValuesList" value="??" label="??" />

As far as the value and label attributes...that depends on what type the objects you are adding to serverValuesList. If you are using LabelValueBean, then you do not need to specify these attributes (the default for value is "value" and the default for label is "label"). If I was adding more complex objects to the list, then I might have a value setting of "serverId" and a label setting of "serverName".

- Brent
[ March 12, 2008: Message edited by: Brent Sterling ]
Bala Raju Mandala
Ranch Hand
Posts: 40
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your reply Brent.

I am bit confused here the way i can use the Selected tag.

my requirement behind this is based on a user name i entered, we create a list and that list will be selected in select box tag.

So for that i am creating the ArryList in Action class and set the list to form bean. I am facing the problem getting this list to JSP. As i am using the selected tag, i am confused with the values i need to give to selected tag and options tag. Can you explain me what are these tags stand for, from my problem perspective?
I'm all tasted up for a BLT! This tiny ad wants a monte cristo!
the value of filler advertising in 2021
    Bookmark Topic Watch Topic
  • New Topic