Try setting a hidden field with the id as a String[] as well.  Then the
two strings[] should come through in the same order (maybe).  Or you
could try using indexed properties and setting a form, rather than a
single value.  

> -----Original Message-----
> From: Kelly Clauson [mailto:[EMAIL PROTECTED] 
> Sent: Saturday, March 29, 2003 7:22 AM
> To: Matt Raible
> Subject: Re: [displaytag-user] Issues with a checkbox decorator (help)
> 
> 
> I'm getting close!
> 
> So, the setter is called with a string array which is good. 
> But, I need some way to associate the items in the array with 
> the elements in the list that created the table. So I'm back 
> to constructing the checkbox to send a value of 
> "on:listIndex". This works except the list index value is 
> only valid for the current page. If a user is on page 2 and 
> clicks the checkbox in the second row on that page, I expect 
> the getListIndex method to return an index value of 11 
> (assuming a pagesize of 10) but it doesn't, it returns an 
> index value of 1, the index of the element on the page. Is 
> this a bug? How else do I associate an element with the 
> string array values passed to the setter of the form bean if 
> not like this?
> 
> Thanks,
> Kelly 
> 
> 
> > [Original Message]
> > From: Matt Raible <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Cc: <[EMAIL PROTECTED]>
> > Date: 3/29/2003 5:22:16 AM
> > Subject: Re: [displaytag-user] Issues with a checkbox 
> decorator (help)
> >
> > Not an indexed value, but a multi-valued attribute.  Just like a
> > <select multiple="true">.  Just use a String array.  Here's 
> how I've 
> > used a String array to set values in an ArrayList on a form.
> >
> >          public void setRoles(String[] roles) {
> >                  this.userRoles = new ArrayList();
> >                  UserRoleForm role = null;
> >                  for (int i=0; i < roles.length; i++) {
> >                          role = new UserRoleForm();
> >                          role.setRoleName(roles[i]);
> >                          this.userRoles.add(role);
> >                  }
> >          }
> >
> >
> > HTH,
> >
> > Matt
> >
> > On Friday, March 28, 2003, at 11:07 PM, Kelly Clauson wrote:
> >
> > > Matt,
> > >
> > > Thanks for the response. Are you saying that the getter and setter
> > > methods
> > > will be called with an index value?
> > > So the setter signature in my example would be: void 
> setVerified(int 
> > > index,
> > > String value) and the setter would be void 
> getVerified(int index) ?
> > >
> > > Also, how do I know the list size to deal with and therefore know 
> > > how
> > > to
> > > size the string array?
> > >
> > > Thanks, I appreciate your help.
> > > Kelly
> > >
> > >> [Original Message]
> > >> From: Matt Raible <[EMAIL PROTECTED]>
> > >> To: <[EMAIL PROTECTED]>
> > >> Date: 3/28/2003 7:30:37 PM
> > >> Subject: RE: [displaytag-user] Issues with a checkbox decorator 
> > >> (help)
> > >>
> > >> I'd try making your form bean have a String[] for the 
> getter/setter 
> > >> of the checkbox's value and then name all the checkboxes 
> with the 
> > >> same name.
> > >>
> > >> HTH,
> > >>
> > >> Matt
> > >>
> > >>> -----Original Message-----
> > >>> From: [EMAIL PROTECTED]
> > >>> [mailto:[EMAIL PROTECTED] On 
> Behalf Of 
> > >>> Kelly Clauson
> > >>> Sent: Friday, March 28, 2003 4:42 PM
> > >>> To: [EMAIL PROTECTED]
> > >>> Subject: [displaytag-user] Issues with a checkbox 
> decorator (help)
> > >>>
> > >>>
> > >>> I am attempting to use a Decorator to put a checkbox in 
> one column 
> > >>> of a table. I am running into a couple of issues, but I 
> don't know 
> > >>> if my approach is correct.
> > >>>
> > >>> My decorator code looks like this:
> > >>>
> > >>> public class CheckboxDecorator extends Decorator {
> > >>>    public CheckboxDecorator() {  super();  }
> > >>>    public String getNullValue() { return null; }
> > >>>
> > >>>    public String getCheckbox() {
> > >>>        MyBean bean = (MyBean) getObject();
> > >>>       StringBuffer s = new StringBuffer();
> > >>>       s.append("<input type=checkbox name=\"verified\" 
> value=\"on:");
> > >>>       s.append(getListIndex());
> > >>>       s.append("\"");
> > >>>       boolean checked = bean.getVerified();
> > >>>       if (checked) {
> > >>>          s.append(" checked=\"true\"");
> > >>>       }
> > >>>       s.append("/>");
> > >>>       return s.toString();
> > >>>    }
> > >>> }
> > >>>
> > >>> Basically, I'm just returning an html formatted string that 
> > >>> contains a checkbox.
> > >>>
> > >>> My (simplified) jsp:
> > >>>
> > >>> <%@ taglib uri="/WEB-INF/display.tld" prefix="display" %> <%@ 
> > >>> taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> 
> <html:form 
> > >>> action="/List" name="ListForm" type="path.to.ListForm"> 
> > >>> <display:table
> > >>>    width="80%"
> > >>>    name="elements"
> > >>>    scope="session"
> > >>>    border="1"
> > >>>    cellpadding="5"
> > >>>    pagesize="8"
> > >>>    export="true"
> > >>>    requestURI="list.do"
> > >>>    decorator="path.to.CheckboxDecorator">
> > >>>
> > >>>    <display:column align="center" property="checkbox"
> > >>> title="Verify"/>
> > >>>    <display:column align="center" property="ID"/>
> > >>>     ...
> > >>> </display:table>
> > >>> <html:submit/>
> > >>> </html:form>
> > >>>
> > >>> And the relevant portion of the form bean:
> > >>>
> > >>> public void setVerified(String aVerified) {
> > >>>       StringTokenizer s = new StringTokenizer(aVerified, ":");
> > >>>       String onoff = s.nextToken();
> > >>>       int index = Integer.parseInt(s.nextToken());
> > >>>       MyBean bean = (MyBean) mElements.get(index);
> > >>>       if (onoff.equals("on")) {
> > >>>          bean.setPublished(true);
> > >>>       }
> > >>>       else {
> > >>>          bean.setPublished(false);
> > >>>       }
> > >>>    }
> > >>>
> > >>>
> > >>> The checkbox column is displaying properly. The main 
> problem I'm 
> > >>> having is that when I hit the submit button, I expect the 
> > >>> setVerified method on the form bean to be called for 
> each box that 
> > >>> is checked. This does not happen. The method is only called for 
> > >>> the first occurrence of a checked box. Why????
> > >>>
> > >>> Another issue is with the Decorator.getListIndex 
> method. I thought 
> > >>> this method would return the current object's index in the 
> > >>> complete list, but it returns the index on the current 
> page. Just 
> > >>> as the getViewIndex method does. Is this a bug or a 
> configuration 
> > >>> issue?
> > >>>
> > >>> Am I completely on the wrong track in trying to get a 
> checkbox in 
> > >>> a column? Has anyone successfully implemented this? I 
> would really 
> > >>> appreciate some help. I've been staring at this for 
> quite a while 
> > >>> now.
> > >>>
> > >>> Thanks,
> > >>>
> > >>> Kelly Clauson
> > >>> [EMAIL PROTECTED]
> > >>>
> > >>>
> > >>>
> > >>>
> > >>>
> > >>> -------------------------------------------------------
> > >>> This SF.net email is sponsored by:
> > >>> The Definitive IT and Networking Event. Be There!
> > >>> NetWorld+Interop Las Vegas 2003 -- Register today!
> > >>> http://ads.sourceforge.net/cgi-bin/redirect.pl?keyn0001en
> > >>> _______________________________________________
> > >>> displaytag-user mailing list 
> [EMAIL PROTECTED]
> > >>> https://lists.sourceforge.net/lists/listinfo/displaytag-user
> > >>>
> > >>
> > >>
> > >>
> > >>
> > >> -------------------------------------------------------
> > >> This SF.net email is sponsored by:
> > >> The Definitive IT and Networking Event. Be There!
> > >> NetWorld+Interop Las Vegas 2003 -- Register today!
> > >> http://ads.sourceforge.net/cgi-bin/redirect.pl?keyn0001en
> > >> _______________________________________________
> > >> displaytag-user mailing list 
> [EMAIL PROTECTED]
> > >> https://lists.sourceforge.net/lists/listinfo/displaytag-user
> > >
> > >
> > >
> > >
> > > -------------------------------------------------------
> > > This SF.net email is sponsored by:
> > > The Definitive IT and Networking Event. Be There!
> > > NetWorld+Interop Las Vegas 2003 -- Register today!
> > > http://ads.sourceforge.net/cgi-bin/redirect.pl?keyn0001en
> > > _______________________________________________
> > > displaytag-user mailing list [EMAIL PROTECTED]
> > > https://lists.sourceforge.net/lists/listinfo/displaytag-user
> 
> 




-------------------------------------------------------
This SF.net email is sponsored by:
The Definitive IT and Networking Event. Be There!
NetWorld+Interop Las Vegas 2003 -- Register today!
http://ads.sourceforge.net/cgi-bin/redirect.pl?keyn0001en
_______________________________________________
displaytag-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/displaytag-user

Reply via email to