How to post javascript var to Struts Action inside topic method ?

64 views
Skip to first unread message

camusg

unread,
Sep 2, 2010, 12:07:18 PM9/2/10
to struts2-jquery
Hello everybody,

With my GridTag, I want to select some lines and I want to post them
to my struts action.
I have seen "Get Selected Rows" button in showcase, but I don't know
how I can modify href in javascript...

Here is my test, starting with "grid-multi.jsp" of showcase :
<s:url id="urlEcho" action="echo"/>
<sj:submit id="grid_multi_testbutton" href="%{urlEcho}"
value="Test Guy" onBeforeTopics="testTopic" button="true"/>

I use the Echo Action, with echo attribut containing id list (from
selected lines of my grid)
I want to create an URL like this : echo.action?echo=11,121,456

And my javascript, in "showcase.js" :
$.subscribe('testTopic', function(event, data) {
var s;
s = $("#gridmultitable").jqGrid('getGridParam', 'selarrrow');
// TODO some code for adding var s to href
});

Is anyone has an idea ?

Thanks a lot !

Guillaume.

PS : I saw posts for custom buttons in grid... but I want an external
button for only specific grids, not for all.

jogep

unread,
Sep 2, 2010, 4:04:41 PM9/2/10
to struts2-jquery
I do not try it but I think this should work.

<form id="myform">
<input id="echo" type="hidden" name="echo" value="" />
</form>

<s:url id="urlEcho" action="echo"/>
<sj:submit
id="grid_multi_testbutton"
formIds="myform" href="%{urlEcho}"
value="Test Guy"
onBeforeTopics="testTopic"
button="true"/>

<script>
$.subscribe('testTopic', function(event, data) {
var values = $("#gridmultitable").jqGrid('getGridParam',
'selarrrow');
$('#echo').val( values )
});
</script>

Johannes
---
web: http://www.jgeppert.com
twitter: http://twitter.com/jogep

camusg

unread,
Sep 3, 2010, 6:23:26 AM9/3/10
to struts2-jquery
Thanks for idea !

I tried your code, but I found a problem...
I found that sj:submit does not call onBeforeTopics method inside a
form or with a formIds reference.
When I change onBeforeTopics by onClickTopics, javascript method
called, but at same time as my http request...

Is there a bug here ?

Guillaume.

camusg

unread,
Sep 8, 2010, 11:17:44 AM9/8/10
to struts2-jquery
Finally, i find one solution :

In jsp, I put sj:submit into s:form... but it is not mandatory :
<s:form id="myform" action="echo">
<s:hidden id="hiddenEcho" name="echo"/>
<sj:submit id="grid_multi_testbutton"
value="Test Guy"
onClickTopics="testTopic"
button="true"/>
</s:form>

In javascript, I define the testTopic method :
$.subscribe('testTopic', function(event, data) {
var values = $("#gridmultitable").jqGrid('getGridParam',
'selarrrow');
document.myform.echo.value = values;
document.myform.submit();
});

I tested with onBeforeTopics, but it don't work in this sample.
I tried "$('#hiddenEcho').val(values);" but it don't work...

With that code, i can post selected id to my struts action.

Guillaume.

Yuping Jin

unread,
Sep 8, 2010, 9:43:12 PM9/8/10
to struts2...@googlegroups.com
I think if <sj:submit> can support this natively it would be great. This is a common use.

Best regards,
--
Jin Yuping
jiny...@gmail.com

Yuping Jin

unread,
Sep 8, 2010, 9:54:38 PM9/8/10
to struts2...@googlegroups.com
As well as <sj:a>. It's a so comon use to append parameters dynamically in client side, but the tags seems not changable once generated.
If I miss anything, please do let me know.

Best regards,
--
Jin Yuping
jiny...@gmail.com

Yuping Jin

unread,
Sep 8, 2010, 10:26:16 PM9/8/10
to struts2...@googlegroups.com
A plain onClick event handler can do this well...
Reply all
Reply to author
Forward
0 new messages