You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Nathan Bubna <na...@esha.com> on 2003/04/01 01:25:28 UTC

[veltools] struts+validator error keys Was: commons validator elements

Charles said:
> Hello all you Struts/Velocity users.
> I am using struts with velocity and I have implemented the commons
> validator.
> Works pretty well I must say.  And fast.

glad to hear it.

> Thing is, I am not sure how to
> access the error strings from Velocity.  And nowhere on the validator site
> does it really tell me where these messages go.

did you check the archives for this list?
i'm pretty sure i sent a long example email some time back.

> Are they coming from the request?  session?  So:
> $errors.prefix $error $error.suffix
>
>     Or
> $request.errors.prefix ....

you should be using the ErrorsTool to deal with these.  if you are, then you
should be doing something like:

#foreach( $e in $errors.foobar )
<span class="error">$e</span>
#end

where "foobar" is the name of the field being validated.  if you do not wish
to display field validation errors individually, you can always just do:

#foreach( $e in $errors.all )
<span class="error">$e</span>
#end

> You get the idea.  Where do they come from.

with Struts, it's my understanding that all ActionError instances go in the
ActionErrors object for the request.  when using Validator, then the
ActionError objects associated with a field being validated should be put
into ActionErrors using the fieldname as the key.

Nathan Bubna
nathan@esha.com


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


RE: [veltools] struts+validator error keys Was: commons validator elements

Posted by "Charles N. Harvey III" <ch...@alloy.com>.
Thanks for the help Nathan.  I wasn't actually using the struts tools.
I was only using the View tools.  Now I am using the struts tools.
But...  I cannot see any error messages.  Here is what I have in the
different config files, I was hoping someone could point out where I
have gone wrong.


--- struts-config.xml ---
...
<form-beans>
   <form-bean name="photo"
type="com.alloy.strength.struts.formbeans.PhotoFormBean"/>
</form-beans>
<action-mappings>
    <action path="/photoupload"
            type="com.alloy.strength.struts.actions.PhotoUploadAction"
            name="photo"
            scope="request"
            validate="true"
            input="/photoupload/index.vm">
            <forward name="success" path="/photoupload/thanks/index.vm"/>
            <forward name="failure" path="/photoupload/index.vm"/>
    </action>
</action-mappings>

--- validation.xml ---
...
    <form name="photo">
            <field property="reg_id" depends="required">
                <arg0 key="photo.regid"/>
            </field>
            <field property="thePhoto" depends="required">
                <arg0 key="photo.thePhoto"/>
            </field>
            <field property="caption" depends="required">
                <arg0 key="photo.caption"/>
            </field>
    </form>

--- ApplicationResources ---
...
photo.reg_id = Registration ID
photo.thePhoto = Photo
photo.caption = Caption

--- /photoupload/index.vm ---
...
#foreach( $e in $errors.all )$e#end
<form name="photo"
      action="${request.contextPath}/photoupload.do?userid=${regid}"
      method="post"
      enctype="multipart/form-data">
  <input type="hidden" name="reg_id" value="${regid}" />
  <input type="text" name="caption" size="50" maxsize="200"
value="$!form.getBean().caption" />
  <input type="file" name="thePhoto" value="$!form.getBean().thePhoto" />
  <input type="image" name="submit"
src="${request.contextPath}/photoupload/images/submit.gif" />
</form>


And I have the errors tool loaded in my toolbox.xml file.
I know I am asking a lot here, and this might not even be the place
for it.  But I am very greatful for any help I can get.  I spent all night
on this last night.

Thanks again.


Charlie



-----Original Message-----
From: Nathan Bubna [mailto:nathan@esha.com]
Sent: Monday, March 31, 2003 6:25 PM
To: Velocity Users List
Subject: [veltools] struts+validator error keys Was: commons validator
elements


Charles said:
> Hello all you Struts/Velocity users.
> I am using struts with velocity and I have implemented the commons
> validator.
> Works pretty well I must say.  And fast.

glad to hear it.

> Thing is, I am not sure how to
> access the error strings from Velocity.  And nowhere on the validator site
> does it really tell me where these messages go.

did you check the archives for this list?
i'm pretty sure i sent a long example email some time back.

> Are they coming from the request?  session?  So:
> $errors.prefix $error $error.suffix
>
>     Or
> $request.errors.prefix ....

you should be using the ErrorsTool to deal with these.  if you are, then you
should be doing something like:

#foreach( $e in $errors.foobar )
<span class="error">$e</span>
#end

where "foobar" is the name of the field being validated.  if you do not wish
to display field validation errors individually, you can always just do:

#foreach( $e in $errors.all )
<span class="error">$e</span>
#end

> You get the idea.  Where do they come from.

with Struts, it's my understanding that all ActionError instances go in the
ActionErrors object for the request.  when using Validator, then the
ActionError objects associated with a field being validated should be put
into ActionErrors using the fieldname as the key.

Nathan Bubna
nathan@esha.com


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



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


RE: [veltools] struts+validator error keys Was: commons validator elements

Posted by "Charles N. Harvey III" <ch...@alloy.com>.
Nathan.
Fabulous.  Thanks so much for the tip.  And I will definately keep
a better eye on the log files.  


Charlie


-----Original Message-----
From: Nathan Bubna [mailto:nathan@esha.com]
Sent: Tuesday, April 01, 2003 3:47 PM
To: Velocity Users List
Subject: Re: [veltools] struts+validator error keys Was: commons
validator elements


Charles said:
> Ok.  I have figured out why I am not getting any error messages.
> My toolbox is not loading up.  And I am not getting any crazy errors.
> I am seeing this in my log file:
>
> 2003-04-01 15:39:19  Velocity   [info] No toolbox entry in configuration.
...
> <param-name>toolbox</param-name>
> <param-value>/WEB-INF/toolbox.xml</param-value>
...
> I don't know what else
> I should be doing to get it to startup.  It _used_ to.  Any idea on
> why it would stop working?  There must be something I have done, me
> being such a toolbox.

nope, actually, it was something i did.  :-)
the param-name for the toolbox definition is now
    "org.apache.velocity.toolbox"
this was done to match the updated param-name for velocity.properties.

B.C. was not maintained since we haven't had a release yet, and your
confusion is entirely legitimate since we haven't got good docs out there
yet.  i'm sorry this cost you so much time.  :-(
(but, in defense, it's always a good idea to keep an eye on the logs ;-)

Nathan Bubna
nathan@esha.com


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


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


Re: [veltools] struts+validator error keys Was: commons validator elements

Posted by Nathan Bubna <na...@esha.com>.
Charles said:
> Ok.  I have figured out why I am not getting any error messages.
> My toolbox is not loading up.  And I am not getting any crazy errors.
> I am seeing this in my log file:
>
> 2003-04-01 15:39:19  Velocity   [info] No toolbox entry in configuration.
...
> <param-name>toolbox</param-name>
> <param-value>/WEB-INF/toolbox.xml</param-value>
...
> I don't know what else
> I should be doing to get it to startup.  It _used_ to.  Any idea on
> why it would stop working?  There must be something I have done, me
> being such a toolbox.

nope, actually, it was something i did.  :-)
the param-name for the toolbox definition is now
    "org.apache.velocity.toolbox"
this was done to match the updated param-name for velocity.properties.

B.C. was not maintained since we haven't had a release yet, and your
confusion is entirely legitimate since we haven't got good docs out there
yet.  i'm sorry this cost you so much time.  :-(
(but, in defense, it's always a good idea to keep an eye on the logs ;-)

Nathan Bubna
nathan@esha.com


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


RE: [veltools] struts+validator error keys Was: commons validator elements

Posted by "Charles N. Harvey III" <ch...@alloy.com>.
Ok.  I have figured out why I am not getting any error messages.
My toolbox is not loading up.  And I am not getting any crazy errors.
I am seeing this in my log file:

2003-04-01 15:39:19  Velocity   [info] No toolbox entry in configuration.

That's the only thing that tells me my toolbox isn't working.

Besides this in the web.xml:
<servlet>
	<servlet-name>velocity</servlet-name>

<servlet-class>org.apache.velocity.tools.view.servlet.VelocityViewServlet</s
ervlet-class>
	<init-param>
		<param-name>toolbox</param-name>
		<param-value>/WEB-INF/toolbox.xml</param-value>
	</init-param>
	<load-on-startup>20</load-on-startup>
</servlet>

And putting the toolbox.xml file in WEB-INF I don't know what else
I should be doing to get it to startup.  It _used_ to.  Any idea on
why it would stop working?  There must be something I have done, me
being such a toolbox.


Charlie


-----Original Message-----
From: Nathan Bubna [mailto:nathan@esha.com]
Sent: Monday, March 31, 2003 6:25 PM
To: Velocity Users List
Subject: [veltools] struts+validator error keys Was: commons validator
elements


Charles said:
> Hello all you Struts/Velocity users.
> I am using struts with velocity and I have implemented the commons
> validator.
> Works pretty well I must say.  And fast.

glad to hear it.

> Thing is, I am not sure how to
> access the error strings from Velocity.  And nowhere on the validator site
> does it really tell me where these messages go.

did you check the archives for this list?
i'm pretty sure i sent a long example email some time back.

> Are they coming from the request?  session?  So:
> $errors.prefix $error $error.suffix
>
>     Or
> $request.errors.prefix ....

you should be using the ErrorsTool to deal with these.  if you are, then you
should be doing something like:

#foreach( $e in $errors.foobar )
<span class="error">$e</span>
#end

where "foobar" is the name of the field being validated.  if you do not wish
to display field validation errors individually, you can always just do:

#foreach( $e in $errors.all )
<span class="error">$e</span>
#end

> You get the idea.  Where do they come from.

with Struts, it's my understanding that all ActionError instances go in the
ActionErrors object for the request.  when using Validator, then the
ActionError objects associated with a field being validated should be put
into ActionErrors using the fieldname as the key.

Nathan Bubna
nathan@esha.com


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


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