0

In my Struts app, I have an action, called Foo.

    <action name="Foo" class="some.path.here.foo">
        <result name="SUCCESS" type="tiles">/foo.tiles</result>
    </action> 

Normally it calls execute(), but I want to call another method called change(). How can I do so?

My Idea was this:

    <form name="Foo" action="Foo" >
        <s:textfield name="Mail" placeholder="Mail" />
        <select name="someselect">
        <s:iterator value="someblabla">
            <option value="<s:property value="somevalue"/>" label="<s:property value="Description"/>"><s:property value="Name"/></option>
        </s:iterator>
        </select>
        <s:submit method="change" value="Go!"></s:submit>
    </form>

But when I want to do this, I get

HTTP Status 404 - No result defined for action some.path.is.here.Foo and result input

Can you help me out here?

Saggex
  • 3,390
  • 3
  • 22
  • 37
  • Are you using any kind of validation? When validation fails, it returns 'input' and there is not corresponding action defined for input. – niyasc Mar 05 '15 at 10:11
  • Have you tried to follow advice given in the error log? – Aleksandr M Mar 05 '15 at 10:12
  • @AleksandrM I do not get anything else, then what I wrote up there. – Saggex Mar 05 '15 at 10:13
  • 1
    Oh, dear. 1) "SUCCESS" must be "success". 2) method="something" in s:submit is DMI, and is deprecated, don't use it. 3) `No result defined for action some.path.is.here.Foo and result input` means something has gone wrong, and an INPUT result is returned, but you've not defined any "input" result in your struts.xml for that action. [Take a look at when and how this can happen](http://stackoverflow.com/a/23450365/1654265). – Andrea Ligios Mar 05 '15 at 10:16
  • @user4559929 What Exactly do you mean with validation? I will post my function in EDIT – Saggex Mar 05 '15 at 10:16
  • *No result defined for action some.path.is.here.Foo and result input* - in other words *add the input result*. And java have **methods** not functions. – Aleksandr M Mar 05 '15 at 10:17
  • @user3383458 Just to verify my guess, try creating a page with some error message and add one more result action. errorpage.html – niyasc Mar 05 '15 at 10:20
  • Check answer section – niyasc Mar 05 '15 at 10:26
  • Unrelated, but there's rarely a great reason to make the option elements manually like that. – Dave Newton Mar 05 '15 at 13:21

3 Answers3

2

execute is the default method in an action. If you want to change it i think you can modify the description of your action with adding the "method" attribute. Like that :

<action name="Foo" class="some.path.here.foo" method="change">
        <result name="SUCCESS" type="tiles">/foo.tiles</result>
</action> 

Hope this help

vincent
  • 1,214
  • 12
  • 22
0

You are getting error because, struts expects 'execute' method unless you specify explicitly. If your action method name is different, you have to specify it explicity using the parameter 'method'.

So your code should be

<action name="Foo" class="some.path.here.foo" method="change">
        <result name="SUCCESS" type="tiles">/foo.tiles</result>
</action> 
niyasc
  • 4,440
  • 1
  • 23
  • 50
0

Struts 2 also supports wildcard methods and dynamic method invocation. DMI is less secure, and not preferred. See the docs here

Michael Peacock
  • 2,011
  • 1
  • 11
  • 14