Reputation: 4373
Let me ask a question, maybe simple, but I am a newbie in Struts2.
I have this action method in ProfileAction action:
@Override
public String execute() throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
HttpSession session = request.getSession();
String id = (String) session.getAttribute("id");
if (id != null && !id.equals("") && !id.equals("0")) {
return SUCCESS;
}
return "noSession";
}
And this in the XML:
<action name="perfil" class="agenda.ProfileAction">
<result name="success" type="tiles">/profile.tiles</result>
<result name="noSession" type="tiles">/login.tiles</result>
</action>
<action name="conexion" class="agenda.ProfileAction" method="login">
<interceptor-ref name="jsonValidationWorkflowStack">
<param name="validation.excludeMethods">init,input</param>
</interceptor-ref>
<result name="loginSuccess" type="tiles">/login/success.tiles</result>
<result name="loginError" type="tiles">/login/error.tiles</result>
</action>
As you see, I have "noSession" result in default method, but when I run the page, it throws an exception because "input" result is required. When I replace "noSession" in the XML by "input", it works, but the side effect is that JSON validation does not work.
It seems that execute method is not being called. I have even place a throw exception and in fact, it is not called.
I am traying to call the action this way:
http://www.domain.com:8080/AgendaPlus/perfil
Upvotes: 1
Views: 262
Reputation: 160181
You're almost certainly getting a validation or type conversion error.
When this happens, S2 will attempt to route you to the "input" result to re-fill the form.
Unrelated, but getting values out of the request like this completely negates a lot of the power of S2. Consider working through some tutorials/etc. and use the built-in conveniences.
One easy, human-readable way to look at the interceptor stack is to use the profiling interceptor. This can be configured to be the default, or set up on a per-action basis:
<action name="themes" class="test.ThemesAction">
<interceptor-ref name="profiling">
<param name="profilingKey">profilingKey</param>
</interceptor-ref>
<interceptor-ref name="defaultStack"/>
<result>/WEB-INF/jsps/themes.jsp</result>
</action>
Make the request including a "profilingKey" parameter set to "true" and your logs will show:
2013-04-09 21:22:25,813 INFO : [1959ms] - invoke:
[1959ms] - interceptor: exception
[1959ms] - invoke:
[1959ms] - interceptor: alias
[1959ms] - invoke:
[1959ms] - interceptor: servletConfig
[1957ms] - invoke:
[1957ms] - interceptor: i18n
[1957ms] - invoke:
[1957ms] - interceptor: prepare
[1956ms] - invoke:
[1956ms] - interceptor: chain
[1956ms] - invoke:
[1956ms] - interceptor: debugging
[1956ms] - invoke:
[1956ms] - interceptor: scopedModelDriven
[1956ms] - invoke:
[1956ms] - interceptor: modelDriven
[1956ms] - invoke:
[1956ms] - interceptor: fileUpload
[1956ms] - invoke:
[1956ms] - interceptor: checkbox
[1956ms] - invoke:
[1956ms] - interceptor: multiselect
[1956ms] - invoke:
[1956ms] - interceptor: staticParams
[1955ms] - invoke:
[1955ms] - interceptor: actionMappingParams
[1955ms] - invoke:
[1955ms] - interceptor: params
[1954ms] - invoke:
[1954ms] - interceptor: conversionError
[1954ms] - invoke:
[1954ms] - interceptor: validation
[1897ms] - invoke:
[1897ms] - interceptor: workflow
[1897ms] - invoke:
[7ms] - invokeAction: themes
[1889ms] - executeResult: success
Upvotes: 2