I think there may be a bug then...

When I try to use a String array in my Java class, I get the following error:

Exception trying to set value with xpath validchecks; Cannot modify property: 
elrsproto.FormBean.validchecks; Cannot convert value of class java.lang.String to type 
class [Ljava.lang.String;; Cannot convert class java.lang.String to class 
[Ljava.lang.String; 

That's why I tried to use just a straight String.  And it works, except that it only 
gets the value of the first check.

Whether I use the nodeset or not, I get the same behaviour.

I did verify that I don't need to use the nodeset if I specify all of the controls 
ahead of time in the form definition.  Thanks.

For now my work-around is to use a javascript array object for the form and then copy 
it into my Java class.  That works.  Odd.


> -----Original Message-----
> From: Giacomo Pati [SMTP:[EMAIL PROTECTED]
> Sent: Thursday, August 21, 2003 3:06 AM
> To:   [EMAIL PROTECTED]
> Subject:      Re: Checkboxes in JXForms - javascript OK, java NOT
> 
> On Wed, 20 Aug 2003, Chris Clark wrote:
> 
> > Based on the samples, I've been looking at checkboxes in JXForms and have a few 
> > questions...
> > Given the following snippet from an xform definition:
> >
> >     <xf:select ref="validchecks" appearance="full">
> >       <xf:label>Check if field is Present &amp; Legible</xf:label>
> >       <xf:itemset nodeset="fieldset">
> >         <xf:label ref="key"/>
> >         <xf:value ref="value"/>
> >       </xf:itemset>
> >     </xf:select>
> >
> > 1) Do you have to use the nodeset?  This is fine if you want multiple
> > checks, but if I just want one checkbox?  I tried a number of things,
> > but none worked.  e.g. an xf:input with a hard-coded type="checkbox".
> > This displayed okay, but the checked/unchecked state wasn't recorded
> > anywhere that I could find.  If you don't need the nodeset, is there a
> > sample and/or docs?
> 
> IIRC no. See below
> 
> > 2) I got the above to work in javascript with the following structure.
> >
> >   var modelObj= {
> >       validchecks: [""],
> >       // define a nodeset (list of all checkboxes in a group)
> >       fieldset: [{key:"Description", value:"desc"},    // key=what to display, 
> > value=what to store in var
> >                  {key:"Name", value:"name"},
> >                  etc...
> >       };
> >   form.setModel(modelObj);
> >   form.sendView("form/form-submit.xml");
> 
> You can do:
> 
>     <xf:select ref="validchecks" appearance="full">
>       <xf:label>Check if field is Present &amp; Legible</xf:label>
>       <xf:item>
>         <xf:label>Description</xf:label
>         <xf:value>desc</xf:value>
>       </xf:item>
>       <xf:item>
>         <xf:label>Name</xf:label
>         <xf:value>name</xf:value>
>       </xf:item>
>       ...
>     </xf:select>
> 
> >
> >
> > When I hit submit, the validchecks is filled out with the value of
> > anything that was checked.
> >
> > 3) Instead of using an object defined in javascript, I wanted to use
> > my own Java Bean (to facilitate access to the form data after submit).
> > The javascript now looks like:
> >
> >   var modelObj = new Packages.elrsproto.FormBean();
> >   form.setModel(modelObj);
> >   form.sendView("form/form-submit.xml");
> >
> > The FormBean looks like this:
> >
> > public class FormBean
> > {
> >     private String validchecks;
> >     private FieldBean[] fieldset = {
> >        new FieldBean("Description", "desc"),
> >        new FieldBean("Name", "name"),
> >        etc...
> >     };
> > ...
> >
> > FieldBean is a helper class that contains two strings named "key" and
> > "value".
> >
> > This displays correctly on screen (i.e. looks the same as the totally
> > javascript version).  The plain edit controls on the form and their
> > String representations in the FormBean (not shown) work fine.
> > However, only the value of the first selected checkbox shows up.  If I
> > check five checkboxes, I only see one value in the "validchecks"> 
> > variable.  When I do this in javascript, I see a comma-delimited list
> > with all of the selected values.
> >
> > Does this fall under the heading of "you aren't supposed to do that,
> > so don't"?  Is this a bug?  Do I just have the syntax wrong?  (I tried
> > a number of things, like making the validchecks an array, but they all
> > threw errors of varying sorts.)
> 
> You have to use a String array for validchecks to get all checked keys.
> This is also used for prepareing all checkboxes for display with values
> in validchecks switched on (have a look at the hobby part in the jxform
> samples).
> 
> --
> Giacomo Pati
> Otego AG, Switzerland - http://www.otego.com
> Orixo, the XML business alliance - http://www.orixo.com
> 

Reply via email to