No result defined for action after using autocomplete in Struts 2

风流意气都作罢 提交于 2020-01-25 00:20:06

问题


I am getting an error of No result defined for action for result input. It was not coming till the time I used Struts2 autocomplete.

This is my autocomplete code :

<s:form class="form-horizontal" style="margin:0 auto" role="form" theme="simple" action="Reports_open_cases">
 <h4>Open Cases</h4>

  ..some controls here

<div class="form-group">              
<div class="col-xs-12 col-sm-4 col-md-4"></div>
 <div class="col-xs-12 col-sm-4 col-md-4" >
 <s:url id="advURL" action="xyz_action"/>    
<sj:select 
 id="abc"  
 name="abc" selectBoxIcon="true"
 href="%{advURL}" 
 list="list_abc" 
 listValue="name" 
 listKey="Id "  
 autocomplete="true"  
 cssClass="form-control"
/>  
</div>

<div class="col-xs-12 col-sm-12 col-md-12 pull-right" style="text-align:right"><br>
     <div class="modal-footer" style="margin:0px; padding:10px 0px 10px">
             <button class="btn btn-success"  type="submit">Generate</button>
            &nbsp;&nbsp;        
            <button class="btn btn-default"  type="Reset">Reset</button>
      </div>
</div>
</s:form>     

my struts.xml (Action):

<constant name="struts.devMode" value="true" />
<constant name="struts.multipart.maxSize" value="20000000" />      
<package name="login" extends="struts-default,json-default" namespace="/">
    <interceptors>
        <interceptor class="vercelon.actions.LoginInterceptor" name="loginInterceptor">
        </interceptor>    
        <interceptor-stack name="loginStack">
        <interceptor-ref name="loginInterceptor"/>
        <interceptor-ref name="defaultStack"/>
        <interceptor-ref name="fileUpload"><param name="maximumSize">10485760</param>
  </interceptor-ref>
    </interceptor-stack>  

    </interceptors>    

<action name="Reports_open_cases" class="vercelon.actions.Report" 
                                 method="Generate_OpenCases">
    <result name="success">/CMS/Reports_OpenCases.jsp</result>
    <result name="ERROR">/Error.jsp</result> 
    <result name="input">/CMS/Reports_Menu.jsp</result>
</action> 

<action name="xyz_action" class="vercelon.actions.Report" method="loadreports">
        <result name="success" type="json"></result>
    </action>

Other then replacing the dropdown to the autocomplete, I haven't made any other changes. When I add input to my struts.xml it doesn't show this error. But the action defined to my form submit doesn't work either. I don't understand where I need to make changes after adding this autocomplete. Please help.


回答1:


When you call some action from the view layer the interceptors run before the action is executed.

Seems your actions use default stack which include validation and workflow interceptors. First interceptor performs validations on actions that extend ActionSupport, the second check if there were errors the INPUT result is returned.

But if you use some -validation.xml or annotation based validations on action class, so every action that is mapped the method of this class is validated by the interceptors above, unless you have configured these interceptors to exclude a method, or use prefixed based method of validation, or skip validation annotation is applied.

All these cases to avoid running validators for the code that haven't been used by some action and needs to avoid them or reconfigure interceptor stack to run without these interceptors.

In your case the action that returns json result doesn't need validation of fields rather than a term. How to configure and override interceptors configuration of the action see in question: How to get result on same page why input is required?.

The working example that uses Select Box with JSON Result as Autocompleter.
The actions source code used in the example.



来源:https://stackoverflow.com/questions/26360432/no-result-defined-for-action-after-using-autocomplete-in-struts-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!