You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Magnus <ma...@snusk.com> on 2004/09/13 15:45:48 UTC
Validator not validating
Hi,
I'm trying to use the Struts validator to validate some input parameters.
The problem is that no matter what I do the parameters are always valid,
I've tried removing newsId from the url, and it's still valid. If it
makes any difference ( which I hope it doesn't ), I want to validate
parameters passed via an url, such as:
/admin/news?method=edit&newsId=1
I've looked at all examples/tutorials I can find but I can't for the
life of me see what's wrong.
My validation.xml looks like:
<form-validation>
<form-set>
<form name="EditNewsForm">
<field
property="newsId"
depends="required,integer">
<arg0
key="typeForm.integer.displayname"/>
<arg1
name="intRange"
key="${var:min}"
resource="false"/>
<arg2
name="intRange"
key="${var:max}"
resource="false"/>
<var>
<var-name>min</var-name>
<var-value>10</var-value>
</var>
<var>
<var-name>max</var-name>
<var-value>20</var-value>
</var>
</field>
</form>
</form-set>
</form-validation>
My ActionMapping looks like:
<action path="/admin/news"
parameter="method"
type="com.snusk.actions.admin.NewsAction"
name="EditNewsForm"
validate="false"
scope="request">
[ some forwards ]
</action>
My ActionForm:
<form-bean
name="EditNewsForm"
type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="newsId"
type="java.lang.Long"/>
</form-bean>
regards,
/Magnus Sjöstrand
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Validator not validating
Posted by Magnus <ma...@snusk.com>.
Sorry, I forgot to include a code snippet from my Action ( /admin/news )
My edit method is:
public ActionForward edit (
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response )
throws Exception
{
ActionErrors errors = form.validate ( mapping, request );
ActionForward forward = null;
if ( errors == null || errors.isEmpty () ){
SnuskService service = getService ();
request.setAttribute ( "current", service.getNewsItem ( 1 ) );
forward = mapping.findForward ( "Edit" );
}else{
forward = list ( mapping, form, request, response );
}
return forward;
}
My intention is that if someone is tampering with the URL, they should
just go back to the news list and have an error displayed. This was the
simplest thing I could think of to start with :)
regards,
/Magnus Sjöstrand
Luis Urueña Frías wrote:
> Hello:
>
> To perform a validation over an action, it's required to enable the
> validation attribute, is'n it?
>
> validate=true like follows
>
> <action path="/admin/news"
> parameter="method"
> type="com.snusk.actions.admin.NewsAction"
> name="EditNewsForm"
> validate="true"
> scope="request">
> [ some forwards ]
> </action>
>
> Regards
>
> Luis Urueña Frías Oficina 101
> Edificio Galileo, módulo Rojo
> Parque Tecnológico de Boecillo
> Valladolid - España
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Validator not validating
Posted by Luis Urueña Frías <lu...@acotelsa.com>.
Hello:
To perform a validation over an action, it's required to enable the
validation attribute, is'n it?
validate=true like follows
<action path="/admin/news"
parameter="method"
type="com.snusk.actions.admin.NewsAction"
name="EditNewsForm"
validate="true"
scope="request">
[ some forwards ]
</action>
Regards
Luis Urueña Frías Oficina 101
Edificio Galileo, módulo Rojo
Parque Tecnológico de Boecillo
Valladolid - España
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org