Using html:options/ tag with multiple=true

2003-06-28 Thread Eva Murray
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Using html:options/ tag with multiple=true

2003-06-28 Thread Wendy Smoak
Eva wrote:
 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.

I vote for the old type of get and set methods do not match problem:

public String[] getJurisdiction() { return this.jurisdiction; }
public void setJurisdiction(String j[]) { this.jurisdiction = j; }

I would try using setJurisdiction( String[] j) instead.

The Introspection/Reflection process is *very* picky when it comes to
recognizing JavaBeans properties.  Usually it's someone mixing String and
int properties, but I can see how it would be confused by String j[] and
String[] as well.

-- 
Wendy Smoak, Arizona State University
BTW, Lucifer just called and he needs a pair of ice skates :-)
James Turner in struts-dev, voting to release Struts 1.1 Final



Re: Using html:options/ tag with multiple=true

2003-06-28 Thread Eva Murray
Hi Wendy,
Thanks so very much for your reply.  It was in fact a big help, and in the
end, helped me to find the solution.

It turned out that the problem was actually with how I was populating the
form jurisdiction field.
Apparently the s.getJurisdictionF() method was returning an array which had
some null entries, and the null entries in the array caused everything to
choke.

I then re-tested with setJurisdiction(String j[])  versus
setJurisdiction(String [ ]j) and everthing worked just fine either way.
None the less, I'll keep the setJurisdiction(String [] j) to make sure I
don't run into other problems.


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

Thanks again
Eva

- Original Message -
From: Wendy Smoak [EMAIL PROTECTED]
To: 'Struts Users Mailing List' [EMAIL PROTECTED]
Sent: Saturday, June 28, 2003 10:55 AM
Subject: RE: Using html:options/ tag with multiple=true


 Eva wrote:
  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.

 I vote for the old type of get and set methods do not match problem:

 public String[] getJurisdiction() { return this.jurisdiction; }
 public void setJurisdiction(String j[]) { this.jurisdiction = j; }

 I would try using setJurisdiction( String[] j) instead.

 The Introspection/Reflection process is *very* picky when it comes to
 recognizing JavaBeans properties.  Usually it's someone mixing String and
 int properties, but I can see how it would be confused by String j[] and
 String[] as well.

 --
 Wendy Smoak, Arizona State University
 BTW, Lucifer just called and he needs a pair of ice skates :-)
 James Turner in struts-dev, voting to release Struts 1.1 Final





-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]