Anand
Anand

Reputation: 10400

How to use anchors instead of Submit button in Struts2?

I wish to use anchors instead of submit button in a struts tag form. Can I do it ? How should i create it ?

please help

Upvotes: 2

Views: 2758

Answers (3)

Richgski
Richgski

Reputation: 11

I ran into this same issue. My solution was to submit the form data using the jQuery serialize method to append the form data tho the href of the anchor tag.

<s:url var="urlFkey" namespace="%{namespace}" action="GotoAddForeignKeyRecord" escapeAmp="false" >
  <s:param name="target" >disp${fieldName}</s:param>
  <s:param name="fkeyName" value="fkeyName"/>
  <s:param name="fkeyTableName" value="fkeyPrimaryTableName"/>
  <s:param name="recordID" value="recordID"/>
</s:url>
<s:a id="disp%{fieldName}" href="%{urlFkey}" cssClass='nyroModal' onclick="this.href = this.href + '&' + $('#%{dispTablename}saveRecord').serialize();">
   Add New <s:property value="fkeyPrimaryTableNameLabel"/>
</s:a>

Notice how the serialize method is called in the onclick event for the anchor tag. You can find more examples of using Struts with jQuery at my blog here.

Upvotes: 1

Tyler B
Tyler B

Reputation: 358

I'd suggest just doing a javascript:form.submit() inside your anchor tag href

Upvotes: 0

Vinayak Bevinakatti
Vinayak Bevinakatti

Reputation: 40503

For anchor using struts tag use this

<s:url id="url" action="dummyAction">
     <s:param name="parameterName"><s:property value="parameterValue"/></s:param>
</s:url>
<s:a href="%{url}">Click here</s:a>

Upvotes: 0

Related Questions