You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Jesse Kuhnert <jk...@gmail.com> on 2007/03/06 06:10:05 UTC

Re: Variable number of rows with JSON - grid component

Looks cool! I wish I had more time to look but I'm busy busy busy...

On 2/23/07, Justin Walsh <ju...@sadalbari.com> wrote:
> Hi,
>
> I've put together a small demo of a grid like html component which makes
> use of a JSON string in a hidden input field (tapestry component) to
> convey state between the client and server.
>
> http://cruise.sadalbari.com:8080/tapestry-prototypes/GridDemo.html
>
> Basically each entry in the grid is an ActionEntry (a javascript class
> which has its java counterpart on the server side).
> ActionEntries contain 3 fields
> 1) A unique id (this is a client assigned unique id)
> 2) An action (either ADD, UPDATE, DELETE or NONE)
> 3) An embedded object - which in this case is a GridEntry object with a
> code and amount
>
> Editing of the html entries fires javascript events which update the
> object model (in the client).  When the user clicks "Save", the object
> model - an array of action entries is converted to a JSON String and
> submitted (using a tapestry form) to the server.
>
> On the server side, I manually convert the JSON string to an object
> graph and then apply the necc. changes (ADDING, UPDATING, DELETING etc)
>
> One big drawback is that because the component is dynamic HTML, I can't
> apply validation (and translation) using the normal tapestry mechanisms.
>  I've hacked around this by including a hidden div containing an
> @TextField component which contains the same attributes (translators,
> validators) that I wish to apply to each of the amount input fields.
>
> <div style="display:none">
>   <input jwcid="amount@TextField" disabled="true" value="ognl:amount"
> id="amount" validators="validators:required"
> translator="translator:number" displayName="amount" />
> </div>
>
> So then on the server side (and this is where it gets ugly) I use this
> component to do translation and validation, catching the validation
> errors and populating a validation delegate.
>
> TextField comp = (TextField)component;
> Object object = comp.getTranslatedFieldSupport().parse(comp, jsonValue
> == JSONObject.NULL ? null : jsonValue.toString());
> comp.getValidatableFieldSupport().validate(comp, null, cycle, object);
>
> I'm a newbie to tapestry and JSON - but am willing to share this
> contribution to anyone that may find it useful.  I'd also like to
> improve on the validation - so if anyone has any suggestions on how do
> this in a more elegant manner let me know.
>
> Thanks
>
> --
> Justin Walsh
> http://www.ewage.co.za
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Jesse Kuhnert
Tapestry/Dojo team member/developer

Open source based consulting work centered around
dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com

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