#{jsAction} Tag to support the object binding

634 views
Skip to first unread message

Ma Fai (gmail.com)

unread,
Mar 31, 2010, 2:07:22 AM3/31/10
to play-framework
The #{jsAction} tag is work well. If the controller method bind multi
basic object like String, Integer.

But it do not work for the object binding.

Controller
[code]

public static void save(Dummy dummy)

[/code]

View Template
[code]

#{jsAction @Dummies.save(':dummy.name', ':dummy.pwd')/}

[/code]

Then I have to create another method

Controller
[code]
public static void save(String name, String pwd)
Dummy dummy = new Dummy(name, pwd);
[/code]


It's somewhat boring, if the object have a lot of attributes. Any best
practice to handle this case?
I also found that, the id of the '<input type='text' ...' is not
allowed in HTML.
May be that's the reason for jsAction tag limitation.

Guillaume Bort

unread,
Mar 31, 2010, 2:43:20 AM3/31/10
to play-fr...@googlegroups.com
I guess that your save() action is called with a POST Ajax request? If
so you don't have to pass all values into the URL path. You can add
them to the request body.

> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>
>

Ma Fai (gmail.com)

unread,
Mar 31, 2010, 4:18:31 AM3/31/10
to play-framework
Hi Guillaume:

Yes, I use the post method. Nearly same like the play framework
example.
Only the load method change to ajax.post


[code]
var listAction = #{jsAction @list(':search', ':size', ':page') /}
$('#result').load(listAction({search: 'x', size: '10', page: '1'}),
function()

[/code]

Sorry, I can not understand 'add them to the request body' meaning.
May you give me some hints?

Thanks again.

On 3月31日, 下午2时43分, Guillaume Bort <guillaume.b...@gmail.com> wrote:
> I guess that your save() action is called with a POST Ajax request? If
> so you don't have to pass all values into the URL path. You can add
> them to the request body.
>

Guillaume Bort

unread,
Mar 31, 2010, 4:23:25 AM3/31/10
to play-fr...@googlegroups.com
The #jsAction will generate the URL to post the request to (path +
queryString). But a POST request also has a body.

Typically with jQuery you will make the POST call this way:

var postURL = #{jsAction @Dummies.save() /}
$.post(postURL(), { name: "John", time: "2pm" } );

2010/3/31 Ma Fai (gmail.com) <maf...@gmail.com>:

Ma Fai (gmail.com)

unread,
Mar 31, 2010, 5:54:59 AM3/31/10
to play-framework
Thanks. I got your point.

But it raise another issue.

Because, the name of the input has be 'person.name'. I try to use
'person\\.name' or 'person\.name'. Both of them do not work in JQuery.
The normal 'person.name' also caused the javascript error.

$.post(postURL(), { person.name: "John", person.time: "2pm" } );


On 3月31日, 下午4时23分, Guillaume Bort <guillaume.b...@gmail.com> wrote:
> The #jsAction will generate the URL to post the request to (path +
> queryString). But a POST request also has a body.
>
> Typically with jQuery you will make the POST call this way:
>
> var postURL = #{jsAction @Dummies.save() /}
> $.post(postURL(), { name: "John", time: "2pm" } );
>

> 2010/3/31 Ma Fai (gmail.com) <mafa...@gmail.com>:

Nicolas Leroux

unread,
Mar 31, 2010, 5:59:40 AM3/31/10
to play-fr...@googlegroups.com
Try with:

{"person.name":"John", "person.time": "2pm"}

Nicolas

Reply all
Reply to author
Forward
0 new messages