In the next class of actions, I use a parameter hook.
@Namespace("/admin_side") @ResultPath("/WEB-INF/content") @ParentPackage(value = "struts-default") @InterceptorRefs(@InterceptorRef(value="store", params={"operationMode", "AUTOMATIC"})) public final class TestAction extends ActionSupport implements Serializable, ValidationAware, Preparable { private static final long serialVersionUID = 1L; private String param1; private String param2; //Getters and setters. public TestAction() {} @Action(value = "TestMessage", results = { @Result(name=ActionSupport.SUCCESS, type="redirectAction", params={"namespace", "/admin_side", "actionName", "Test"}), @Result(name = ActionSupport.INPUT, location = "Test.jsp")}, interceptorRefs={ @InterceptorRef(value="paramsPrepareParamsStack", params={"params.acceptParamNames", "param1, param2", "params.excludeParams", "extraParam", "validation.validateAnnotatedMethodOnly", "true"}) }) public String insert() { // Do something. Add or update a row to the database (one at a time). addActionMessage("Action message"); addActionError("Error message"); return ActionSupport.SUCCESS; } @Action(value = "Test", results = { @Result(name = ActionSupport.SUCCESS, location = "Test.jsp"), @Result(name = ActionSupport.INPUT, location = "Test.jsp")}, interceptorRefs = { @InterceptorRef(value = "paramsPrepareParamsStack", params = {"params.acceptParamNames", "param1, param2", "params.excludeParams", "extraParam", "validation.validateAnnotatedMethodOnly", "true", "validation.excludeMethods", "load"})}) public String load() throws Exception { // This method is just required to return an initial view on page load. return ActionSupport.SUCCESS; } @Override public void prepare() throws Exception {} }
Below is <s:form> :
<s:form namespace="/admin_side" action="Test" validate="true" id="dataForm" name="dataForm"> <s:if test="hasActionMessages()"> <s:actionmessage theme="jquery"/> </s:if> <s:if test="hasActionErrors()"> <s:actionerror theme="jquery"/> </s:if> <s:hidden name="param1"/> <s:hidden name="param2"/> <s:hidden name="extraParam"/> <s:submit value="Submit" action="TestMessage"/> </s:form>
Here the hidden field of the extraParam form extraParam not declared and therefore does not have a setter and getter in the action class.
In this case, the following message appears on the server terminal:
SEVERE: developer notification (set struts.devMode to false to disable this message): An unexpected exception caught setting "extraParam" to 'class actions.TestAction: error setting expression' extraParam 'with value [' ',]
params.excludeParams does not exclude the extraParam parameter, as in the action class.
Is it possible to somehow prevent such exceptions when using interceptor parameters. Such messages are unnecessarily added to the action messages and are displayed via <s:actionmessage/> if they are used when they should not be displayed at all.
If this paramsPrepareParamsStack replaced with defaultStack in the action class, then such messages are not displayed. He simply warns the following.
A WARNING. The [extraParam] parameter is in the excludeParams list. patterns!
Please do not just say, set struts.devMode to false to disable such messages.