[castle][JIRA] Created: (MR-448) Make JSONReturnBinderAttribute open for extension

0 views
Skip to first unread message

Victor Kornov (JIRA)

unread,
May 10, 2008, 9:28:20 PM5/10/08
to castle-pro...@googlegroups.com
Make JSONReturnBinderAttribute open for extension
-------------------------------------------------

Key: MR-448
URL: http://support.castleproject.org//browse/MR-448
Project: MonoRail
Issue Type: Patch
Components: Ajax Support
Affects Versions: Future
Reporter: Victor Kornov
Priority: Minor
Attachments: Monorail_JSONReturnBinder_MakeMoreOpen.patch

I'm using jQuery Form plugin to post file uploads "async" (it uses iframes here). My controller action responds with some JSON data. Accorging to http://www.malsup.com/jquery/form/#code-samples (look Files tab) returned server data should look like <textarea>JSON respons goes here</textarea> because it's being put into iframe's innerHtml.

So, I looked at existing JSONReturnBinderAttribute and modified it a bit to be able to use it's logic (inherit and override) and wrap JSON in textarea. Attaching a patch created from ..\Castle\MonoRail\


--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://support.castleproject.org//secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira


Gauthier Segay (JIRA)

unread,
May 11, 2008, 3:08:20 PM5/11/08
to castle-pro...@googlegroups.com
[ http://support.castleproject.org//browse/MR-448?page=comments#action_12718 ]

Gauthier Segay commented on MR-448:
-----------------------------------

Hello Victor.

From your description, I'm unsure to see an exact match with JSON, you want to render HTML or raw text, so IMHO, it doesn't relate anymore to JSONBinder.

I think it will be more accurate to tweak actual JSONBinder to allow extension in derived classes, by making some logic refactoring and render some members virtual.

Also, did you took a look at the IReturnBinder interface and extension hooks for custom implementation (if extending JSONBinder doesn't do it)?

Thanks you for considering theses alternate ways

Gildas

unread,
May 12, 2008, 6:11:04 AM5/12/08
to Castle Project Development List
Hi,

That's something I have done in my projects.

I created a JsonMessage class to be serialized in JSON by a cusom
ReturnBinder.

I use the JQueryValidator I posted some time ago. Btw I will post a
patch soon for it, cause, even if you can specify with the option
"IsAjax" that your form is submited via Ajax, it's not possible yet to
specify the js mehtod to call on success which makes this feature
useless. So I added an option for this and it can now generate the
code for you.

The method specified is then called when your form is submited and
returns successfully with a JsonMessage. I then use this message in a
custom jQuery plugin I called jQuery.feedBack. If someone is
interested, I can post the code for it. (it's basically an hidden Div
with three UL lists in it, one for each type of messages : info,
warnings and errors).

Oh, and I made an integration of the jQuery plugin called Flexigrid
(http://www.webplicity.net/flexigrid/), as a viewcomponent with
support for paging (no sorting yet but that can be quite easy to
implement). For this one, I modified the original plugin to add a
"initialdata" option (to not have a ajax call for data once the page
is loaded the first time) and two other to specify the url of
jQuery.template plugin (http://www.stanlemon.net/projects/jquery-
templates.html) template to populate the rows. I have fun with it but
I'm not really happy with my implementation yet. Maybe I'll just post
the code for you guys to play with and give me some feedbacks :)

Have fun :)

Gildas

On May 11, 9:08 pm, "Gauthier Segay (JIRA)"
<jiranotificat...@castleproject.org> wrote:
> [http://support.castleproject.org//browse/MR-448?page=comments#action_...]
>
> Gauthier Segay commented on MR-448:
> -----------------------------------
>
> Hello Victor.
>
> From your description, I'm unsure to see an exact match with JSON, you want to render HTML or raw text, so IMHO, it doesn't relate anymore to JSONBinder.
>
> I think it will be more accurate to tweak actual JSONBinder to allow extension in derived classes, by making some logic refactoring and render some members virtual.
>
> Also, did you took a look at the IReturnBinder interface and extension hooks for custom implementation (if extending JSONBinder doesn't do it)?
>
> Thanks you for considering theses alternate ways
>
>
>
> > Make JSONReturnBinderAttribute open for extension
> > -------------------------------------------------
>
> > Key: MR-448
> > URL:http://support.castleproject.org//browse/MR-448
> > Project: MonoRail
> > Issue Type: Patch
> > Components: Ajax Support
> > Affects Versions: Future
> > Reporter: Victor Kornov
> > Priority: Minor
> > Attachments: Monorail_JSONReturnBinder_MakeMoreOpen.patch
>
> > I'm using jQuery Form plugin to post file uploads "async" (it uses iframes here). My controller action responds with some JSON data. Accorging tohttp://www.malsup.com/jquery/form/#code-samples(look Files tab) returned server data should look like <textarea>JSON respons goes here</textarea> because it's being put into iframe's innerHtml.

Victor Kornov (JIRA)

unread,
May 12, 2008, 9:56:40 AM5/12/08
to castle-pro...@googlegroups.com
[ http://support.castleproject.org//browse/MR-448?page=comments#action_12721 ]

Victor Kornov commented on MR-448:
----------------------------------

Hi, Gauthier.

I refactored JSONReturnBinderAttribute.Bind into 2 methods and made them virtual, so my UploadJSONReturnBinder looks like:
class UploadJSONReturnBinderAttribute: JSONReturnBinderAttribute {
protected override string GetRawValue(...) {
return "<textarea>" + base.GetRawValue(...) + "</textarea>";
}
}

It's semantics and usage warrant "inherit and override" strategy. Other ways just lead to duplication, i.e. I'm forced to copy-paste JSONReturnBinderAttribute implementation.

hamilton verissimo (JIRA)

unread,
May 24, 2008, 7:19:40 PM5/24/08
to castle-pro...@googlegroups.com
[ http://support.castleproject.org//browse/MR-448?page=all ]

hamilton verissimo resolved MR-448.
-----------------------------------

Resolution: Applied

Applied, thanks

> Make JSONReturnBinderAttribute open for extension
> -------------------------------------------------
>
> Key: MR-448
> URL: http://support.castleproject.org//browse/MR-448
> Project: MonoRail
> Issue Type: Patch
> Components: Ajax Support
> Affects Versions: Future
> Reporter: Victor Kornov

> Assigned To: hamilton verissimo

Reply all
Reply to author
Forward
0 new messages