1

I have an Apache Struts web application. All of my actions are defined in my struts.xml file. I am trying to add support to my action classes to have validation annotations added to my project.

To try and get this working I added the struts2-convention-plugin.jar and also commons-lang.jar.

I then added an annotation on top of my action method.

jsp

<s:form id="tradingOutageFrm" action="addTradingOutageDo.action" 
  validate="true" theme="simple">

struts.xml

<action name="addTradingOutageDo" class="com.myproject.action.TradingOutageAction" 
      method="addDo">
    <result name="success" type="tiles">page.tradingOutageAdd</result>
</action>   

My action class

public class TradingOutageAction extends ActionSupport {

    @RequiredStringValidator(type = ValidatorType.SIMPLE, 
                        fieldName = "storeNo", 
                          message = "Please enter a store.")
    public String addDo() throws Exception {                    
        try{
            Map<String, Object> session = ActionContext.getContext().getSession();      
            String userId = session.get("userid").toString();       

            tradingOutage.setStoreNo(storeNo);
            tradingOutage.setStoreServer(storeServer);

            tradingOutageDAO.insertOutage(userId, startDate, startTime, 
                                          endDate, endTime, tradingOutage); 
            addActionMessage(MessageConstants.RECORD_INSERTED);         
        }catch(Exception e){
            addActionError(MessageConstants.UPDATE_FAILED + " " + e.getMessage());
        }
        return SUCCESS;
    }

Without the annotation everything works fine but with the annotation I get a

No result defined for action com.myproject.action.TradingOutageAction and result input.

Can anyone help me with what might be wrong here.

Shog9
  • 156,901
  • 35
  • 231
  • 235
Richie
  • 4,989
  • 24
  • 90
  • 177
  • 3
    When validation fails it redirects to `INPUT` result and the validation fails as `addTradingOutageDo` doesn't meet the requirements (empty `storeNo` field). You can test validation with adding `?storeNo=ble` to the request – Lukasz Lenart Dec 02 '15 at 08:47
  • @Richie you need to read this: http://stackoverflow.com/questions/23448616/struts2-input-result-how-does-it-work-how-are-conversion-validation-errors-h/23450365#23450365 – Andrea Ligios Dec 02 '15 at 09:04
  • Also note that when Lukasz says *the validation fails*, the real meaning is that *the validation is working* (and making the request fail). And that's why Struts2 tries to return the INPUT result, without finding a mapping. – Andrea Ligios Dec 02 '15 at 09:09
  • thanks you for your help guys. This is the answer to my question. – Richie Dec 03 '15 at 03:04

0 Answers0