Use the simple-map-processor for validation: <call-map-processor in-map-name="context" out-map-name="context"> <simple-map-processor name="inputValidate"> <process field="startingDrawer"><convert type="BigDecimal"><fail-message message="Insert a valid starting drawer amount"/></convert></process> </simple-map-processor> </call-map-processor>
Regards Scott HotWax Media http://www.hotwaxmedia.com On 24/05/2011, at 7:05 AM, risali...@gmail.com wrote: > Hi Scott, > > I agree with you but when I did it (probably one year ago) I see that if I > use the method simpleTypeConvert the exception is not recognized by > call-class-method and then the exception is shown to the final user, > something similar to: > > ERROR: Could not complete the Open Terminal > [file:/ofbiz_webpos2/specialpurpose/webpos/script/org/ofbiz/webpos/event/ManagerEvents.xml#openTerminal] > process [Method to execute named simpleTypeConvert threw an exception: > org.ofbiz.base.util.GeneralException: java.text.ParseException: Unparseable > number: "a33ee" (java.text.ParseException: Unparseable number: "a33ee")] > > instead using my method the user see this error: > > Insert a valid starting drawer amount > > I agree to use only one method for conversion (so the standard one > simpleTypeConvert) but in this case I need to trap the exception in the > simple method. > > Any hint to solve this problem and then remove the method > UtilNumber.stringToBigDecimal. > > On markmail I found this old thread: > > http://ofbiz.markmail.org/search/?q=exception%20in%20call-class-method#query:exception%20in%20call-class-method+page:1+mid:orxqauretvhwuznf+state:results > > Thanks > Marco > > >> Hi Marco, >> >> We have the conversion framework for converting Strings to BigDecimals so >> there is no need to implement a new method for it: >> BigDecimal bigDecimal = (BigDecimal) ObjectType.simpleTypeConvert(object, >> "BigDecimal", null, locale); >> >> Regards >> Scott >> >> On 23/05/2011, at 1:11 AM, mrisal...@apache.org wrote: >> >>> Author: mrisaliti >>> Date: Sun May 22 13:11:17 2011 >>> New Revision: 1125951 >>> >>> URL: http://svn.apache.org/viewvc?rev=1125951&view=rev >>> Log: >>> Webpos2 improved version (OFBIZ-4287) >>> >> [snip] >>> >>> >>> Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilNumber.java >>> URL: >>> http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilNumber.java?rev=1125951&r1=1125950&r2=1125951&view=diff >>> ============================================================================== >>> --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilNumber.java >>> (original) >>> +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilNumber.java Sun >>> May 22 13:11:17 2011 >>> @@ -20,6 +20,8 @@ >>> package org.ofbiz.base.util; >>> >>> import java.math.BigDecimal; >>> +import java.text.NumberFormat; >>> +import java.text.ParseException; >>> import java.util.HashMap; >>> import java.util.Locale; >>> >>> @@ -250,4 +252,27 @@ public class UtilNumber { >>> >>> return (bd.toString() + "%"); >>> } >>> + >>> + /** >>> + * Method to convert a string into BigDecimal. >>> + * >>> + * @param stringToConvert String to convert to BigDecimal >>> + * @return The string converted to BigDecimal >>> + */ >>> + public static BigDecimal stringToBigDecimal(String stringToConvert, >>> Locale locale) { >>> + if (stringToConvert != null && stringToConvert != "") { >>> + Number numb = null; >>> + NumberFormat nf = NumberFormat.getInstance(locale); >>> + nf.setMaximumFractionDigits(10); >>> + try { >>> + numb = nf.parse(stringToConvert); >>> + return (new BigDecimal(numb.toString())); >>> + } catch (ParseException e) { >>> + return null; >>> + } >>> + } >>> + else { >>> + return null; >>> + } >>> + } >>> } >>> >> >
smime.p7s
Description: S/MIME cryptographic signature