| <?xml version="1.0" encoding="UTF-8"?> |
| |
| <!-- |
| * Licensed to the Apache Software Foundation (ASF) under one or more |
| * contributor license agreements. See the NOTICE file distributed with |
| * this work for additional information regarding copyright ownership. |
| * The ASF licenses this file to You under the Apache License, Version 2.0 |
| * (the "License"); you may not use this file except in compliance with |
| * the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| --> |
| |
| <ui:composition template="/main.xhtml" |
| xmlns="http://www.w3.org/1999/xhtml" |
| xmlns:tc="http://myfaces.apache.org/tobago/component" |
| xmlns:ui="http://xmlns.jcp.org/jsf/facelets"> |
| |
| <p>Tobago has JSR 303 Validation support. |
| With it, you can describe the validation in an annotation in the controller.</p> |
| |
| <tc:section label="Required"> |
| <p>In this example, the input cannot be empty - in other words, it's required. |
| The value in the controller is annotated with <code class="language-java">@NotNull</code>.</p> |
| <demo-highlight language="markup"><tc:in label="Input" value="\#{validationJsr303Controller.required}"/></demo-highlight> |
| <demo-highlight language="java">@NotNull |
| private String required;</demo-highlight> |
| <tc:form id="required"> |
| <tc:in id="in1" label="Input (required)" value="#{validationJsr303Controller.required}"/> |
| <tc:button id="submit1" label="Submit"/> |
| </tc:form> |
| </tc:section> |
| |
| <tc:section label="Length"> |
| <p>The length of the given string must be between 2 and 4 characters.</p> |
| <demo-highlight language="markup"><tc:in label="Input" value="\#{validationJsr303Controller.length}"/></demo-highlight> |
| <demo-highlight language="java">@Size(min = 2, max = 4, message = "Length must be between 2 and 4") |
| private String length;</demo-highlight> |
| <tc:form id="length"> |
| <tc:in id="in2" label="2 to 4 Character" value="#{validationJsr303Controller.length}"/> |
| <tc:button id="submit2" label="Submit"/> |
| </tc:form> |
| </tc:section> |
| </ui:composition> |