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:labelCheck 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:labelCheck if field is Present amp; Legible/xf:label xf:item xf:labelDescription/xf:label xf:valuedesc/xf:value /xf:item xf:item xf:labelName/xf:label xf:valuename/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
RE: Checkboxes in JXForms - javascript OK, java NOT
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:labelCheck 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:labelCheck if field is Present amp; Legible/xf:label xf:item xf:labelDescription/xf:label xf:valuedesc/xf:value /xf:item xf:item xf:labelName/xf:label xf:valuename/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
Re: Checkboxes in JXForms - javascript OK, java NOT
Why not use xf:itemset in this case instead of jx:forEach? Giacomo Pati wrote: On Thu, 21 Aug 2003, Chris Clark wrote: 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. Ok, let check: We use a Java Bean that has a: private String [] m_roles; which gets initialized with an array from a database and the array size fits the numbers of item we've stored in the database (even a 'm_roles = new String[ 0 ]' works for us). with setter/getter public void setRoless( String [] roles ) { m_roles = roles; } public String [] getRoless( ) { return m_roles; } and the form snipped we use look like: xf:select ref=/roless appearance=full xf:labeli18n:textROLE/i18n:text/xf:label jx:forEach var=role items=${allRoles} xf:item xf:label${role.name}/xf:label xf:value${role.name}/xf:value /xf:item /jx:forEach /xf:select Hope this helps. -- Giacomo Pati Otego AG, Switzerland - http://www.otego.com Orixo, the XML business alliance - http://www.orixo.com
RE: Checkboxes in JXForms - javascript OK, java NOT
I'm using xf:itemset at the moment. Never seen the jx:ForEach before which gets back to one of my original questions: Are there any docs for jxForms yet? If so, where? Regardless of whether I use the itemset or not, I can get my checkboxes to display correctly on the screen. The problem comes when I want to capture the state of the checkboxes. If I define my model in javascript with a var results[] then it works okay. I get back an array of strings. If I define my model in a Java Bean and pass it to the form after instantiating with var model = new Packages.path.class(), then it doesn't work. If the bean defines the results as a String[], then I get the cast exception (previous email). If I define results as a single String, then I get the id of the first checked checkbox, but none of the others. I tried initializing my array of Strings in my java class but it didn't make a difference whether it was or not. Right now I'm going with the slightly kludgy workaround of using a javascript model for the form and then copying it to my Java Bean after submission. -Original Message- From: Christopher Oliver [SMTP:[EMAIL PROTECTED] Sent: Thursday, August 21, 2003 2:21 PM To: [EMAIL PROTECTED] Subject: Re: Checkboxes in JXForms - javascript OK, java NOT Why not use xf:itemset in this case instead of jx:forEach? Giacomo Pati wrote: On Thu, 21 Aug 2003, Chris Clark wrote: 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. Ok, let check: We use a Java Bean that has a: private String [] m_roles; which gets initialized with an array from a database and the array size fits the numbers of item we've stored in the database (even a 'm_roles = new String[ 0 ]' works for us). with setter/getter public void setRoless( String [] roles ) { m_roles = roles; } public String [] getRoless( ) { return m_roles; } and the form snipped we use look like: xf:select ref=/roless appearance=full xf:labeli18n:textROLE/i18n:text/xf:label jx:forEach var=role items=${allRoles} xf:item xf:label${role.name}/xf:label xf:value${role.name}/xf:value /xf:item /jx:forEach /xf:select Hope this helps. -- Giacomo Pati Otego AG, Switzerland - http://www.otego.com Orixo, the XML business alliance - http://www.orixo.com
Checkboxes in JXForms - javascript OK, java NOT
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:labelCheck 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? 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); 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.) Help. Thanks, Chris