You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Eva Murray <ev...@murray.name> on 2003/06/28 15:50:50 UTC

Using tag with multiple=true

Can someone tell me what I'm doing wrong?
I have a JSP page with a form that I would like to display.  I want the form
to be prepopulated with the data which I retrieved from the database, and
those
items previously selected by the user highlighted .  I am unable to do this
for
the multi-select drop down lists.

Can you tell me what do I need to do to accomplish that or what is wrong
with what I have done?  I have looked long and hard and have not been able
to
come up with a solution.  I have found examples for single select drop down
lists, but not
for multi-select.

I enter into the browser http://localhost:9080/csd/update.do?id=404
The Update Action is executed which populates all of the form field values
with data pulled from the database.  The insertcsc.jsp page is then
displayed.
This page contains the TestPageForm which is presented with each of the form
fields
prepopulated from the database, except for the MultiSelect Drop Down lists.
The multi
select drop downs have the  data from the collection for initial display,
but the
selected items are not highlighted.

Thanks for any insight.
Eva Murray
=====================================


The JSP Page insertcsc.jsp
<jsp:useBean id="DB" scope="page" class="csd.RetrieveDropDownData" />
<% pageContext.setAttribute("jurisdictionDis",DB.getJurisdictionDropDown());
%>

<html:select property="jurisdiction" size="6" multiple="true"
styleClass="tabbody">
<html:options collection="jurisdictionDis" property="value"
labelProperty="label"/>
</html:select>

The method in the csd.RetrieveDropDownData Java Class which creates the
ArrayList
public ArrayList getJurisdictionDropDown() {
java.util.ArrayList al = new java.util.ArrayList();
try {
Collection col = (Collection) new Vector();
DropDownDAODB drp = new DropDownDAODB();
al.add(new csd.LabelValueBean("Make a Selection(s)",""));
col = drp.listJurisdictions();
Iterator ite = col.iterator();
while (ite.hasNext()) {
String str = (String) ite.next();
  al.add(new csd.LabelValueBean(str,str));
  }
} catch (Exception ex)   {
al.add(new csd.LabelValueBean("",""));
System.err.println("Error getting Planned. " + ex);
}
return al;
}

The TestPageForm Class
public class TestPageForm extends ActionForm {

private String [] jurisdiction = null;
public String[] getJurisdiction() {
return this.jurisdiction;
}
public void setJurisdiction(String j[]) {
this.jurisdiction = j;
}
public void reset(ActionMapping mapping, HttpServletRequest request) {
jurisdiction = null;
}

Struts-config XML
    <form-bean name="testPageForm"
    type="csd.TestPageForm"/>
    <action name="testPageForm" path="/update" scope="request"
type="csd.UpdateAction"
validate="false">
    <forward name="success" path="/insertcsc.jsp">
    </forward>
    </action>

The UpdateAction Class
public ActionForward perform(
TestPageForm testPageForm = (TestPageForm) form;
Service s = (Service) ServiceUtility.getServiceByPk(id);
testPageForm.setJurisdiction(s.getJurisdictionF());
}

The s.getJurisdictionF() is a method in the Service Value Object.  It takes
the string
data from the database and converts it to String[]
  public String[] getJurisdictionF() {
  String [] jurisdiction = new String[5];
  int i = 0;
  String juris;
  StringTokenizer st = new StringTokenizer(_jurisdiction,",");
     while (st.hasMoreTokens()) {
     juris = st.nextToken().trim();
     jurisdiction[i] = juris;
     }
return jurisdiction;
  }




---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org