I hope someone can help me..
I do not manage to use the validator framework.
Here my configuration :
dbforms-config.xml
----------------------------
<init-param>
<param-name>validation</param-name>
<param-value>/WEB-INF/validation.xml</param-value>
</init-param>
I tried to debug what's going on.
I looked at the code of dbforms and I realized that when I validate the form I do not pass into the org.dbforms.event.ValidationEvent.doValidation() method.
I don't understand why.
So, I found another solution. I use the interceptors.
But I have problems.
I have to create a ProductValidation class to validate my products. Here is the code:
if (designation == null || designation.trim().length()==0 || designation.compareTo("") == 0) {
errors.add("Designation is required.<br>");
}
if (category.compareTo("0") == 0 || category.trim().length()==0) {
errors.add("Category is required<br>");
}
if(!errors.isEmpty()) {
throw new MultipleValidationException(errors);
}
else return GRANT_OPERATION;
}
public int preInsert(HttpServletRequest request, Table table, FieldValues fieldValues, DbFormsConfig config, Connection con)
throws ValidationException {
return checkProduct(fieldValues);
}
public int preUpdate(HttpServletRequest request, Table table, FieldValues fieldValues, DbFormsConfig config, Connection con)
throws ValidationException {
return checkProduct(fieldValues);
}
}
In the dbform tag I put the following attributes:
<db:dbform tableName="alter_achat_product"
maxRows="1"
multipart="true"
followUp="alter_annuaire_product_search.jsp"
redisplayFieldsOnError="true"
followUpOnError="alter_annuaire_product_creation.jsp"
autoUpdate="false"
captionResource="true">
For creation everything works well, but for the update the error message is posted twice.
Could you explain me why?
Thanks in advance !
Regards
Sandra
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks you for your help woodchuck.
I don't understand why it doesn't work because I don't use subforms.
My form upload files, so I have to put multipart to true.
And there isn't mistake in the interceptor name or table name.
And it works fine for creation.
it is a mystery ;o)
Regards,
Sandra
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi everybody,
I hope someone can help me..
I do not manage to use the validator framework.
Here my configuration :
dbforms-config.xml
----------------------------
<init-param>
<param-name>validation</param-name>
<param-value>/WEB-INF/validation.xml</param-value>
</init-param>
<init-param>
<param-name>validator-rules</param-name>
<param-value>/WEB-INF/validator-rules.xml</param-value>
</init-param>
Validation.xml
---------------------
<form-validation>
<formset>
<form name="Products">
<field depends="required" property="name">
<msg name="required" key="errors.required" resource="true"/>
<arg0 name="required" key="errors.field.name" resource="true"/>
</field>
</form>
</formset>
</form-validation>
product_create.jsp
---------------------------
<db:dbform tableName="products"
maxRows="1"
multipart="true"
autoUpdate="false"
followUp="product_search.jsp"
formValidatorName="Products"
redisplayFieldsOnError="true"
followUpOnError="product_create.jsp"
captionResource="true">
When I submit my form with the field "name" empty, my form is submitted (I haven't error message), and the insert is done.
I don't understand why.
I look bugtracker example, it works fine..
It seems me to have made the same thing.
Someone can help me?
Thanks in advance.
Regards
Sandra
Could you try to debug what's going on? For me validation is working.
Is your validator-rules file on the right place?
Thanks
Henner
I tried to debug what's going on.
I looked at the code of dbforms and I realized that when I validate the form I do not pass into the org.dbforms.event.ValidationEvent.doValidation() method.
I don't understand why.
So, I found another solution. I use the interceptors.
But I have problems.
I have to create a ProductValidation class to validate my products. Here is the code:
package com.altervisions.annuaire;
import org.dbforms.config.*;
import org.dbforms.event.*;
import java.sql.*;
import java.util.Vector;
import javax.servlet.http.*;
public class Product extends DbEventInterceptorSupport {
private int checkProduct(FieldValues fieldValues) throws ValidationException {
Vector errors = new Vector();
String designation = (String) fieldValues.get("designation").getFieldValue();
String category = (String) fieldValues.get("category_id").getFieldValue();
if (designation == null || designation.trim().length()==0 || designation.compareTo("") == 0) {
errors.add("Designation is required.<br>");
}
if (category.compareTo("0") == 0 || category.trim().length()==0) {
errors.add("Category is required<br>");
}
if(!errors.isEmpty()) {
throw new MultipleValidationException(errors);
}
else return GRANT_OPERATION;
}
public int preInsert(HttpServletRequest request, Table table, FieldValues fieldValues, DbFormsConfig config, Connection con)
throws ValidationException {
return checkProduct(fieldValues);
}
public int preUpdate(HttpServletRequest request, Table table, FieldValues fieldValues, DbFormsConfig config, Connection con)
throws ValidationException {
return checkProduct(fieldValues);
}
}
In the dbform tag I put the following attributes:
<db:dbform tableName="alter_achat_product"
maxRows="1"
multipart="true"
followUp="alter_annuaire_product_search.jsp"
redisplayFieldsOnError="true"
followUpOnError="alter_annuaire_product_creation.jsp"
autoUpdate="false"
captionResource="true">
For creation everything works well, but for the update the error message is posted twice.
Could you explain me why?
Thanks in advance !
Regards
Sandra
for me, when i see multiple error messages it's because i am using subforms with autoUpdate="true"
i noticed you set multipart="true", does your form upload files? if not, you should set this to false or just leave out this attribute.
also, i noticed your interceptor is called "Product" but your form is for the "alter_achat_product" table... is there a mistake here?
woodchuck
Thanks you for your help woodchuck.
I don't understand why it doesn't work because I don't use subforms.
My form upload files, so I have to put multipart to true.
And there isn't mistake in the interceptor name or table name.
And it works fine for creation.
it is a mystery ;o)
Regards,
Sandra