[Seaside] Checkbox and AJAX?

Johan Brichau johan at inceptive.be
Fri Dec 20 21:49:46 UTC 2013


Mariano,

You can combine a script callback with the ajax callback that performs the serialization of the checkbox.
In that script callback, you can generate a script that replaces the contents of the tableContainer (having an id, for example).

	html form: [
		html label:[	
			html checkbox
				value: (self isSelected: anObject);
				onClick: (html jQuery ajax 
					serializeThisWithHidden;
					script: [ :s | s << ((s jQuery id: id) html: self report) ]);
				callback: [ :value | self selectRow: anObject value: value ]]]

What happens is the following:
- The ajax callback first executes the serialization of the checkbox. This is the callback you attached to your checkbox itself
- The script callback of the ajax request generates the response of the ajax callback and thus is executed last
- The generated script gets executed on your client. It replaces the contents of the tableContainer with what 'self report' rendered.

There's quite some gotcha's in the above:
- you can combine multiple callbacks on a single ajax request, but only one 'response' callback can exist, otherwise you need to resort to chaining using the onComplete: method of an ajax request.
- if you would use method temporaries to pass values from one callback block to another, you need to use a value holder object in GemStone [1] (even in 3.1 !)

Replacing only the row is not a problem either. You just need to know which row to replace both server-side and client-side. Generating explicit ids per row is a possibility, but there are more.

cheers
Johan

[1] http://forum.world.st/use-of-method-temporaries-in-callback-blocks-td2340788.html


On 20 Dec 2013, at 22:15, Mariano Martinez Peck <marianopeck at gmail.com> wrote:

> Now, a last question. In my case, I want to re-render the whole table/containter after the ajax because selected rows have a special color (css class)....I know which is the ID of my tableContainer. I also have access to the component I would like to re-render (self report). I tried a few things like this:
> 
> renderCellFormContent: anObject on: html
> 
> 	html form: [
> 		html label:[	
> 			html checkbox
> 				value: (self isSelected: anObject);
> 				onClick: (html jQuery ajax 
> 					serializeThisWithHidden;
> 					html: [ :renderer | self halt. renderer render: self report ]
> 					"onSuccess: ((html jQuery: '#tableContainer') load)");
> 				callback: [ :value | self selectRow: anObject value: value ]]]
> 		
> But none worked. I am still newbie with Ajax stuff so I am probably doing something wrong.
> BTW, if I can only refresh the row, cool, but as far as I know that's not possible (or complex?). So just rendering the table again I think it would be ok (unless I loose scroll position).


More information about the seaside mailing list