Uday Kanth
Uday Kanth

Reputation: 361

How to pass a value to an action in Struts 2 when you don't have a form?

I've written a submit button like this:

<s:submit type="button" value="Delete" action="%{notesDeleteUrl}" theme="simple"/>

And I've defined the url like this.

<s:url value="notesDeleteAction.action" id="notesDeleteUrl" >
<s:param name="noteId"><s:propertyvalue="iNote" />    </s:param>                                   
</s:url>

So basically, I have no < s:form > tag on my JSP but I need to call an action with the submit button while passing a value to it. And I get this error.

So I understand that it's unable to resolve the action because of the added parameter, but how else can I send this value to the action?

Upvotes: 0

Views: 2719

Answers (1)

NickJ
NickJ

Reputation: 9579

Your error is nothing to do with the parameter. Struts doesn't know what to do with the URL /notesDeleteAction

You'll need to include the action in your struts.xml file:

<package name="yourpackage" namespace="/" extends="struts-default">
  <action name="notesDeleteAction" class="foo.YourClass">
    <result>somepage.jsp</result>
  </action>
</package> 

There are 2 ways to get the parameter in your class, foo.YourClass

One way is:

Map parameters = ActionContext.getContext().getParameters();

The other way is for you class to implement org.apache.struts2.interceptor.ParameterAware

Upvotes: 0

Related Questions