This is a FirstSpirit form field mapper that transfer data from a java class via annotations to a form field and vise versa.
- Map different kind of java types from and to java class via annotations
- String <-> String
- Date <-> Date
- Boolean <-> Boolean
- Number<-> Number
- String (HTML) <-> DomElement
- Collection <-> FormDataList (inline, database)
- String <-> Option
- Entity (native, database) <-> Option
- Collection <-> Collection
- Collection ((native, database) <-> Collection
- DatasetContainer <-> Class
- Annotations can be used in Setter, Getter or accessible class attributes
- Map nested java classes for example FirstSpirit FormDataList with section templates
- Maven is required
- Git is required
- Clone project via git because no public artifact is available.
<dependency> <groupId>com.diva-e.firstspirit</groupId> <artifactId>form-field-mapper</artifactId> <version>${form-field-mapper-version}</version> </dependency>
Usage start with creation of a reusable (stateless) FormFieldMapper instance:
FormFieldMapper formFieldMapper = new FormFieldMapper();
FormData formData = <getFormDataViaAPI()> Language language = <getLanguageForAllFormFieldFromViaAPIOrNull()>
DTO dto = new DTO() { @FormField("<FirstSpiritFormFieldName>") public <SupportedClassOrCollection> attribute; @FormField("<OtherFirstSpiritFormFieldName>") public void setOtherAttribute(<SupportedClassOrCollection> otherAttribute) { ... } }
formFieldMapper.map(formData, dto, language);
DTO dto = new DTO() { @FormField("<FirstSpiritFormFieldName>") public <SupportedClassOrCollection> attribute; @FormField("<OtherFirstSpiritFormFieldName>") public <SupportedClassOrCollection> getOtherAttribute() { ... } }
FormData formData = <getFormDataViaAPI()> Language language = <getLanguageForAllFormFieldFromViaAPIOrNull()>
formFieldMapper.map(dto, formData, language);
@Template("<FirstSpiritTemplateName>") public class Source { @FormField(<FirstSpiritFormFieldName>") public <SupportedClassOrCollection> attribute; }
public class DTO { @FormField(<FirstSpiritFormFieldName>") public Collection<Source> attribute; }
FormData formData = <getFormDataViaAPI()> Language language = <getLanguageForAllFormFieldFromViaAPIOrNull()>
formFieldMapper.map(dto, formData, language);
public static class Source { @FormField(<FirstSpiritFormFieldName>") public <SupportedClass> attribute; } @Database("database") public static class SupportedClass { @FormField(value = "fs_id", isEntityName = true) public Long fsId; }
FormData formData = <getFormDataViaAPI()> Language language = <getLanguageForAllFormFieldFromViaAPIOrNull()>
formFieldMapper.map(dto, formData, language);
You can add new mapping strategies by using this method
FormFieldMapper#addStrategy