You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Robin Mannering <ro...@mtndesigns.co.uk> on 2009/06/27 13:11:22 UTC
Struts 2 and Velocity
Hi all
I've recently switched from Struts 1.x to Struts 2.1.6 and would like to
continue using velocity to render the view.
I also wish to take advantage of the Struts 2 tag library by using
velocity directly.
From the documentation at
http://struts.apache.org/2.1.6/docs/velocity-tags.html, I see the format
is:
#s**tag **(...) ... #end
However, I'm having difficult using the tags. The following is ok and
works as expected
#stextfield ("label=Employee Name" "name=empname" "size=15"
"maxlength=10")
However, I would like to display fieldErrors as I need by name. I'm
trying the following which doesn't seem to work.
#sfielderror #sparam ("value=username")
#end
The 'end' tag is not expected on this one
Can anybody point me in the right direction?
Thanks
Robin
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2 and Velocity
Posted by Dave Newton <ne...@yahoo.com>.
Robin Mannering wrote:
> Hi Dave,
>
> It worked ! It seems to be case sensitive. Thanks for your help.
>
> Can you please tell me how you knew to specify 'fieldName' ? I cannot
> find it documented anywhere
In the S2 tag reference [1] on the fielderror tag page [2].
Dave
[1] http://struts.apache.org/2.x/docs/tag-reference.html
[2] http://struts.apache.org/2.x/docs/fielderror.html
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2 and Velocity
Posted by Robin Mannering <ro...@mtndesigns.co.uk>.
Hi Dave,
It worked ! It seems to be case sensitive. Thanks for your help.
Can you please tell me how you knew to specify 'fieldName' ? I cannot
find it documented anywhere
Dave Newton wrote:
> It might be fieldName; case-sensitive.
>
> I'm not very familiar with the Velocity tag support, but it may be
> similar to Freemarker in that some tags are in-line tags, some are
> block tags, and decisions were made at some point to try and cover the
> most common use-case.
>
> If that's the case then you'll probably have to loop over the field
> names of interest.
>
> Dave
>
> Robin Mannering wrote:
>> Thanks for your response.
>>
>> Unfortunately, #sfielderror ("fieldname=username") does not work.
>>
>> All the current field errors are rendered in an unordered list.
>>
>> Using struts2 tags, it would be:
>>
>> <s:fielderror>
>> <s:param>field1</s:param>
>> <s:param>field2</s:param>
>> </s:fielderror>
>>
>> OR
>>
>> <s:fielderror>
>> <s:param value="%{'field1'}" />
>> <s:param value="%{'field2'}" />
>> </s:fielderror>
>>
>> These are two tags nested which I'm having trouble translating into
>> Velocity. Any other ideas?
>>
>> Dave Newton wrote:
>>> Robin Mannering wrote:
>>>> From the documentation at
>>>> http://struts.apache.org/2.1.6/docs/velocity-tags.html, I see the
>>>> format is:
>>>>
>>>> #s**tag **(...) ... #end
>>>>
>>>> However, I'm having difficult using the tags. The following is ok
>>>> and works as expected
>>>>
>>>> #stextfield ("label=Employee Name" "name=empname" "size=15"
>>>> "maxlength=10")
>>>>
>>>> However, I would like to display fieldErrors as I need by name.
>>>> I'm trying the following which doesn't seem to work.
>>>>
>>>> #sfielderror #sparam ("value=username")
>>>> #end
>>>> The 'end' tag is not expected on this one
>>>>
>>>> Can anybody point me in the right direction?
>>>
>>> Does #sfielderror ("fieldname=username") not work, or do you need
>>> multiple fields?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 8.5.375 / Virus Database: 270.12.93/2205 - Release Date: 06/27/09 05:53:00
>
>
Re: Struts 2 and Velocity
Posted by Dave Newton <ne...@yahoo.com>.
It might be fieldName; case-sensitive.
I'm not very familiar with the Velocity tag support, but it may be
similar to Freemarker in that some tags are in-line tags, some are block
tags, and decisions were made at some point to try and cover the most
common use-case.
If that's the case then you'll probably have to loop over the field
names of interest.
Dave
Robin Mannering wrote:
> Thanks for your response.
>
> Unfortunately, #sfielderror ("fieldname=username") does not work.
>
> All the current field errors are rendered in an unordered list.
>
> Using struts2 tags, it would be:
>
> <s:fielderror>
> <s:param>field1</s:param>
> <s:param>field2</s:param>
> </s:fielderror>
>
> OR
>
> <s:fielderror>
> <s:param value="%{'field1'}" />
> <s:param value="%{'field2'}" />
> </s:fielderror>
>
> These are two tags nested which I'm having trouble translating into
> Velocity. Any other ideas?
>
> Dave Newton wrote:
>> Robin Mannering wrote:
>>> From the documentation at
>>> http://struts.apache.org/2.1.6/docs/velocity-tags.html, I see the
>>> format is:
>>>
>>> #s**tag **(...) ... #end
>>>
>>> However, I'm having difficult using the tags. The following is ok
>>> and works as expected
>>>
>>> #stextfield ("label=Employee Name" "name=empname" "size=15"
>>> "maxlength=10")
>>>
>>> However, I would like to display fieldErrors as I need by name. I'm
>>> trying the following which doesn't seem to work.
>>>
>>> #sfielderror #sparam ("value=username")
>>> #end
>>> The 'end' tag is not expected on this one
>>>
>>> Can anybody point me in the right direction?
>>
>> Does #sfielderror ("fieldname=username") not work, or do you need
>> multiple fields?
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2 and Velocity
Posted by Robin Mannering <ro...@mtndesigns.co.uk>.
Thanks for your response.
Unfortunately, #sfielderror ("fieldname=username") does not work.
All the current field errors are rendered in an unordered list.
Using struts2 tags, it would be:
<s:fielderror>
<s:param>field1</s:param>
<s:param>field2</s:param>
</s:fielderror>
OR
<s:fielderror>
<s:param value="%{'field1'}" />
<s:param value="%{'field2'}" />
</s:fielderror>
These are two tags nested which I'm having trouble translating into
Velocity. Any other ideas?
Dave Newton wrote:
> Robin Mannering wrote:
>> From the documentation at
>> http://struts.apache.org/2.1.6/docs/velocity-tags.html, I see the
>> format is:
>>
>> #s**tag **(...) ... #end
>>
>> However, I'm having difficult using the tags. The following is ok
>> and works as expected
>>
>> #stextfield ("label=Employee Name" "name=empname" "size=15"
>> "maxlength=10")
>>
>> However, I would like to display fieldErrors as I need by name. I'm
>> trying the following which doesn't seem to work.
>>
>> #sfielderror #sparam ("value=username")
>> #end
>> The 'end' tag is not expected on this one
>>
>> Can anybody point me in the right direction?
>
> Does #sfielderror ("fieldname=username") not work, or do you need
> multiple fields?
>
> Dave
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 8.5.375 / Virus Database: 270.12.93/2205 - Release Date: 06/27/09 05:53:00
>
>
Re: Struts 2 and Velocity
Posted by Dave Newton <ne...@yahoo.com>.
Robin Mannering wrote:
> From the documentation at
> http://struts.apache.org/2.1.6/docs/velocity-tags.html, I see the format
> is:
>
> #s**tag **(...) ... #end
>
> However, I'm having difficult using the tags. The following is ok and
> works as expected
>
> #stextfield ("label=Employee Name" "name=empname" "size=15"
> "maxlength=10")
>
> However, I would like to display fieldErrors as I need by name. I'm
> trying the following which doesn't seem to work.
>
> #sfielderror #sparam ("value=username")
> #end
> The 'end' tag is not expected on this one
>
> Can anybody point me in the right direction?
Does #sfielderror ("fieldname=username") not work, or do you need
multiple fields?
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org