Hi Javi I have used ISBN stereotype and validation class in qaManager and want to share same with OpenXava.
Following was done 1) Added to default-size.xml <for-stereotype name="ISBN" size="13"/>
2) Added to editors.xml <editor url="textEditor.jsp"> <for-stereotype stereotype="ISBN"/> </editor>
3) Added to Stereotype-type-default.xml <for stereotype="ISBN" type="String"/>
4) Added to messages_en.properties file
isbn_validation_error={0} must be a valid ISBN address
5) Validation class
package org.openxava.validators;
import org.openxava.validators.IPropertyValidator; import org.openxava.util.Messages; /** * * @author Janesh Kodikara */
public class ISBNValidator implements IPropertyValidator {
private org.apache.commons.validator.ISBNValidator validator = new org.apache.commons.validator.ISBNValidator();
public void validate(Messages errors, Object value, String propertyName, String modelName) throws Exception {
if (value == null || value.toString().length() ==0 ) return;
if (! validator.isValid(value.toString())) { errors.add("isbn_validation_error", propertyName); } }
}
Appreciate your comments to improve the same.
Thanking You Janesh
Hi Janesh,
the code for ISBN stereotype is already in CVS, therefore it will be available in OX2.2.4 and OX3.0beta5.
I ignored the part of editor.xml, because if you declare String as type for you stereotype it will use textEditor by default.
Cheers Javi
Log in to post a comment.
Hi Javi
I have used ISBN stereotype and validation class in qaManager and want to share same with OpenXava.
Following was done
1) Added to default-size.xml
<for-stereotype name="ISBN" size="13"/>
2) Added to editors.xml
<editor url="textEditor.jsp">
<for-stereotype stereotype="ISBN"/>
</editor>
3) Added to Stereotype-type-default.xml
<for stereotype="ISBN" type="String"/>
4) Added to messages_en.properties file
isbn_validation_error={0} must be a valid ISBN address
5) Validation class
package org.openxava.validators;
import org.openxava.validators.IPropertyValidator;
import org.openxava.util.Messages;
/**
*
* @author Janesh Kodikara
*/
public class ISBNValidator implements IPropertyValidator {
private org.apache.commons.validator.ISBNValidator validator = new org.apache.commons.validator.ISBNValidator();
public void validate(Messages errors, Object value, String propertyName, String modelName) throws Exception {
if (value == null || value.toString().length() ==0 ) return;
if (! validator.isValid(value.toString())) {
errors.add("isbn_validation_error", propertyName);
}
}
}
Appreciate your comments to improve the same.
Thanking You
Janesh
Hi Janesh,
the code for ISBN stereotype is already in CVS,
therefore it will be available in OX2.2.4 and OX3.0beta5.
I ignored the part of editor.xml, because if you declare
String as type for you stereotype it will use textEditor by default.
Cheers
Javi