struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Greg Huber (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (WW-1967) Dynamic Method Invocation, validator with ActionName-aliasName-validation.xml files.
Date Mon, 21 Jan 2013 14:46:12 GMT

    [ https://issues.apache.org/jira/browse/WW-1967?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13558804#comment-13558804
] 

Greg Huber commented on WW-1967:
--------------------------------

For anyone else looking at this,  resolved with Lukasz solution above,  interceptor:

{code:java}
/**
 * Define our own context to support method's names in validation file name If
 * DMI is enabled and method was specified validation file name will be
 * constructed like this: -
 * 
 * <ActionClass>-<actionAlias>!<methodName>-validation.xml
 */
public class DMIAwareValidationInterceptor extends ValidationInterceptor {

	private static final long serialVersionUID = 9007212648956424490L;
	private boolean dmiEnabled = false;

	@Inject(StrutsConstants.STRUTS_ENABLE_DYNAMIC_METHOD_INVOCATION)
	public void setEnableDynamicMethodInvocation(String value) {
		dmiEnabled = Boolean.parseBoolean(value);
	}

	/**
	 * @see com.opensymphony.xwork2.validator.ValidationInterceptor#getValidationContext(com.opensymphony.xwork2.ActionProxy)
	 */
	@Override
	protected String getValidationContext(ActionProxy proxy) {
		if (dmiEnabled && StringUtils.isNotEmpty(proxy.getMethod())) {
			return proxy.getActionName() + "!" + proxy.getMethod();
		}
		return super.getValidationContext(proxy);
	}

}
{code}
                
> Dynamic Method Invocation, validator with ActionName-aliasName-validation.xml files.
> ------------------------------------------------------------------------------------
>
>                 Key: WW-1967
>                 URL: https://issues.apache.org/jira/browse/WW-1967
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions
>    Affects Versions: 2.0.6
>         Environment: Fedora 4, tomcat
>            Reporter: Greg Huber
>            Assignee: Lukasz Lenart
>            Priority: Minor
>             Fix For: 2.3.9
>
>         Attachments: patch_WW-1967.txt, patch_WW-1967_xwork_2.txt
>
>
> Hello,
> I have been trying to get validation working with dynamic method invocation, using ActionName-aliasName-validation.xml
files.
> When the struts.property is set >> struts.enable.DynamicMethodInvocation=true,
  in the DefaultActionMapper the mapping name is changed by removing !submit from the action
eg fieldValidatorsExamples!submit becomes fieldValidatorsExamples.  When the validator tries
to find FieldValidatorsExampleAction-fieldValidatorsExamples!submit-validator.xml it cannot,
as the validator is looking for FieldValidatorsExampleAction-fieldValidatorsExamples-validator.xml.
 But this is now not linked to a method.
> {code:java}
> if (allowDynamicMethodCalls) {
>     // handle "name!method" convention.
>     String name = mapping.getName();
>     int exclamation = name.lastIndexOf("!");
>     if (exclamation != -1) {
>         mapping.setName(name.substring(0, exclamation)); 
>         mapping.setMethod(name.substring(exclamation + 1));
>     }
> }
> {code}
> With struts.enable.DynamicMethodInvocation=false, validator works but method name is
null.
> This line of code is causing the problem mapping.setName(name.substring(0, exclamation));.
 Without this line seems to work but I am no expert!
> eg:
> {code:xml}
> <action name="fieldValidatorsExamples!*" class="org.apache.struts2.showcase.validation.FieldValidatorsExampleAction"
method="{1}" >
>     <result name="input" type="dispatcher">/validation/fieldValidatorsExample.jsp</result>
>     <result type="dispatcher">/validation/successFieldValidatorsExample.jsp</result>
> </action>
> {code}
> {code:html}
> <s:form action="fieldValidatorsExamples!submit" namespace="/validation" method="POST"
theme="xhtml">
>     <s:textfield label="Required Validator Field" name="requiredValidatorField" />
>     <s:textfield label="Required String Validator Field" name="requiredStringValidatorField"
/>
>     <s:textfield label="Integer Validator Field" name="integerValidatorField" />
>     <s:textfield label="Date Validator Field" name="dateValidatorField" />
>     <s:textfield label="Email Validator Field" name="emailValidatorField" />
>     <s:textfield label="URL Validator Field" name="urlValidatorField" />
>     <s:textfield label="String Length Validator Field" name="stringLengthValidatorField"
/>
>     <s:textfield label="Regex Validator Field" name="regexValidatorField"/>
>     <s:textfield label="Field Expression Validator Field" name="fieldExpressionValidatorField"
/>
>     <s:submit label="Submit" />
> </s:form>
> {code}
> Cheers Greg

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message