My recommendation is that you override the setter in the subclass and throw
IllegalArgumentException (runtime exception) as you probably already have
done.

Somewhere you need to convert this to an ApplicationException and I think a
good place is the ErrorHandlingAdvice, which is used in front of the
services. You can replace the default implementation with your own (subclass
of default).
Add method 
public void afterThrowing(Method m, Object[] args, Object target,
IllegalArgumentException e) throws ApplicationException {

Replace it with generator property
framework.errorHandlingAdviceClass
See:
http://fornax-platform.org/cp/display/fornax/7.+Developer%27s+Guide+%28CSC%29#7.Developer%27sGuide%28CSC%29-FrameworkClasses

If we are talking about setting the value in the client then you need to
convert the exception with something else. Please clarify where in the
application the value is assigned.


All persistent Entities and Value Objects will also have a surrogate id
attribute, which is the primary key in the database. This is kind of best
practice with Hibernate.
See also:
http://fornax-platform.org/cp/display/fornax/3.+Advanced+Tutorial+%28CSC%29#3.AdvancedTutorial%28CSC%29-Key

/Patrik


ralfst wrote:
> 
> Hi,
> 
> i would like to implement a setter for a double value that checks the
> value against a range of values. If the value isn't in the range, an
> Exception should be thrown.
> 
> I simply used a BasicType in model.design:
> 
>               BasicType Rating {
>                       !immutable
>                       
>                       Double value;
>               }
> 
> The BasicType Rating is used like this:
> 
>       Entity Movie {
>           scaffold
>                       
>             String movieName key;
>             String edition key;
> 
>             reference @Rating rating nullable;
>       }
> 
> The range is fix (0 to 10).
> 
> My first implementation was to throw a SystemException, because if I used
> a checked exception (ApplicationException) the setter would need a throws
> declaration. That isn't possible as far as I know because the generated
> RatingBase has no throws declaration for the setter...
> 
> But it isn't nice when a SystemError is displayed only because the user
> entered a wrong value. So i would like to catch the exception and handle
> it by showing the user a info message.
> 
> Where do I have to add this code or is there a better way to handle the
> validation of the value?
> 
> Furthermore I was wondering myself why there is always an ID created for
> an entity in the db and not just taken e.g. in my example movieName and
> edition as db keys?
> 
> Greets, Ralf
> 

-- 
View this message in context: 
http://www.nabble.com/checking-against-range-of-values-tp20293432s17564p20293969.html
Sent from the Fornax-Platform mailing list archive at Nabble.com.


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Fornax-developer mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fornax-developer

Reply via email to