You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Lukasz Lenart (JIRA)" <ji...@apache.org> on 2013/01/02 08:36:13 UTC

[jira] [Updated] (WW-2923) Allow validator parameters to be set via OGNL rather than hard coding in XML

     [ https://issues.apache.org/jira/browse/WW-2923?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Lukasz Lenart updated WW-2923:
------------------------------

    Description: 
I have been experimenting with a softer way to perform validations.  I like the idea of externalizing the validations in XML, however, it would be more flexible if the parameters could be "set" using matches from the ValueStack rather than requiring them to be hardcoded in the XML.  I have drilled into the validator creation and believe that the ValidatorConfig.Builder(ValidatorConfig cfg) might be the place to check for ${foo}.  There are many other places in the framework where this string is searched for and its content replaced by using an OGNL search.

In my current use case, I am fetching valid ranges from a database according to user inputs.  These varying integers are what I would like to use as my min and max values.  I realize I could use an expression type validation or just code the validation inside my action.  However, it doesn't seem natural to be forced into an alternative technique with the ValueStack being so central to the framework.  It seems that if the value stack can be used for the validator message "Age must be between ${min} and ${max}" it should also be available for fetching constraints.

{code:xml}
<field name="age">
	<field-validator type="int">
		<param name="min">${minLimit}</param>
		<param name="max">${maxLimit}</param>
		<message>Age must be between ${minLimit} and ${maxLimit}</message>
	</field-validator>
</field>
{code}

Peace,
Scott

  was:
I have been experimenting with a softer way to perform validations.  I like the idea of externalizing the validations in XML, however, it would be more flexible if the parameters could be "set" using matches from the ValueStack rather than requiring them to be hardcoded in the XML.  I have drilled into the validator creation and believe that the ValidatorConfig.Builder(ValidatorConfig cfg) might be the place to check for ${foo}.  There are many other places in the framework where this string is searched for and its content replaced by using an OGNL search.

In my current use case, I am fetching valid ranges from a database according to user inputs.  These varying integers are what I would like to use as my min and max values.  I realize I could use an expression type validation or just code the validation inside my action.  However, it doesn't seem natural to be forced into an alternative technique with the ValueStack being so central to the framework.  It seems that if the value stack can be used for the validator message "Age must be between ${min} and ${max}" it should also be available for fetching constraints.

	<field name="age">
		<field-validator type="int">
			<param name="min">${minLimit}</param>
			<param name="max">${maxLimit}</param>
			<message>Age must be between ${minLimit} and ${maxLimit}</message>
		</field-validator>
	</field>

Peace,
Scott

    
> Allow validator parameters to be set via OGNL rather than hard coding in XML
> ----------------------------------------------------------------------------
>
>                 Key: WW-2923
>                 URL: https://issues.apache.org/jira/browse/WW-2923
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: XML Validators
>    Affects Versions: 2.1.2
>         Environment: Standard
>            Reporter: Scott Stanlick
>            Priority: Minor
>             Fix For: 2.3.9
>
>
> I have been experimenting with a softer way to perform validations.  I like the idea of externalizing the validations in XML, however, it would be more flexible if the parameters could be "set" using matches from the ValueStack rather than requiring them to be hardcoded in the XML.  I have drilled into the validator creation and believe that the ValidatorConfig.Builder(ValidatorConfig cfg) might be the place to check for ${foo}.  There are many other places in the framework where this string is searched for and its content replaced by using an OGNL search.
> In my current use case, I am fetching valid ranges from a database according to user inputs.  These varying integers are what I would like to use as my min and max values.  I realize I could use an expression type validation or just code the validation inside my action.  However, it doesn't seem natural to be forced into an alternative technique with the ValueStack being so central to the framework.  It seems that if the value stack can be used for the validator message "Age must be between ${min} and ${max}" it should also be available for fetching constraints.
> {code:xml}
> <field name="age">
> 	<field-validator type="int">
> 		<param name="min">${minLimit}</param>
> 		<param name="max">${maxLimit}</param>
> 		<message>Age must be between ${minLimit} and ${maxLimit}</message>
> 	</field-validator>
> </field>
> {code}
> Peace,
> Scott

--
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