You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Mark Lundquist <ml...@wrinkledog.com> on 2005/06/14 21:01:13 UTC

[flow+forms] need help w/ binding booleanfield

Hi, I'm having trouble with a binding on a <booleanfield> widget.  That 
is to say, the binding seems to be working fine, but... I'm doing a 
form.save() to a Flowscript object, and when I try to access the 
property bound to the <booleanfield>, things aren't working right.  I 
think it might have something to do with some kind of Rhino/LiveScript 
object wrapping and unwrapping magic that I don't understand...

I have this in a repeater binding:

	<fb:value id="selected" path="selected">
		<fd:convertor datatype="boolean"/>
	</fb:value>


Then in the flowscript I, do this to set up the display of the form:

         var i = getCatalog().iterator();
         while (i.hasNext()) {
             var item = i.next();
             catalogChoices.push (
				 {
					catalogItem: item,
					selected: new java.lang.Boolean (false)
			 	 }
			  );
         }

         form.load (catalogChoices);


After I display the form, I call form.save() on the same catalogChoices 
object, and then I do this:

         var selections = new HashSet();
         for (i in catalogChoices) {
			var lineItem = catalogChoices[i];
             print (lineItem.selected);	// What's going on here?!?
             if (lineItem.selected) {	// always true?!
                 selections.add (lineItem.catalogItem);
             }
         }
         order.setItems (selections);

If I've checked a few of the boxes, here's what gets printed out, e.g.:

	false
	true
	true
	false
	true

...or whatever.  But... the code in the 'if' statement always runs!

So I'm trying to figure this out, and I added the following code before 
calling showForm():

	for (i in catalogChoices) {
		print (catalogChoices[i].selected.getClass();
	}

Great, it prints 'java.lang.Boolean', as expected.  But then if I add 
the same code after the call to form.save(), I get the exception 
"getClass is not a function"!

I don't get it!  Can anybody explain what's going on?

Thanks a lot,
—mark

Re: [flow+forms] need help w/ binding booleanfield

Posted by Marc Salvetti <ma...@notremanou.net>.
Yesterday i had similar problems, i solved it with this test :

        if(row.getChild("select").getValue().booleanValue()){

Maybe this helps :)

Marc

Mark Lundquist a écrit :

>
>
> On Jun 14, 2005, at 12:17 PM, Mark Lundquist wrote:
>
>
>     Update...
>
>     I instrumented the flowscript code some more, add this after the
>     call to load():
>
>     print (catalogChoices[i].selected == 'true');
>
>     ...and this prints "true" for the checkboxes that are checked. So,
>     it's like it's getting saved as a String by the binding framework!
>
>     Questions:
>     1) Why would it do that, since I'm specifying a boolean convertor
>     in the binding?
>     2) ...and if this is what's going on, how come my call to
>     getClass() throws a flowscript exception instead of returning
>     'java.lang.String'?
>
>     Thanks! :-)
>
>
> OK, another update... :-)
>
> I just figured out that I actually /don't/ want to use a boolean 
> convertor in the binding. This would be for converting from a String 
> on load() and back to a String on save(). (I still don't know why I 
> would get 'getClass is not a function' on a String, but it doesn't 
> really matter now :-).
>
> OK, so... convertor is gone from the binding file. But the test
>
> if (lineItem.selected)
>
> still always evaluates to true, no matter if checkbox was checked or not.
>
> /But/... if I change it to this:
>
> if (lineItem.selected == true)
>
> then it works!
>
> So, I'm all confused because I don't know what object type I am really 
> dealing with here in the flowscript nor the best idiom for coding with 
> it. Any suggestions?
>
> (Also, if I put the getClass() instrumentation back in, now what 
> happens is that as it iterates through the items it prints 
> 'java.lang.Boolean' for unchecked checkboxes until it reaches one that 
> is checked, and then it throws the "getClass is not a function" error).
>
> Some might say that the wrong idiom here is my use of the binding 
> framework to bind to a flowscript object instead of to a "real bean" 
> from my model layer, and that I should be accessing widgets directly 
> for information that is only used in the controller layer. But I 
> wanted to experiment with this style and see how things went, because 
> I think it can make the flowscript code clearer and simpler, 
> especially when dealing with repeaters. Essentially, I'm using a 
> Javascript object as an /ad hoc/, lightweight DTO.
>
> —ml—
>
>

	

	
		
___________________________________________________________________________ 
Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger 
Téléchargez cette version sur http://fr.messenger.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: [flow+forms] need help w/ binding booleanfield

Posted by Mark Lundquist <ml...@wrinkledog.com>.
On Jun 14, 2005, at 12:17 PM, Mark Lundquist wrote:

>
> Update...
>
> I instrumented the flowscript code some more, add this after the call 
> to load():
>
> 	print (catalogChoices[i].selected == 'true');
>
> ...and this prints "true" for the checkboxes that are checked.  So, 
> it's like it's getting saved as a String by the binding framework!
>
> Questions:
> 	1) Why would it do that, since I'm specifying a boolean convertor in 
> the binding?
> 	2) ...and if this is what's going on, how come my call to getClass() 
> throws a flowscript exception instead of returning 'java.lang.String'?
>
> Thanks! :-)

OK, another update... :-)

I just figured out that I actually don't want to use a boolean 
convertor in the binding.  This would be for converting from a String 
on load() and back to a String on save().  (I still don't know why I 
would get 'getClass is not a function' on a String, but it doesn't 
really matter now :-).

OK, so... convertor is gone from the binding file.  But the test

	if (lineItem.selected)

still always evaluates to true, no matter if checkbox was checked or 
not.

But... if I change it to this:

	if (lineItem.selected == true)

then it works!

So, I'm all confused because I don't know what object type I am really 
dealing with here in the flowscript nor the best idiom for coding with 
it.  Any suggestions?

(Also, if I put the getClass() instrumentation back in, now what 
happens is that as it iterates through the items it prints 
'java.lang.Boolean' for unchecked checkboxes until it reaches one that 
is checked, and then it throws the "getClass is not a function" error).

Some might say that the wrong idiom here is my use of the binding 
framework to bind to a flowscript object instead of to a "real bean" 
from my model layer, and that I should be accessing widgets directly 
for information that is only used in the controller layer.  But I 
wanted to experiment with this style and see how things went, because I 
think it can make the flowscript code clearer and simpler, especially 
when dealing with repeaters.  Essentially, I'm using a Javascript 
object as an ad hoc, lightweight DTO.

—ml—


Re: [flow+forms] need help w/ binding booleanfield

Posted by Mark Lundquist <ml...@wrinkledog.com>.
On Jun 14, 2005, at 12:01 PM, Mark Lundquist wrote:

> [..snip..]
>
> After I display the form, I call form.save() on the same 
> catalogChoices object, and then I do this:
>
>         var selections = new HashSet();
>         for (i in catalogChoices) {
> 			var lineItem = catalogChoices[i];
>             print (lineItem.selected);	// What's going on here?!?
>             if (lineItem.selected) {	// always true?!
>                 selections.add (lineItem.catalogItem);
>             }
>         }
>         order.setItems (selections);
>
> If I've checked a few of the boxes, here's what gets printed out, e.g.:
>
> 	false
> 	true
> 	true
> 	false
> 	true
>
> ...or whatever.  But... the code in the 'if' statement always runs!
>
> So I'm trying to figure this out, and I added the following code 
> before calling showForm():
>
> 	for (i in catalogChoices) {
> 		print (catalogChoices[i].selected.getClass();
> 	}
>
> Great, it prints 'java.lang.Boolean', as expected.  But then if I add 
> the same code after the call to form.save(), I get the exception 
> "getClass is not a function"!

Update...

I instrumented the flowscript code some more, add this after the call 
to load():

	print (catalogChoices[i].selected == 'true');

...and this prints "true" for the checkboxes that are checked.  So, 
it's like it's getting saved as a String by the binding framework!

Questions:
	1) Why would it do that, since I'm specifying a boolean convertor in 
the binding?
	2) ...and if this is what's going on, how come my call to getClass() 
throws a flowscript exception instead of returning 'java.lang.String'?

Thanks! :-)
—ml—


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org