Interface BeanHandler
- All Known Implementing Classes:
AbstractBeanHandler
,BeanHandlerHtml
,BeanHandlerPlain
,BeanHandlerXml
- Since:
- 1.0
-
Method Summary
Modifier and TypeMethodDescriptionReturns a form builder which will be used to generate forms in the corresponding template.void
removeBean
(Template template, Object bean, String prefix) Reverts all values to their defaults when the identifiers match properties of the given bean preceded by the given prefix, whether those values were set with a previous call toTemplate.setBean(Object)
.void
Sets all values in the given template whose names match names of properties in the given bean, preceded by the given prefix, if present.
-
Method Details
-
setBean
void setBean(Template template, Object bean, String prefix, boolean encode) throws TemplateException Sets all values in the given template whose names match names of properties in the given bean, preceded by the given prefix, if present. If the given prefix isnull
, it is ignored.For example, given a class:
class Person { private String first; private String last; public String getFirstName() { return first; } public void setFirstName(String name) { this.first = name; } public String getLastName() { return last; } public void setLastName(String name) { this.last = name; } }
And given a template:
Hello <!--V 'NAME:firstName'/--> <!--V 'NAME:lastName'/-->.
Calling this method with an instance of Person where
first
was "Jim
" andlast
was "James
", and the prefix "NAME:
", would produce:Hello Jim James.
Calling this method is equivalent to calling
setValue
individually for each property of the bean prefixed with the given prefix.If
encode
istrue
, this method will use the template's encoder to encode the bean properties before setting the values.Only bean properties will be considered for insertion in the template. This means only properties with a getter and a setter will be considered.
- Parameters:
template
- the template whose values will be filledbean
- a bean whose properties will be used to fill in values in the templateprefix
- the prefix of values which will be filled with the given bean's property values- Throws:
TemplateException
- if this template has no bean handling capability; oran error occurred during the introspection of the bean
- Since:
- 1.0
-
removeBean
Reverts all values to their defaults when the identifiers match properties of the given bean preceded by the given prefix, whether those values were set with a previous call toTemplate.setBean(Object)
. The values of the bean's properties are ignored.Calling this method is equivalent to calling
Template.removeValue(java.lang.String)
once for the name of each property of the given bean, prefixed with the given prefix.- Parameters:
bean
- a bean whose property names will be used to determine whetherprefix
- a prefix- Throws:
TemplateException
- if this template has no bean handling capability; oran error occurred during the introspection of the bean
- Since:
- 1.0
-
getFormBuilder
FormBuilder getFormBuilder()Returns a form builder which will be used to generate forms in the corresponding template.- Returns:
- a form builder for use with the corresponding template
- Since:
- 1.0
-