cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Giacomo Pati <giac...@apache.org>
Subject Re: Checkboxes in JXForms - javascript OK, java NOT
Date Thu, 21 Aug 2003 07:06:01 GMT
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


Mime
View raw message