Re: Passing complex GET parameters to Mason2
Jonathan Swartz <[email protected]> Wed, 24 Oct 2012 08:59:01 -0700
| Newsgroups | gmane.comp.web.mason.user |
|---|---|
| Message-ID | <[email protected]> |
$.args ($self->args) will return a hashref of arguments passed to a component. It's like %ARGS, except that it's a method call rather than a magic scalar.
On Oct 24, 2012, at 5:18 AM, Kamil Niechajewicz wrote:
> Hello,
>
> We ran into a problem recently – we have quite complex form that is used to edit multiple "rows" of data. This means we have input structure like this:
>
> <input type="text" name="row_1" />
> <input type="text" name="row_2" />
> <input type="text" name="row_n" />
>
> There can be also additional data related to each row so:
> <input type="radio" name="row_1_type" />
> <input type="radio" name="row_1_category" />
>
> With old Mason we could just use %ARGS and process it manually with regexps and create nested array-hash structure:
>
> [0] => { name => …, type => …, category => … },
> [1] => { name => …, type => …, category => … },
> [n] => { name => …, type => …, category => … }
>
> But Mason2 uses Moose constructor and requires parameters to be defined as attributes – its obvious defining every possible number of such row data will be very tedious and ugly:
>
> <%class>
> has 'row_1_name';
> has 'row_1_type';
> has 'row_1_category'
> .
> .
> .
> has 'row_n_name';
> has 'row_n_type';
> has 'row_n_category'
> </%class>
>
> How to solve this problem in a Mason2 way? Some frameworks allow to use naming convention with square brackets that describe nested nature of input data:
>
> <input type="text" name="row[1][name]" />
> <input type="radio" name="row[1][type]" />
>
> etc. but I don't think Mason2 supports this. Would it be possible to create some pre-processing method that would prepare data in such format for passing into Moose constructor, so we could use more advanced Moose attributes for GET data, and just pre-process it before it reaches the actual component? Or is there a better way?
>
> Other way to do this I think is to use class meta methods and just create needed attributes on runtime, this would save a lot of typing, but we still are not flexible, as we need to generate certain number of input rows, and if we receive one more row it will break.
>
> Mason2 is great so far, but sometimes we run into problems when doing more advanced stuff thats not described anywhere. Hope someone can point us in the right direction.
>
> Regards,
> KN
>
>
>
>
> ------------------------------------------------------------------------------
> Everyone hates slow websites. So do we.
> Make your web apps faster with AppDynamics
> Download AppDynamics Lite for free today:
> http://p.sf.net/sfu/appdyn_sfd2d_oct_______________________________________________
> Mason-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/mason-users
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
Mason-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mason-users