1

In Struts 2, "input" is returned when a check fails in the validate() method. I then map <result name="input"> in struts.xml for the appropriate page.

I am just wondering how it gets the "input", which is a String when the validate() method itself returns void?

@Override
public void validate() {
    // if checks here
}

I would like to understand this concept.

Roman C
  • 49,761
  • 33
  • 66
  • 176
k_rollo
  • 5,304
  • 16
  • 63
  • 95
  • 1
    You can read the docs for this or [this](http://stackoverflow.com/a/26367502/573032) or [this](http://stackoverflow.com/a/18504177/573032). – Roman C Dec 02 '14 at 18:31
  • Well you need to add field or action errors. The framework runs validate, setting these values into a map, if the map is empty then it runs execute(). You can also take a look a the code (add sources using maven) and then inspect ActionSupport and you can see the action side of the code (not the calling side) but it should be clear enough how that works. You supply functionality which struts2 calls and figures out what to do. Typical framework programming, it follows the Hollywood pattern: You don't call us, we call you. – Quaternion Dec 02 '14 at 19:37
  • 1
    You may find this a good read: [Struts2 INPUT result: how does it work? How are conversion / validation errors handled?](http://stackoverflow.com/a/23450365/1654265) – Andrea Ligios Dec 03 '14 at 08:46

1 Answers1

1

The validate() method itself returns nothing (void). It's invoked by validation interceptor.

But after this interceptor usually is going workflow interceptor. This interceptor is responsible to return INPUT result if the action hasErrors().

Roman C
  • 49,761
  • 33
  • 66
  • 176