Aug 1st, 2011, 05:34 PM
Number Field Logic
I have a number field in one of my entities. I need to add some logic that this field can only take numbers that are powers of two and if it isn't then an error should be thrown to the user.
I have no idea where to start with this, I'm fairly new to web development. I was thinking I could push in the setters and getters for the number field and add logic there but then how will the appropriate error be thrown?
Aug 1st, 2011, 05:50 PM
You can use following formula...
log(n)/log(2) = an integer; means n is a power 2 number.
There might be other ways for getting it. At least you got one now.
Aug 1st, 2011, 05:55 PM
I know what formula to use I'm just having trouble executing it on a roo project. i.e. Where/what file does this piece of code go into? How do I make sure an error is thrown so the user sees "Invalid number not a power of two"
Aug 1st, 2011, 06:09 PM
You know the hard part then... The other part could be like this:
2) server side way. In entity controller loading the message error in the returning model object.
Aug 2nd, 2011, 06:51 PM
Sorry could you give me a little more information on how to do this? How do i create a .jspx in the entity?
It also would be helpful if I had more details on how to exactly do it in the server side way you described.