beehive-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Deepak Natarajan" <>
Subject RE: Beehive Form Field Validation
Date Wed, 19 Dec 2007 17:02:42 GMT

Hi Paul -

Thanks for your response. Your steps would have definitely saved me a lot of

I will condense my question into a simpler form - perhaps you could
enlighten me a bit more.

Is it possible/sensible to have non-simple data types for actionform bean
properties in Beehive? Like BigDecimal, for example? Or are they all plain
strings? Is there any equivalent to the struts DynaActionForm in the Beehive

My problem is essentially that I would like to have a BigDecimal property in
my form bean, but of course the value posted from the form is a string and
the setter fails with a number format exception. I'm unable to design a
validation rule (with or without the wizard) for this condition - and it
wouldnt help since the validation annotation is on the getter anyway.


> -----Original Message-----
> From: Gorbas, Paul H [IT] []
> Sent: 19. december 2007 17:07
> To: Beehive Users;
> Subject: RE: Beehive Form Field Validation
> This may help - note I wrote for myself and posted to the workshop
> users group a while back:
> Here's how to implement data validation in Workshop 10.1.  There are
> several ways to validate, but this is server side Validation of a form
> encapsulated in a data bean.  Below is what is working for me and I am
> sharing it in hopes it will aid others:
> 1) Modify ( or create ) your form bean to implement the Validatable
> interface.
>    public class ProvisionData implements Serializable, Validatable
>    { ....
> 2) In your data bean implement the Validatable method.  It doesn't need
> to do anything, you can just put in a stub.
>    public void validate( ActionMapping arg0, HttpServletRequest arg1,
> ActionMessages arg2 )
>    {
>    }
> 3) In the Page Flow Explorer, right click on any Action that takes the
> dataBEan as a input parameter, then select from the pop-up menu
> "Validation Rules" and ActionFromScope from the sub pop-up menu.
> 4) The Validation Rules Wizard opens, in it you will see a tree of all
> the properties defined in your dataBean.
> 5) In the tree, below each property node, is a "All" Node - this is for
> localization and you can define specific language nodes if you wish.
> 6) Any exiting Rules you have previously defined will show up.  You can
> click on the rule to modify it's behavior.
> 7) To add a new rule, right click on the ALl Node ( or a new
> localization node you created) and select "Add Rule", and fill out the
> form the wizard generates for you to fill in specifying the type of
> validation rule you created.
> 8) When the wizard closes, because I choose ActionFromScope in step 3,
> the action methods annotation gets modified to include the validation
> rules you defined.  Specially it adds ( or modifies) the
> validatableProperties argument of the Jpf.Action annotation.
> 9) The one item the wizard was not generating is the
> validationErrorForward parameter of you Jpf.Action annotation, but it
> is easy enough to add it in yourself. ( A common scenario is that you
> were on a user input page that post to your action method on a form
> submit, on success it will go to the page your forwards.@Jpf.Forward
> argument specified if it failed one or more validation steps, then it
> will go to your validationErrorForward.@Jpf.Forward path ( typically
> returning back to same input page again ).
> 10) Here is an example of a annotation after the wizard is done with it
> ( I added white space for easier reading ).  In the below example, I
> have defined 3 validations rules.  Two rules are defined on the
> property "subType", and another rule is defined for the property
> "subid"
>    @Jpf.Action
>    ( forwards = { @Jpf.Forward(name = "addDone", path =
> "rtp_Input.jsp") }
>    , validationErrorForward=@Jpf.Forward( name="validationFail"
>                                         ,
> path="rtp_AddProvisioningData.jsp"
>                                         )
>    , validatableProperties = { @Jpf.ValidatableProperty( propertyName =
> "subType"
>                                                        , validateMask =
> @Jpf.ValidateMask(message = "Subscripton Type must be one of these
> values: [A,E,F,I,N,U,V,X,B,C,H,M,P,Z,1-9]", regex =
> "[A,E,F,I,N,U,V,X,B,C,H,M,P,Z,1-9]")
>                                                        ,
> validateMaxLength = @Jpf.ValidateMaxLength(message = "Subscription Type
> Code is a single character.", chars = 1)
>                                                        )
>                              , @Jpf.ValidatableProperty(
> propertyName="subid"
>                                                        ,
> validateMaxLength=@Jpf.ValidateMaxLength(message="Subscription Id max
> length is 16 characters.", chars=16)
>                                                        )
>                              }
>    )
> 11) Your almost done - as it is this will work, if a validation rule
> fails it will call your dataBeans validate() method ( where I suppose
> you could do some special validation handling ), then the server will
> serve up what every page your  up whatever page your
> validationErrorForward specified.
> 12) To actually have the error message displayed on you served up page
> you will need to and additional netui tag(s) for each property you
> created a rule for.  The tag goes in your jsp page like this
> "<netui:error key="subid"/>"  and the value for the key must equal the
> propertyName in the rules ValidatableProperty tag which much match a
> parameter name of one of your dataBeans member properties.
> 13) When all this is in place the Page Flow editor overview will
> display the error path from your action ( along with your other page
> flows).  When your input page is initially hit, the jsp's netui:error
> will display nothing.
> 14) If you submit the form and validate one or more rules, then the
> input page gets displayed again, and the "<netui:error key="subid"/>"
> tag will display one or more errors.  In my example I used in step 10
> above, I had two netui:error tags in my input jsp page - one for the
> subType, a second for the subid.  If I submit a page violating all 3
> rules, then the <netui:error key="subType"/> will display BOTH messages
> it defined, while the <netui:error key="subid"/> will display its
> single message.
> Good luck!
> -Paul G.
> -----Original Message-----
> From: Deepak Natarajan []
> Sent: Wednesday, December 19, 2007 8:52 AM
> To:
> Subject: Beehive Form Field Validation
> Hi -
> I have a very basic question about form validation in Beehive. Any
> help/guidance will be much appreciated.
> My understanding is that Beehive uses/extends Apache Commons Validatior
> framework. According to the Beehive Javadocs for validationRules
> (
> beehi
> ve/netui/pageflow/validation/ValidatorRules.html) there are various
> methods inherited from FieldChecks such as validateInteger etc. But the
> corresponding annotations to use these methods seem to be missing...or
> am I confusing myself here? Can anyone provide a simple example to use
> these? The beehive netui samples doesnt have any extensive examples in
> this area.
> Also, is it necessary that a form bean properties should be string
> types and not their real domain type (with the conversion ability
> checked in a custom rule)? Its a fundamental question, and the reason
> I'm asking is that for a BigDecimal bean property for example, if I
> enter a String value in the form, a NumberFormatException occurs
> obviously - since the validation seems to be done after the property
> setter is run, not before. Other techniques that I've encountered
> before are to have validation checks inside the setter, or some client-
> side checks etc. For me it seemed intuitive that the
> @Jpf.ValidateProperty should have been on the setter (which is where I
> put it initially until the IDE corrected me!) so that before the bean
> property is set, type validation is done - but now when the container
> does the automatic conversion to the object type, it fails with a
> NumberFormatException. What is a good pattern for this case?
> Also, any idea which version of Apache commons validator is being used
> by Beehive 1.0.2?
> Thanks in advance
> Deepak

View raw message