struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Felipe Fraga <felipefr...@gmail.com>
Subject Re: submitting a form without a submit button ajax-style
Date Wed, 11 Feb 2009 17:51:56 GMT
Hello,

Using Struts 2 built-in dojo, you could just:

function submitForm(namespace, action, formName, targetDivName) {
	var theForm = dojo.byId( formName );
	//remove initial slash
	var theUrl = namespace.substring(1,namespace.length) + "/" + action +
".action";
	dojo.io.bind({
		url: theUrl,
		formNode: theForm,
		load : function(type, data) {  dojo.byId( targetDivName ).innerHTML = data;},
		error: function(type, error){  dojo.byId( targetDivName ).innerHTML
= error.message;  },
		mimeType :"text/html",
		method: "POST"
	});
}

If you suppress the url, the form action is used instead.


Regards,

Felipe Fraga


On Wed, Feb 11, 2009 at 2:55 PM, mitch gorman <mgorman@shadowtv.biz> wrote:
> ulf n wrote:
>> Thanks for all the input on this one!
>>
>> alas the form.submit(), causes a reload of the page :(
>>
>    doh!
>
>    okay, so the issue is, you need the 'targets=""' attribute, but
> unfortunately for you, s:select doesn't have that bad boy.  what i think
> you'll need to do, to get around this is to use listenTopics="/after" on
> the s:div you're trying to update, and change submitForm() to
>
>
> <script type="text/javascript">
>    function submitForm(id) {
>        var form = document.getElementById(id);
>        form.submit();
>        dojo.event.topic.publish('/after');
>    }
> </script>
>
>    i have not tested this, so i'm not certain this will work.  it's
> possible (but unlikely) that the publish might need to occur before the
> form.submit(), so try that, too, if the function shown above doesn't do
> the job.
>
>    if this doesn't work for ya, i got nothin'.  good luck.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message