You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by manub <e....@reply.it> on 2009/05/19 14:59:47 UTC

passing form parameters to a custom validator

Hi all,

I'm trying to write a custom field validator which needs other fields to
validate the field I need to validate. How can I pass field values (and not
static params) to a field validator in the validation xml? I'm using Struts
2.1.6.

Thank you.
-- 
View this message in context: http://www.nabble.com/passing-form-parameters-to-a-custom-validator-tp23615918p23615918.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: passing form parameters to a custom validator

Posted by Lukasz Lenart <lu...@googlemail.com>.
2009/5/21 manub <e....@reply.it>:
> I think that this may work for the expression validator because you are
> supplying an expression.

I've been thinking about <param/> tag, with it you can set any field
in your validator and it can be an OGNL expression.


Regards
-- 
Lukasz
http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: passing form parameters to a custom validator

Posted by manub <e....@reply.it>.
I think that this may work for the expression validator because you are
supplying an expression.

Maybe I need to use an expression too, but I don't know how to evaluate it
within my Java class for Validator.


Lukasz Lenart wrote:
> 
> 2009/5/20 manub <e....@reply.it>:
>> I've written a custom field validator, which needs other field values to
>> validate his field. I need a way to pass that values to that field
>> validator.
> 
> Did you try to use param tag as below?
> 
> <field name="employee.employeeType">
>   <field-validator type="expression" short-circuit="false">
>     ${@pl.org.lenart.ems.model.EmployeeType@.value()
> != 'dd'}
>     error.employee.type.required
>     <message />
>   </field-validator>
> </field>
> 
> 
> 
> Regards
> -- 
> Lukasz
> http://www.lenart.org.pl/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/passing-form-parameters-to-a-custom-validator-tp23615918p23649333.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: passing form parameters to a custom validator

Posted by Lukasz Lenart <lu...@googlemail.com>.
2009/5/20 manub <e....@reply.it>:
> I've written a custom field validator, which needs other field values to
> validate his field. I need a way to pass that values to that field
> validator.

Did you try to use param tag as below?

<field name="employee.employeeType">
  <field-validator type="expression" short-circuit="false">
    <param name="expression">${@pl.org.lenart.ems.model.EmployeeType@.value()
!= 'dd'}</param>
    <param name="messageKey">error.employee.type.required</param>
    <message />
  </field-validator>
</field>



Regards
-- 
Lukasz
http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: passing form parameters to a custom validator

Posted by manub <e....@reply.it>.

Lukasz Lenart wrote:
> 
> Frankly, I don't understand, are you trying to pass data from
> validator xml configuration to action?
> 

I've written a custom field validator, which needs other field values to
validate his field. I need a way to pass that values to that field
validator.

-- 
View this message in context: http://www.nabble.com/passing-form-parameters-to-a-custom-validator-tp23615918p23630526.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: passing form parameters to a custom validator

Posted by Lukasz Lenart <lu...@googlemail.com>.
2009/5/20 manub <e....@reply.it>:
> Yes, I did. But in the action the string takes the value "${field}" and not
> the field value.

Frankly, I don't understand, are you trying to pass data from
validator xml configuration to action?


Regards
-- 
Lukasz
http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: passing form parameters to a custom validator

Posted by manub <e....@reply.it>.
Yes, I did. But in the action the string takes the value "${field}" and not
the field value.


Lukasz Lenart wrote:
> 
> 2009/5/19 manub <e....@reply.it>:
>> I'm trying to write a custom field validator which needs other fields to
>> validate the field I need to validate. How can I pass field values (and
>> not
>> static params) to a field validator in the validation xml? I'm using
>> Struts
>> 2.1.6.
> 
> Did you try ${fieldFromAction} ?
> 
> 
> Regards
> -- 
> Lukasz
> http://www.lenart.org.pl/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/passing-form-parameters-to-a-custom-validator-tp23615918p23630243.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: passing form parameters to a custom validator

Posted by Lukasz Lenart <lu...@googlemail.com>.
2009/5/19 manub <e....@reply.it>:
> I'm trying to write a custom field validator which needs other fields to
> validate the field I need to validate. How can I pass field values (and not
> static params) to a field validator in the validation xml? I'm using Struts
> 2.1.6.

Did you try ${fieldFromAction} ?


Regards
-- 
Lukasz
http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: passing form parameters to a custom validator

Posted by manub <e....@reply.it>.
Did it this way. Passed field names via the  tag, then obtained values inside
the validator class using getFieldValue(fieldName, object).

Thank you for suggestions.


stanlick wrote:
> 
> Rather than pass this, that and the other parameter(s) to your validator,
> why not just retrieve what you need from inside the validator?  You have
> the
> ActionInvocation passed to your doIntercept(...), which contains the
> ValueStack containing your objects.
> 
> Peace,
> Scott
> 
> 
> 
> On Tue, May 19, 2009 at 7:59 AM, manub <e....@reply.it> wrote:
> 
>>
>> Hi all,
>>
>> I'm trying to write a custom field validator which needs other fields to
>> validate the field I need to validate. How can I pass field values (and
>> not
>> static params) to a field validator in the validation xml? I'm using
>> Struts
>> 2.1.6.
>>
>> Thank you.
>> --
>> View this message in context:
>> http://www.nabble.com/passing-form-parameters-to-a-custom-validator-tp23615918p23615918.html
>> Sent from the Struts - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/passing-form-parameters-to-a-custom-validator-tp23615918p23651619.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: passing form parameters to a custom validator

Posted by st...@gmail.com.
Rather than pass this, that and the other parameter(s) to your validator,
why not just retrieve what you need from inside the validator?  You have the
ActionInvocation passed to your doIntercept(...), which contains the
ValueStack containing your objects.

Peace,
Scott



On Tue, May 19, 2009 at 7:59 AM, manub <e....@reply.it> wrote:

>
> Hi all,
>
> I'm trying to write a custom field validator which needs other fields to
> validate the field I need to validate. How can I pass field values (and not
> static params) to a field validator in the validation xml? I'm using Struts
> 2.1.6.
>
> Thank you.
> --
> View this message in context:
> http://www.nabble.com/passing-form-parameters-to-a-custom-validator-tp23615918p23615918.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>