public interface TemplateModel extends Serializable
It is also possible to import a Bean's properties to the model using
importBean(String, Object, Predicate)
Supported property types:
Modifier and Type | Method and Description |
---|---|
default <T> List<T> |
getListProxy(String modelPath,
Class<T> beanType)
Gets a proxy of the given part of the model as a list of beans of the
given type.
|
default <T> T |
getProxy(String modelPath,
Class<T> beanType)
Gets a proxy of the given part of the model as a bean of the given type.
|
default void |
importBean(String modelPath,
Object bean,
Predicate<String> propertyNameFilter)
Import a bean properties passing the given filter to this template model.
|
default void |
importBeans(String modelPath,
List<?> beans,
Predicate<String> propertyNameFilter)
Imports a list of beans to this template model.
|
default <T> T getProxy(String modelPath, Class<T> beanType)
You can use this for a type-safe way of updating a bean in the model. You should not use this to update a database entity based on updated values in the model.
The modelPath
is a dot separated set of property names,
representing the location of the bean in the model. The root of the model
is "" and the path "person" represents what getPerson()
would
return. The path "person.address" represents what
getPerson().getAddress()
would return.
public class Address {
private String street;
public String getStreet(){
return street;
}
public void setStreet(String street){
this.street = street;
}
}
public class Person {
private String name;
private Address address;
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
public void setAddress(Address address){
this.address = address;
}
public Address getAddress(){
return address;
}
}
interface MyModel extends TemplateModel {
Person getPerson();
}
T
- the proxy typemodelPath
- a dot separated path describing the location of the bean in
the modelbeanType
- requested bean typemodelPath
default <T> List<T> getListProxy(String modelPath, Class<T> beanType)
You can use this to update the collection or the contents of the collection in the model.
The modelPath
is a dot separated set of property names,
representing the location of the list in the model. The root of the model
is "" and the path "persons" represents what List
<Person> getPersons()
would return.
T
- the proxy typemodelPath
- a dot separated path describing the location of the list in
the modelbeanType
- requested bean typemodelPath
default void importBean(String modelPath, Object bean, Predicate<String> propertyNameFilter)
The given filter should decide based on the bean property name whether that property should be imported to the model. For nested bean properties, the dot annotation is used.
For example, when the given bean
is of type Person, and it
has a property Address address
, the properties inside the
Address
are passed to the given filter prefixed with
address.
. e.g. address.postCode
.
modelPath
- a dot separated path describing the location of the bean in
the modelbean
- the to importpropertyNameFilter
- the filter to apply to the bean's propertiessupported property types
default void importBeans(String modelPath, List<?> beans, Predicate<String> propertyNameFilter)
modelPath
- the path defining which part of the model to import intobeans
- the beans to importpropertyNameFilter
- a filter determining which bean properties to importimportBean(String, Object, Predicate)
,
supported property types
Copyright © 2020. All rights reserved.