Dynamic Data Exercise
MaestroThe UI design product. |
Form Builder | All versions
This feature is related to all versions.
Here you can follow instructions to build a small demonstration form and a Fluent Groovy Service the form can call to fetch dynamic data.
The service returns the value of a Form Space property to the caller. The form calls the service from the Form Load Rule using DynamicData.call
, and there is a Dynamic Data Button that will call the same service whenever it is clicked.
- Login to Manager
- Select Forms/Form Spaces from the menu
- Click the 'Web Plug-in' link
- Click the 'Properties' tab
- Click New
- Enter 'test property' as the name
- Select 'String' as the Type
- Enter a value into the Value text area
- Click Save
Write the service
- Login to Manager
- Select Service/All Services from the menu
- Click New
- From Service Type dropdown, select Dynamic Data
- From Service Template, select Fluent Dynamic Data
- Provide the name 'Space Property'
- Select your organization from the dropdown
- Click the Groovy Script tab and paste this code into the Value text box:
import com.avoka.tm.vo.*
import com.avoka.tm.query.PropertyQuery
import javax.servlet.http.*
import groovy.json.JsonBuilder
class FluentDynamicData {
String invoke(SvcDef svcDef, Txn txn, HttpServletRequest request, User user) {
def data = [
success: true,
value: new PropertyQuery().setName(request.getParameter("property")).setSpaceName(request.getParameter("space")).getValue()
]
return new JsonBuilder(data).toPrettyString()
}
}
- Click Save
Test the service
- Click the Unit Test tab and paste this code into the Value text box:
import com.avoka.core.groovy.GroovyLogger as logger
import com.avoka.tm.svc.*
import com.avoka.tm.test.*
import com.avoka.tm.util.*
import com.avoka.tm.vo.*
class UnitTest {
void invoke(SvcDef svcDef, Map testParams) throws Exception {
Txn txn = new MockVoBuilder().createTxnOpened()
MockRequest request = new MockRequest()
Map params = [
"svcDef": svcDef,
"txn": txn,
"request": request,
"user": null
]
request.setParameter("space", "web plug-in")
request.setParameter("property", "test property")
String result = (String) new ServiceInvoker(svcDef).invoke(params)
logger.info result
Path path = new Path(result)
assert path.val('success')
}
}
- Click Save
- Click Run Test
- Login to Maestro
- Click your organization's node in the tree
- Click 'Create Project'
- Enter any name you like
- Click Create
- Click Create Form
- Enter any name you like
- Select 'Maguire – Default form' from the Template dropdown
- Drag a Text Field onto the wireframe below the 'OK, Let's Get Started!' panel
- Rename it to 'Form Loaded Property Value'
- Drag a 'Dynamic Data Button' onto the wireframe below the new text field
- Rename it to 'Fetch Space Property'
- Drag a Text Field onto the wireframe beside the dynamic data button
- Rename it to 'Property Value'
- Drag a Data Field onto the top node of the structure
- Rename it to 'Property Name'
- Add another Data Field - rename it to 'Space Name'
- Add another Data Field – rename it to 'Property Value'
- Click 'Form Options'
- Click 'Form Rules'
- Click 'Create Rule'
- Click 'Load' under the Form category and paste in this code:
DynamicData.call("Space Property", {space:"web plug-in", property:"test property"})
.then(function(response) {
data.formLoadedPropertyValue = response.value
})
- Click Save
- Click Save again
- Drag a Dynamic Data Button onto the wireframe below the Property Value text field
- Rename it to 'Fetch Space Property'
- Expand 'Configuration' in the Properties panel
- Click 'Click To Browse' below 'Input Field Mapping'
- Click 'Add' so there are 2 rows in the mapping table
- Enter 'space' as the key value on the first mapping row
- Make sure the 'Space Name' data field node is visible in the structure tree
- Place the cursor in the 'Field Reference' column of the first mapping row
- Double-click 'Space Name' in the tree – data.spaceName will be set in Field Reference column
- Repeat the process on the second mapping row
- Enter 'property' as the key
- Double-click 'Property Name' - Field Reference will become data.propertyName
- Click Save
- Click 'Click To Browse' below 'Response Field Mapping'
- Map the response field:
- Enter 'value' as the key – this maps the 'value' property in JSON returned by the service
- Double-click 'Property Value' – Field Reference will become
data.propertyValue
- Click Save
- Select 'Build and Render Form' from the Build dropdown in the Maestro menu bar to see that the Form Space property value has been entered into the 'Form Loaded Property Value'.
- Click the 'Fetch Space Property' dynamic data button to see the 'Property Value' text field will be populated with the same property value.
- Go to Manager.
- Change the property value.
- Go back to the Maestro form.
- Click 'Fetch Space Property', without refreshing the page, to see the changed value in the 'Property Value' text field, but the value of 'Form Loaded Property Value' will not have changed.
- Refresh the form and you will see the 'Form Loaded Property Value' changes.
Next, learn how to .