user2551629
user2551629

Reputation: 21

How to use a button to pass values to the action instead of href link in Struts 2?

I have a href link, which passes some values to the action class in Struts 2.

<a href='<s:url action='generatePdf' escapeAmp="false">
<s:param name='selectedValue' value='selectedValue' />
<s:param name='fromTransactionDate' value='fromTransactionDate' />
<s:param name='fromDate' value='fromDate' />
</s:url>'>
    <font   style="color: blue;">Generate PDF</font>
</a>

I want to use a button instead of the link. Not able to find the way for that.

Upvotes: -1

Views: 1437

Answers (2)

Roman C
Roman C

Reputation: 1

Try this

<s:url var="myUrl" action='generatePdf' escapeAmp="false">
    <s:param name='selectedValue' value='selectedValue' />
    <s:param name='fromTransactionDate' value='fromTransactionDate' />
    <s:param name='fromDate' value='fromDate' />
</s:url>
<input type="button" style="color: blue;" value="Generate PDF"
       onclick="window.location='<s:property value="%{#myUrl}"/>';">

Upvotes: 2

Stephan
Stephan

Reputation: 18041

The easiest way to do this would be to just use an image instead of text

<a href='<s:url action='generatePdf' escapeAmp="false">
  <s:param name='selectedValue' value='selectedValue' />
  <s:param name='fromTransactionDate' value='fromTransactionDate' />
  <s:param name='fromDate' value='fromDate' />
  </s:url>'>
  <img src="myimage.jpg">
</a> 

If you want the button to have a "buttony" feel to it when you hover over it and when you click on it, you need to go a bit further.

Upvotes: 0

Related Questions