tapestry study---03

来源:互联网 发布:好看的人工智能电影 编辑:程序博客网 时间:2024/05/20 15:38
  1. You can present any object in a TextField, as long as you provide a translator. The TextField will use it to translate the value to a string for display and on form submission, it will use to translate the string input back into an object to store into the value. If a translator can't translate the string into a value, it will act like a validator and record an error. Most translators in Tapystry will treat an empty string as valid and return a null. This is used to allow optional inputs.
  2. To validate the input in a TextField, just specify a list of validators for the TextField. If any validator considers the value invalid, it will record a field tracking in the validation delegate. How can the validator find out the validation delegate to use? It finds it from the surrounding Form component, so you must tell the Form component which validation delegate to use. Most validators in Tapystry will consider null as valid to allow optional inputs. If the input is mandatory, you should use a required validator.
  3. In addition to the TextField component, the DatePicker component and TextArea component also support translation and validation in exactly the same way.
  4. If the validation is not related to a particular input field, you may do it in your submit listener and record the error into the validation delegate yourself.
  5. A validation delegate is just a lisr of field trackings. A field tracking records the name of the HTML input field,the old value (maybe invalid) and an error renderer. This allows us to re-display the page with the invalid inputs and error messages when there are errors. A field tracking is not necessarily an error(i.e.,when the error renderer is null)
  6. Usually you will use a bean to hold the validation delegate and maybe some validators that require complicated initialization. As beans they will be created on demand whenever they're used.Some validators support validation using Javascript. To use this feature, you need to enable clident side validation on the Form component. In addition, you should hava a Body component. In addition to using the validators provided by Tapestry, you can easily carete your own by implementing the validator interface.
  7. To display the first error in the validation delegate,you can use a Delegator component to delegate the rendering to the first non-null error renderer. To display all errors , you need to use a For component to look through all the field trackings. A For component will look through its "source" parameter and render its body for each element.
  8. If you'd like to optionally skip a something in the HTML page,you can use an if component. If the condition is true, it will render its body, Otherwise it will skip it.
  9. You can use a FieldLabel along with a TextFied so that it shows itself in red if the TextField is in error. It checks if the TextField is in error by checking the validation delegate.
  10. You can use informal parameters for many Tapestry component. They will be passed on to the HTML element generated by that component.
原创粉丝点击