You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "David C. Hicks" <dh...@i-hicks.org> on 2008/10/15 22:53:15 UTC
Validation Help?
I'm sure I've just got some little something not set up right or out of
place, but I can't seem to get validation working.
I have a class com.allureglobal.harvey.controller.CustomerController
that extends ActionSupport. There is a corresponding
CustomerController-validation.xml file located in the same package.
Validation is on my interceptor stack. The JSP's that work in
conjunction with the CustomerController all work, but no validation
occurs. I'm not sure what to look for at this point. Anyone got any clues?
Thanks,
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Validation Help?
Posted by "David C. Hicks" <dh...@i-hicks.org>.
Oh geez. All of the indentation got waxed when I sent this. Sorry about
that. It looked a lot neater when I composed it.
David C. Hicks wrote:
> We are not overriding the validate() method of ActionSupport. I
> double-checked to be sure of that.
>
> CustomerController (is an extension of a couple of base classes but
> eventually extends ActionSupport):
> public class CustomerController extends
> AbstractCrudController<Customer> {
> private static final long serialVersionUID = 1L;
>
> public CustomerController(GenericDao<Customer, Long> dao) {
> super(Customer.class, dao);
> }
>
> public List<Customer> getCustomers() {
> return getPersistentEntityList();
> }
>
> public Customer getCustomer() {
> return getPersistentEntity();
> }
>
> public void setCustomer(Customer customer) {
> setPersistentEntity(customer);
> }
>
> @Override
> protected void performPreCreateOperations() {
> }
>
> @Override
> protected boolean performPreAddOperations() {
> return true;
> }
>
> @Override
> protected void performPreUpdateOperations() {
> }
>
> @Override
> protected void performPrepareOperations() {
> }
>
> @Override
> protected Privilege crudPrivilege() {
> return Privilege.CRUD_CUSTOMER;
> }
> }
>
> Customer action configuration:
> <struts>
> <package name="customer" namespace="/customer" extends="harvey">
> <action name="list" method="list" class="customerController">
> <result name="success" type="tiles">customer.list</result>
> </action>
> <action name="view" method="view" class="customerController">
> <result name="success" type="tiles">customer.view</result>
> </action>
> <action name="create" method="create" class="customerController">
> <result name="success" type="tiles">customer.create</result>
> </action>
> <action name="add" method="add" class="customerController">
> <result type="redirectAction">list</result>
> <result name="input" type="tiles">customer.create</result>
> </action>
> <action name="edit" method="edit" class="customerController">
> <result name="success" type="tiles">customer.edit</result>
> </action>
> <action name="update" method="update" class="customerController">
> <result type="redirectAction">list</result>
> <result name="input" type="tiles">customer.edit</result>
> </action>
> <action name="delete" method="delete" class="customerController">
> <result type="redirectAction">list</result>
> </action>
> </package>
> </struts>
>
> Customer validation configuration:
>
> <validators>
> <field name="customer.name">
> <field-validator type="requiredstring">
> <message>You must enter a value for Customer Name.</message>
> </field-validator>
> <field-validator type="stringlength">
> <param name="min">4</param>
> <message>Customer name must be at least ${min} characters long.</message>
> </field-validator>
> <field-validator>
> <param name="max">20</param>
> <message>Customer name may not be longer than ${max}
> characters.</message>
> </field-validator>
> </field>
> </validators>
>
> Customer Create JSP:
> <%@ taglib prefix="s" uri="/struts-tags"%>
> <%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
> <div class="body">
> <h1>Create Customer</h1>
> <s:form namespace="/customer" action="add" validate="false"
> method="POST">
> <tiles:insertAttribute name="form" />
> </s:form>
> </div>
>
> And here is the form.jsp that provides the fields for this form:
> <%@ taglib prefix="s" uri="/struts-tags"%>
> <div class="dialog">
> <table>
> <tbody>
> <tr class="prop">
> <td valign="top" class="name required">
> <label for="description">Name:</label>
> </td>
> <td valign="top">
> <s:textfield id="name" name="customer.name"/>
> </td>
> </tr>
> <tr class="prop">
> <td>
> <span class="button"><s:submit/></span>
> </td>
> </tr>
> </tbody>
> </table>
> </div>
>
> Dave Newton wrote:
>> --- On Wed, 10/15/08, David C. Hicks wrote:
>>> I can't really tell if validation is even being called.
>>> If by "is workflow" you mean is it in the interceptor stack,
>>> Yes. It is in the stack immediately following validation.
>>>
>>> I'll be happy to provide whatever information you need.
>>> I would be considered a "newbie". So, I'm not really
>>> sure what information is helpful.
>>
>> The code (if applicable, like are you defining your own validate()),
>> configuration (action, validation), and possibly the JSP (showing
>> things like the action being submitted to, and an example field for
>> which validation is failing). And the version of Struts 2.
>>
>> Dave
>>
>>
>> ---------------------------------------------------------------------
>> 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
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Validation Help?
Posted by Dave Newton <ne...@yahoo.com>.
Don't mistake my curtness for disgust ;)
--- On Wed, 10/15/08, David C. Hicks wrote:
> If by "zero-config" you're referring to our network, that would be
> No. We're on a fairly standard DHCP/DNS local network here
> at the office. If you mean something else, then I'm afraid I'm
> blonde again. :-)
Zero-config refers to an S2 plugin that allows XML-free (mostly) configuration and can sometimes affect the way things work--it's just one of the information points that can be handy.
Another thing I'll often try is running it with the default stack to see if the error persists. Time permitting I or someone else will take the fragments presented and do a quick sanity check; I didn't see anything immediately obvious, but I don't always see stuff just looking at stuff, either :)
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Validation Help?
Posted by "David C. Hicks" <dh...@i-hicks.org>.
Hey Dave,
Sorry - I didn't mean to be deliberately vague. I'm kind of stumbling
through this to help the team. The real Struts "genius" of the bunch is
wrapped up with other problems. I was just trying to help.
If by "zero-config" you're referring to our network, that would be No.
We're on a fairly standard DHCP/DNS local network here at the office.
If you mean something else, then I'm afraid I'm blonde again. :-)
I think I tried setting up a CustomerController-add-validation.xml, but
I'll give it another try.
Thanks for the feedback,
Dave
Dave Newton wrote:
> --- On Wed, 10/15/08, David C. Hicks wrote:
>
>> We are using the "simple" theme primarily, but even if the page won't
>> report errors shouldn't the action fail if it is validating and I give
>> it bad data on purpose?
>>
>
> Yes, but you never actually said specifically what was or wasn't happening, so I had to guess.
>
>
>> Our main layout has a <s:actionerror/> tag that should get
>> any reported validation, though.
>>
>
> Didn't know that either.
>
>
>> We're just not relying on the theme to insert that tag for us.
>>
>
> None of the default shipping themes would; the themes that show error messages put the messages inline with the form fields.
>
> The first thing I'd try is creating a XxxController-add-validation.xml and see if that works, since you've defined an alias for the action class. (Where Xxx is whatever that controller class was called.)
>
> Are you using zero-config?
>
> Dave
>
>
> ---------------------------------------------------------------------
> 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: Validation Help?
Posted by Dave Newton <ne...@yahoo.com>.
--- On Wed, 10/15/08, David C. Hicks wrote:
> We are using the "simple" theme primarily, but even if the page won't
> report errors shouldn't the action fail if it is validating and I give
> it bad data on purpose?
Yes, but you never actually said specifically what was or wasn't happening, so I had to guess.
> Our main layout has a <s:actionerror/> tag that should get
> any reported validation, though.
Didn't know that either.
> We're just not relying on the theme to insert that tag for us.
None of the default shipping themes would; the themes that show error messages put the messages inline with the form fields.
The first thing I'd try is creating a XxxController-add-validation.xml and see if that works, since you've defined an alias for the action class. (Where Xxx is whatever that controller class was called.)
Are you using zero-config?
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Validation Help?
Posted by "David C. Hicks" <dh...@i-hicks.org>.
We are using the "simple" theme primarily, but even if the page won't
report errors shouldn't the action fail if it is validating and I give
it bad data on purpose? We believe it's simply not executing the
validation. Our main layout has a <s:actionerror/> tag that should get
any reported validation, though. We're just not relying on the theme to
insert that tag for us.
Dave Newton wrote:
> What theme are you using? The presence of a bunch of table-oriented tags would lead me to believe you're using the "simple" theme, which doesn't report validation errors.
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Validation Help?
Posted by Dave Newton <ne...@yahoo.com>.
What theme are you using? The presence of a bunch of table-oriented tags would lead me to believe you're using the "simple" theme, which doesn't report validation errors.
--- On Wed, 10/15/08, David C. Hicks <dh...@i-hicks.org> wrote:
> From: David C. Hicks <dh...@i-hicks.org>
> Subject: Re: Validation Help?
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Date: Wednesday, October 15, 2008, 5:42 PM
> We are not overriding the validate() method of
> ActionSupport. I
> double-checked to be sure of that.
>
> CustomerController (is an extension of a couple of base
> classes but
> eventually extends ActionSupport):
> public class CustomerController extends
> AbstractCrudController<Customer> {
> private static final long serialVersionUID = 1L;
>
> public CustomerController(GenericDao<Customer, Long>
> dao) {
> super(Customer.class, dao);
> }
>
> public List<Customer> getCustomers() {
> return getPersistentEntityList();
> }
>
> public Customer getCustomer() {
> return getPersistentEntity();
> }
>
> public void setCustomer(Customer customer) {
> setPersistentEntity(customer);
> }
>
> @Override
> protected void performPreCreateOperations() {
> }
>
> @Override
> protected boolean performPreAddOperations() {
> return true;
> }
>
> @Override
> protected void performPreUpdateOperations() {
> }
>
> @Override
> protected void performPrepareOperations() {
> }
>
> @Override
> protected Privilege crudPrivilege() {
> return Privilege.CRUD_CUSTOMER;
> }
> }
>
> Customer action configuration:
> <struts>
> <package name="customer"
> namespace="/customer"
> extends="harvey">
> <action name="list" method="list"
> class="customerController">
> <result name="success"
> type="tiles">customer.list</result>
> </action>
> <action name="view" method="view"
> class="customerController">
> <result name="success"
> type="tiles">customer.view</result>
> </action>
> <action name="create"
> method="create"
> class="customerController">
> <result name="success"
> type="tiles">customer.create</result>
> </action>
> <action name="add" method="add"
> class="customerController">
> <result
> type="redirectAction">list</result>
> <result name="input"
> type="tiles">customer.create</result>
> </action>
> <action name="edit" method="edit"
> class="customerController">
> <result name="success"
> type="tiles">customer.edit</result>
> </action>
> <action name="update"
> method="update"
> class="customerController">
> <result
> type="redirectAction">list</result>
> <result name="input"
> type="tiles">customer.edit</result>
> </action>
> <action name="delete"
> method="delete"
> class="customerController">
> <result
> type="redirectAction">list</result>
> </action>
> </package>
> </struts>
>
> Customer validation configuration:
>
> <validators>
> <field name="customer.name">
> <field-validator type="requiredstring">
> <message>You must enter a value for Customer
> Name.</message>
> </field-validator>
> <field-validator type="stringlength">
> <param name="min">4</param>
> <message>Customer name must be at least ${min}
> characters long.</message>
> </field-validator>
> <field-validator>
> <param name="max">20</param>
> <message>Customer name may not be longer than ${max}
> characters.</message>
> </field-validator>
> </field>
> </validators>
>
> Customer Create JSP:
> <%@ taglib prefix="s"
> uri="/struts-tags"%>
> <%@ taglib prefix="tiles"
> uri="http://tiles.apache.org/tags-tiles"%>
> <div class="body">
> <h1>Create Customer</h1>
> <s:form namespace="/customer"
> action="add" validate="false"
> method="POST">
> <tiles:insertAttribute name="form" />
> </s:form>
> </div>
>
> And here is the form.jsp that provides the fields for this
> form:
> <%@ taglib prefix="s"
> uri="/struts-tags"%>
> <div class="dialog">
> <table>
> <tbody>
> <tr class="prop">
> <td valign="top" class="name
> required">
> <label
> for="description">Name:</label>
> </td>
> <td valign="top">
> <s:textfield id="name"
> name="customer.name"/>
> </td>
> </tr>
> <tr class="prop">
> <td>
> <span
> class="button"><s:submit/></span>
> </td>
> </tr>
> </tbody>
> </table>
> </div>
>
> Dave Newton wrote:
> > --- On Wed, 10/15/08, David C. Hicks wrote:
> >
> >> I can't really tell if validation is even
> being called.
> >> If by "is workflow" you mean is it in
> the interceptor stack,
> >> Yes. It is in the stack immediately following
> validation.
> >>
> >> I'll be happy to provide whatever information
> you need.
> >> I would be considered a "newbie". So,
> I'm not really
> >> sure what information is helpful.
> >>
> >
> > The code (if applicable, like are you defining your
> own validate()), configuration (action, validation), and
> possibly the JSP (showing things like the action being
> submitted to, and an example field for which validation is
> failing). And the version of Struts 2.
> >
> > Dave
> >
> >
> >
> ---------------------------------------------------------------------
> > 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
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Validation Help?
Posted by "David C. Hicks" <dh...@i-hicks.org>.
We are not overriding the validate() method of ActionSupport. I
double-checked to be sure of that.
CustomerController (is an extension of a couple of base classes but
eventually extends ActionSupport):
public class CustomerController extends AbstractCrudController<Customer> {
private static final long serialVersionUID = 1L;
public CustomerController(GenericDao<Customer, Long> dao) {
super(Customer.class, dao);
}
public List<Customer> getCustomers() {
return getPersistentEntityList();
}
public Customer getCustomer() {
return getPersistentEntity();
}
public void setCustomer(Customer customer) {
setPersistentEntity(customer);
}
@Override
protected void performPreCreateOperations() {
}
@Override
protected boolean performPreAddOperations() {
return true;
}
@Override
protected void performPreUpdateOperations() {
}
@Override
protected void performPrepareOperations() {
}
@Override
protected Privilege crudPrivilege() {
return Privilege.CRUD_CUSTOMER;
}
}
Customer action configuration:
<struts>
<package name="customer" namespace="/customer" extends="harvey">
<action name="list" method="list" class="customerController">
<result name="success" type="tiles">customer.list</result>
</action>
<action name="view" method="view" class="customerController">
<result name="success" type="tiles">customer.view</result>
</action>
<action name="create" method="create" class="customerController">
<result name="success" type="tiles">customer.create</result>
</action>
<action name="add" method="add" class="customerController">
<result type="redirectAction">list</result>
<result name="input" type="tiles">customer.create</result>
</action>
<action name="edit" method="edit" class="customerController">
<result name="success" type="tiles">customer.edit</result>
</action>
<action name="update" method="update" class="customerController">
<result type="redirectAction">list</result>
<result name="input" type="tiles">customer.edit</result>
</action>
<action name="delete" method="delete" class="customerController">
<result type="redirectAction">list</result>
</action>
</package>
</struts>
Customer validation configuration:
<validators>
<field name="customer.name">
<field-validator type="requiredstring">
<message>You must enter a value for Customer Name.</message>
</field-validator>
<field-validator type="stringlength">
<param name="min">4</param>
<message>Customer name must be at least ${min} characters long.</message>
</field-validator>
<field-validator>
<param name="max">20</param>
<message>Customer name may not be longer than ${max} characters.</message>
</field-validator>
</field>
</validators>
Customer Create JSP:
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
<div class="body">
<h1>Create Customer</h1>
<s:form namespace="/customer" action="add" validate="false" method="POST">
<tiles:insertAttribute name="form" />
</s:form>
</div>
And here is the form.jsp that provides the fields for this form:
<%@ taglib prefix="s" uri="/struts-tags"%>
<div class="dialog">
<table>
<tbody>
<tr class="prop">
<td valign="top" class="name required">
<label for="description">Name:</label>
</td>
<td valign="top">
<s:textfield id="name" name="customer.name"/>
</td>
</tr>
<tr class="prop">
<td>
<span class="button"><s:submit/></span>
</td>
</tr>
</tbody>
</table>
</div>
Dave Newton wrote:
> --- On Wed, 10/15/08, David C. Hicks wrote:
>
>> I can't really tell if validation is even being called.
>> If by "is workflow" you mean is it in the interceptor stack,
>> Yes. It is in the stack immediately following validation.
>>
>> I'll be happy to provide whatever information you need.
>> I would be considered a "newbie". So, I'm not really
>> sure what information is helpful.
>>
>
> The code (if applicable, like are you defining your own validate()), configuration (action, validation), and possibly the JSP (showing things like the action being submitted to, and an example field for which validation is failing). And the version of Struts 2.
>
> Dave
>
>
> ---------------------------------------------------------------------
> 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: Validation Help?
Posted by Dave Newton <ne...@yahoo.com>.
--- On Wed, 10/15/08, David C. Hicks wrote:
> I can't really tell if validation is even being called.
> If by "is workflow" you mean is it in the interceptor stack,
> Yes. It is in the stack immediately following validation.
>
> I'll be happy to provide whatever information you need.
> I would be considered a "newbie". So, I'm not really
> sure what information is helpful.
The code (if applicable, like are you defining your own validate()), configuration (action, validation), and possibly the JSP (showing things like the action being submitted to, and an example field for which validation is failing). And the version of Struts 2.
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Validation Help?
Posted by "David C. Hicks" <dh...@i-hicks.org>.
I can't really tell if validation is even being called.
If by "is workflow" you mean is it in the interceptor stack, Yes. It is
in the stack immediately following validation.
I'll be happy to provide whatever information you need. I would be
considered a "newbie". So, I'm not really sure what information is helpful.
Dave Newton wrote:
> --- On Wed, 10/15/08, David C. Hicks wrote:
>
>> [...] Validation is on my interceptor stack.
>>
>
> Is "workflow"? Do you know that *validation* doesn't occur, or that it just doesn't return to input on validation errors?
>
> Without any further information it'll be tough to help.
>
> Dave
>
>
> ---------------------------------------------------------------------
> 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: Validation Help?
Posted by Dave Newton <ne...@yahoo.com>.
--- On Wed, 10/15/08, David C. Hicks wrote:
> [...] Validation is on my interceptor stack.
Is "workflow"? Do you know that *validation* doesn't occur, or that it just doesn't return to input on validation errors?
Without any further information it'll be tough to help.
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org