-
Rendered into HTML
-
Rendered into Mails
-
Rendered into PDF
-
Rendered into CSV
Form Validation
When saving an object, errors are reported, localized, with no additional cost…
See Grails documentation on Constraints Usage to check your object validity before saving.
Code Sample
def userForm(User user) {
user ?= new User(params)
UiFormSpecifier f = new UiFormSpecifier() (1)
f.ui user, { (2)
section "User", { (3)
field user.username_ (4)
field user.firstName_
field user.lastName_
ajaxField user.manager_, (5)
this.&selectUserM2O as MC
field user.password_
}
section "Coords", {
field user.businessUnit_
field user.mail_
field user.subsidiary_
}
section "Status", {
field user.enabled_
field user.accountExpired_
field user.accountLocked_
field user.passwordExpired_
}
formAction this.&saveUser as MC, (6)
user.id
}
taackUiService.show new UiBlockSpecifier().ui { (7)
modal {
form f
}
} (8)
}
| 1 | Create the form |
| 2 | Pass object to be edited and spec of the form |
| 3 | Section called user |
| 4 | Basic field, terminating with an underscore, those symbols are generated by Taack AST on class with the TaackFieldEnum annotation |
| 5 | Many-To-One relation, the action selectUserM2O will open a popup to select the manager of the user |
| 6 | Specify an action where the form will be sent to. Here it is saveUser, it will save the user |
| 7 | Create the block in a modal |
| 8 | Display it … |
Asciidoc
You can add an asciidoc editor by creating an EditorOption object and pass it to fieldEditorFromMap or fieldEditor.
This editor can import images dropped in the text area and import ODF files (image included).
Create EditorOption object
EditorOption.EditorOptionBuilder editor = EditorOption.getBuilder()
editor.addSpanRegexes(TaackBaseAsciidocSpans.spans)
editor.addSpanRegexes(TaackAsciidocTable.spans)
editor.addSpanRegexes(TaackAsciidocPlantUML.spans)
editor.uploadFileAction(this.&dropEditor as MC, [cmsPage: cmsPage.id])
fieldEditor cmsPage.bodyContent_, editor.build()
innerFormAction this.&previewBody as MC
Create dropEditor action
@Transactional
def dropEditor() {
CmsPage page = CmsPage.get(params.long('cmsPage'))
params.remove('cmsPage')
if (params.get('onpaste')) {
render "${convertersToAsciidocService.convertFromHtml(params.get('onpaste') as String)}"
} else {
final List<MultipartFile> mfl = (request as MultipartHttpServletRequest).getFiles('filePath')
final mf = mfl.first()
if ([AttachmentContentType.SHEET_ODS.mimeType, AttachmentContentType.LO_TEXT.mimeType].contains(mf.contentType)) {
render convertersToAsciidocService.convert(page, mf.inputStream)
} else {
CmsImage cmsImage = taackSaveService.save(CmsImage)
if (cmsImage && page) {
cmsImage.cmsPage = page
}
render "image::${cmsImage.originalName}[]" (1)
}
}
}
| 1 | Render asciidoc code that will be displayed in the editor |
Import images via a custom service
Use taackEditorService to convert page, and save images in files dropped to your custom object.
String convert(CmsPage page, InputStream inputStream) {
taackEditorService.convert(new TaackEditorService.ISaveImage() {
@Override
String saveImage(String imagePath, byte[] image) {
return saveImage(page, imagePath, image) (1)
}
}, inputStream)
}
String convertFromHtml(String html) {
taackEditorService.convertFromHtml(html)
}
| 1 | Images will be attached to the page object. |
DSL Symbols Hierarchy
DSL Elements
Inputs
-
hiddenField: add an input of type hidden into the form. -
field: add an input with a label. -
ajaxField: add a many 2 many to one field. The MethodClosure must point to a block showing a modal window
Structure
-
section: add a form section, optionally Width of the section -
col: Allows a splitting section into columns
Action
-
formAction: Label, action called, params of the action (either id and map), is ajax