struts tag for button call Action

13,316

You can do a form with two hidden parameters, and a submit of type button.

<s:form action="myAction">
<s:hidden name="productId" value="%{productId}" />
<s:hidden name="userId" value="%{userId}" />
<s:submit  value="Click me!" type="button"/>
</s:form>

In my action you declare the properties productId and userId with relative getters and setters.

Share:
13,316
KPS
Author by

KPS

Updated on June 04, 2022

Comments

  • KPS
    KPS almost 2 years

    Just wondering if anyone has ever seen or written a customer tag to call Struts2 Actions.

    What I'm looking for is something like this:-

    <s:button value="Click Me!" action="thisIsMyAction" >
        <s:param name="productId" value="%{productId}" />
        <s:param name="userId" value="%{userId}" />
    </s:button>
    

    So that then in the Action you have

    public String thisIsMyAction() {
    
       String productId = getServletRequest.getParameter("productId");
       String userId= getServletRequest.getParameter("userId");
    
       // Do some stuff here.
    
       return SUCCESS;
    }
    

    Reason being, we don't alays want to use href or images and we're not always submitting a form.

    Cheers in advance