|
From: Chad B. <cwb...@us...> - 2008-08-27 20:13:10
|
User: cwbrandon
Date: 08/08/27 13:13:21
Modified: andromda-jsf2/src/main/java/org/andromda/cartridges/jsf2
JSFUtils.java
andromda-jsf2/src/main/resources/templates/jsf2/configuration
validator-rules.xml.vsl
Log:
Make isType work with abstract types, also add double to validator-rules
Revision Changes Path
1.8 +30 -8 cartridges/andromda-jsf2/src/main/java/org/andromda/cartridges/jsf2/JSFUtils.java
Index: JSFUtils.java
===================================================================
RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/java/org/andromda/cartridges/jsf2/JSFUtils.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -w -r1.7 -r1.8
--- JSFUtils.java 29 Jun 2008 01:56:38 -0000 1.7
+++ JSFUtils.java 27 Aug 2008 20:13:20 -0000 1.8
@@ -352,7 +352,7 @@
*/
public static boolean isByte(final ClassifierFacade type)
{
- return UMLMetafacadeUtils.isType(
+ return isType(
type,
JSFProfile.BYTE_TYPE_NAME);
}
@@ -362,7 +362,7 @@
*/
public static boolean isShort(final ClassifierFacade type)
{
- return UMLMetafacadeUtils.isType(
+ return isType(
type,
JSFProfile.SHORT_TYPE_NAME);
}
@@ -372,7 +372,7 @@
*/
public static boolean isInteger(final ClassifierFacade type)
{
- return UMLMetafacadeUtils.isType(
+ return isType(
type,
JSFProfile.INTEGER_TYPE_NAME);
}
@@ -382,7 +382,7 @@
*/
public static boolean isLong(final ClassifierFacade type)
{
- return UMLMetafacadeUtils.isType(
+ return isType(
type,
JSFProfile.LONG_TYPE_NAME);
}
@@ -392,7 +392,7 @@
*/
public static boolean isFloat(final ClassifierFacade type)
{
- return UMLMetafacadeUtils.isType(
+ return isType(
type,
JSFProfile.FLOAT_TYPE_NAME);
}
@@ -402,11 +402,12 @@
*/
public static boolean isDouble(final ClassifierFacade type)
{
- return UMLMetafacadeUtils.isType(
+ return isType(
type,
JSFProfile.DOUBLE_TYPE_NAME);
}
+
/**
* @return <code>true</code> if the type of this field is a date, <code>false</code> otherwise
*/
@@ -420,7 +421,7 @@
*/
public static boolean isTime(final ClassifierFacade type)
{
- return UMLMetafacadeUtils.isType(
+ return isType(
type,
JSFProfile.TIME_TYPE_NAME);
}
@@ -430,11 +431,32 @@
*/
public static boolean isUrl(final ClassifierFacade type)
{
- return UMLMetafacadeUtils.isType(
+ return isType(
type,
JSFProfile.URL_TYPE_NAME);
}
+
+ private static boolean isType(final ClassifierFacade type, String typeName)
+ {
+ boolean isType = UMLMetafacadeUtils.isType(
+ type,
+ typeName);
+ if (!isType)
+ {
+ // - handle abstract types that are mapped to java types
+ if (type.getLanguageMappings() != null)
+ {
+ final String javaTypeName = type.getLanguageMappings().getTo(type.getFullyQualifiedName(true));
+ if (javaTypeName != null)
+ {
+ isType = javaTypeName.replaceAll(".*\\.", "").equalsIgnoreCase(type.getLanguageMappings().getTo(typeName));
+ }
+ }
+ }
+ return isType;
+ }
+
/**
* @return <code>true</code> if the type of this field is a String, <code>false</code> otherwise
*/
1.4 +78 -0 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/configuration/validator-rules.xml.vsl
Index: validator-rules.xml.vsl
===================================================================
RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/configuration/validator-rules.xml.vsl,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -r1.3 -r1.4
--- validator-rules.xml.vsl 17 Sep 2007 17:40:50 -0000 1.3
+++ validator-rules.xml.vsl 27 Aug 2008 20:13:21 -0000 1.4
@@ -583,6 +583,84 @@
</validator>
+ <validator name="double"
+ classname="org.andromda.cartridges.jsf.validator.ParameterChecks"
+ method="validateDouble"
+ methodParams="javax.faces.context.FacesContext,
+ java.lang.Object,java.util.Map,
+ java.util.Collection,
+ org.apache.commons.validator.ValidatorAction,
+ org.apache.commons.validator.Field"
+ depends=""
+ msg="errors.float"
+ jsFunctionName="FloatValidations">
+
+ <javascript><![CDATA[
+ function validateFloat(form) {
+ var bValid = true;
+ var focusField = null;
+ var i = 0;
+ var fields = new Array();
+ var formName = form.getAttributeNode("name");
+ oFloat = eval('new ' + formName.value + '_FloatValidations()');
+ for (x in oFloat) {
+ var field = form[oFloat[x][0]];
+
+ if (typeof(field) == 'undefined') {
+ return true;
+ }
+
+ if (field.type == 'text' ||
+ field.type == 'textarea' ||
+ field.type == 'select-one' ||
+ field.type == 'radio') {
+
+ var value = '';
+ // get field's value
+ if (field.type == "select-one") {
+ var si = field.selectedIndex;
+ if (si >= 0) {
+ value = field.options[si].value;
+ }
+ } else {
+ value = field.value;
+ }
+
+ if (value.length > 0) {
+ // remove '.' before checking digits
+ var tempArray = value.split('.');
+ var joinedString= tempArray.join('');
+
+ if (!isAllDigits(joinedString)) {
+ bValid = false;
+ if (i == 0) {
+ focusField = field;
+ }
+ fields[i++] = oFloat[x][1];
+
+ } else {
+ var iValue = parseFloat(value);
+ if (isNaN(iValue)) {
+ if (i == 0) {
+ focusField = field;
+ }
+ fields[i++] = oFloat[x][1];
+ bValid = false;
+ }
+ }
+ }
+ }
+ }
+ if (fields.length > 0) {
+ focusField.focus();
+ alert(fields.join('\n'));
+ }
+ return bValid;
+ }]]>
+ </javascript>
+
+ </validator>
+
<validator name="equal"
classname="org.andromda.cartridges.jsf.validator.ParameterChecks"
method="validateEqual"
|