Modified: incubator/beehive/trunk/samples/netui-samples/validation/Controller.java URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/netui-samples/validation/Controller.java?rev=177943&r1=177942&r2=177943&view=diff ============================================================================== --- incubator/beehive/trunk/samples/netui-samples/validation/Controller.java (original) +++ incubator/beehive/trunk/samples/netui-samples/validation/Controller.java Mon May 23 01:45:09 2005 @@ -23,47 +23,100 @@ import org.apache.beehive.netui.pageflow.annotations.*; @Jpf.Controller( - simpleActions = [EMAIL PROTECTED](name="begin",path="index.jsp")}, - validatableBeans={ - @Jpf.ValidatableBean( - type=Controller.MyForm.class, - validatableProperties={ - @Jpf.ValidatableProperty( - propertyName="date", - displayName="This field", - [EMAIL PROTECTED](), - [EMAIL PROTECTED](pattern="M-d-y") - ) - } - ) + simpleActions={ + @Jpf.SimpleAction(name="begin",path="index.jsp") + }, + messageBundles={ + @Jpf.MessageBundle(bundlePath="org.apache.beehive.samples.netui.resources.validation.messages") } ) public class Controller extends PageFlowController { + /** + * Basic submit action -- uses validation rules defined on MyForm. + */ @Jpf.Action( forwards={ @Jpf.Forward(name="success", path="success.jsp") }, [EMAIL PROTECTED](name="fail", navigateTo=Jpf.NavigateTo.currentPage) ) - public Forward validate( MyForm form ) + public Forward submit(MyForm form) { - getRequest().setAttribute("date", form.getDate()); - return new Forward( "success" ); + Forward fwd = new Forward("success"); + fwd.addActionOutput("value", form.getValue()); + return fwd; } - public static class MyForm implements Serializable + /** + * This action adds an additional validation rule for the 'value' property. + */ + @Jpf.Action( + forwards={ + @Jpf.Forward(name="success", path="success.jsp") + }, + [EMAIL PROTECTED](name="fail", navigateTo=Jpf.NavigateTo.currentPage), + + // This is the extra validation rule. + validatableProperties={ + @Jpf.ValidatableProperty( + propertyName="value", + [EMAIL PROTECTED](chars=4, messageKey="errors.toolong") + ) + } + ) + public Forward submitWithExtraRule(MyForm form) { - private String _date; + Forward fwd = new Forward("success"); + fwd.addActionOutput("value", form.getValue()); + return fwd; + } + + /** + * The form bean class. Note that form beans do <i>not</i> have to be inner classes; validation + * annotations work on external form bean classes, too. + * + * This form bean class uses message resources from the page flow's message bundle (defined + * inside the @Jpf.Controller annotation). A form bean class can also define its <i>own</i> + * message bundle through the @Jpf.FormBean annotation. + */ + public static class MyForm + implements Serializable + { + private String _value; + private String _confirmValue; + + @Jpf.ValidatableProperty( + displayNameKey="displayname.value", + [EMAIL PROTECTED](), + [EMAIL PROTECTED](chars=3) + ) + public String getValue() + { + return _value; + } - public String getDate() + public void setValue( String value ) + { + _value = value; + } + + @Jpf.ValidatableProperty( + displayNameKey="displayname.confirmvalue", + [EMAIL PROTECTED](), + [EMAIL PROTECTED]( + condition="${actionForm.confirmValue == actionForm.value}", + messageKey="errors.nomatch" + ) + ) + public String getConfirmValue() { - return _date; + return _confirmValue; } - public void setDate( String str ) + public void setConfirmValue( String confirmValue ) { - _date = str; + _confirmValue = confirmValue; } } }
Modified: incubator/beehive/trunk/samples/netui-samples/validation/index.jsp URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/netui-samples/validation/index.jsp?rev=177943&r1=177942&r2=177943&view=diff ============================================================================== --- incubator/beehive/trunk/samples/netui-samples/validation/index.jsp (original) +++ incubator/beehive/trunk/samples/netui-samples/validation/index.jsp Mon May 23 01:45:09 2005 @@ -21,13 +21,43 @@ <%@ taglib prefix="netui-template" uri="http://beehive.apache.org/netui/tags-template-1.0"%> <netui-template:template templatePage="/resources/template/template.jsp"> + <netui-template:setAttribute name="samTitle" value="Validation"/> + <netui-template:section name="main"> - <netui:form action="validate"> - <p>Submit date (MM-dd-YYYY): - <netui:textBox dataSource="actionForm.date"/></p> - <netui:error key="date"/> - <p><netui:button value="Submit"/></p> + <i> + The form bean <code>MyForm</code> uses annotations to define several validation rules: + <ul> + <li>Both fields are required.</li> + <li>The 'value' field must be at least three characters long.</li> + <li>The fields must match.</li> + </ul> + </i> + <br/> + <netui:form action="submit"> + <table> + <tr> + <td>value:</td> + <td> + <netui:textBox dataSource="actionForm.value"/> + <netui:error key="value"/> + </td> + </tr> + <tr> + <td>confirm value:</td> + <td> + <netui:textBox dataSource="actionForm.confirmValue"/> + <netui:error key="confirmValue"/> + </td> + </tr> + </table> + <br/> + <netui:button value="Submit"/> + <i>(submits to action 'submit', which just uses the rules defined on <code>MyForm</code>)</i> + <br/> + <netui:button value="Submit (extra rule)" action="submitWithExtraRule"/> + <i>(submits to action 'submitWithExtraRule', which adds a rule that requires 'value' to be at most four characters long)</i> </netui:form> </netui-template:section> + </netui-template:template> Modified: incubator/beehive/trunk/samples/netui-samples/validation/success.jsp URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/netui-samples/validation/success.jsp?rev=177943&r1=177942&r2=177943&view=diff ============================================================================== --- incubator/beehive/trunk/samples/netui-samples/validation/success.jsp (original) +++ incubator/beehive/trunk/samples/netui-samples/validation/success.jsp Mon May 23 01:45:09 2005 @@ -23,9 +23,8 @@ <netui-template:template templatePage="/resources/template/template.jsp"> <netui-template:setAttribute name="samTitle" value="Validation"/> <netui-template:section name="main"> - <p>Data submitted: <netui:span value="${requestScope.date}"/></p> - <p>Date validation successful.</p> - <p><netui:anchor action="begin">Submit another date</netui:anchor></p> + <p>Validation successful.</p> + <p><netui:anchor action="begin">Start over</netui:anchor></p> </netui-template:section> </netui-template:template>
