简体   繁体   中英

Struts2 jQuery plugin - submit button

I have Struts 2 jQuery plugin submit button, when click the button its not firing the action class as Struts submit button. I need to keep the same page after click the button.Please look into below code difference.

Struts submit button - Working good:

<s:form action="product!list" id="searchForm" theme="simple" method="Post">
     <s:submit action="product" method="list" value="Find" />
</s:form>

Converting Struts submit to Struts-jQuery submit submit button - Not Working good:

<s:form action="product!list" id="searchForm" theme="simple" method="Post" >     
     <sj:submit />
</s:form>

if using only form action <sj:submit/> , the page the refreshing and working as Struts tag, but it should not be.

In order <sj:submit> to work properly targets attribute must be set to some value and form must have id attribute.

<s:form action="product!list" id="searchForm">     
  <sj:submit targets="results"/>
</s:form>

You should include <sj:head/> tag in the body of the <head> . This tag links JQuery and stylesheet on the page and other initial things, without it Ajax call has not made and as a result page refreshes. See examples of submitting tag SubmitTag :

 <%@ taglib prefix="s" uri="/struts-tags"%> <%@ taglib prefix="sj" uri="/struts-jquery-tags"%> <html> <head> <sj:head/> </head> <body> <s:form id="form" action="AjaxTest"> <input type="textbox" name="data"> <sj:submit value="Submit Form" /> </s:form> </body> </html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM