The remainder of this appendix describes how to use the MapXMLBuilder
class through several illustrative examples. Note that in the JSP fragments ${FH}
is a variable created elsewhere on the page; its value is the full Nucleus pathname of the form handler.
Simple Tags
The first example generates this relatively simple strprop
tag:
<strprop op="equal" name="childSKU.color"> rose </strprop>
The JSP looks like this:
<-- Create the <strprop> tag --> <dspel:input type="hidden" bean="${FH}.documentSetsBuilder.tags.myTag.tagname" value="strprop"> <-- Add the <strprop op="equal"> attribute --> <dspel:input type="hidden" bean="${FH}.documentSetsBuilder.tags.myTag.attr.op" value="equal"> <-- Add the <strprop name="childSKU.color"> attribute --> <dspel:input type="hidden" bean="${FH}.documentSetsBuilder.tags.myTag.attr.name" value="childSKU.color"> <-- Finally, the <strprop> tag's body --> <dspel:input type="hidden" bean="${FH}.documentSetsBuilder.tags.myTag.body" value="rose">
Note that myTag
is an arbitrary string identifier for a given tag on the page. This value is not rendered in the XML output; it merely serves as a way to distinguish between multiple tags at the same level.
The JSP fragment above illustrates how the basic components of any tag are specified on the page:
| The input tag’s |
| The input tag’s |
| The input tag’s |
Nested Tags
This example illustrates the generation of two property constraints tags nested within a Boolean <and>
tag:
<and> <strprop op="equal" name="childSKU.color"> rose </strprop> <numprop op="lesseq" name="childSKU.price"> 30.00 </numprop> </and>
The JSP looks like this:
<-- Create the outer <and> tag --> <dspel:input type="hidden" bean="${FH}.documentSetsBuilder.tags.andTag.tagname" value="and"> <-- Create the nested <strprop> tag --> <dspel:input type="hidden" bean="${FH}.documentSetsBuilder.tags.andTag.strp.tagname" value="strprop"> <-- Add the <strprop op="equal"> attribute --> <dspel:input type="hidden" bean="${FH}.documentSetsBuilder.tags.andTag.strp.attr.op" value="equal"> <-- Add the <strprop name="childSKU.color"> attribute --> <dspel:input type="hidden" bean="${FH}.documentSetsBuilder.tags.andTag.strp.attr.name" value="childSKU.color"> <-- Add the <strprop> tag's body --> <dspel:input type="hidden" bean="${FH}.documentSetsBuilder.tags.andTag.strp.body" value="rose"> <-- Create the nested <numprop> tag --> <dspel:input type="hidden" bean="${FH}.documentSetsBuilder.tags.andTag.nump.tagname" value="numprop"> <-- Add the <strprop op="lesseq"> attribute --> <dspel:input type="hidden" bean="${FH}.documentSetsBuilder.tags.andTag.nump.attr.op" value="equal"> <-- Add the <strprop name="childSKU.price"> attribute --> <dspel:input type="hidden" bean="${FH}.documentSetsBuilder.tags.andTag.nump.attr.name" value="childSKU.price"> <-- Finally, the <strprop> tag's body --> <dspel:input type="hidden" bean="${FH}.documentSetsBuilder.tags.andTag.nump.body" value="30.00" >
Things to note from this example
You don’t need to explicitly close XML tags, because tag hierarchy is defined in the
bean
attribute values of the input tags.The value of the
type
attribute need not be"hidden"
. For example, thebody
input tags for each of the two nested tags could be normal input fields, to allow the user to input the color and maximum price.
Conditionally Rendered Tags
There may be times when the decision to generate one or more tags cannot be made when the page is rendered. Specifically, it may be undesirable to generate tags meant to capture user input when no input is provided. In the example below, if the user does not enter a value for the product color, childSKU.color
, then the constraint tag should not be generated.
The conditionally generated strprop
tag:
<strprop op="equal" name="childSKU.color"> value from user input, if provided </strprop>
The JSP:
<-- Create the <strprop> tag --> <dspel:input type="hidden" bean="${FH}.documentSetsBuilder.tags.myTag.tagname" value="strprop"> <-- Add the <strprop op="equal"> attribute --> <dspel:input type="hidden" bean="${FH}.documentSetsBuilder.tags.myTag.attr.op" value="equal"> <-- Add the <strprop name="childSKU.color"> attribute --> <dspel:input type="hidden" bean="${FH}.documentSetsBuilder.tags.myTag.attr.name" value="childSKU.color"> <-- The user input field, in this case the <strprop> tag's body --> <dspel:input type="text" bean="${FH}.documentSetsBuilder.tags.myTag.body"> <-- The conditional generation option: generate only if user enters a value for the tag body --> <dspel:input type="hidden" bean="${FH}.documentSetsBuilder.tags.myTag.opts.generate" value="ifvalue:body">
Things to note from this example:
The
tagname
.opts
values are used to specify tag generation options toMapXMLBuilder
. These values do not appear in the generated XML.Currently, the only valid option directive is
generate
. The valid options for thegenerate
directive are:true
-- Generate the tag (the default).false
-- Do not generate the tag.ifchild
-- Generate the tag only if it will contain any child tags. Use this option to prevent the generation of an empty outer tag when none of its child tags are generated.ifvalue:
tagElement
-- Generate the tag iftagIdentifier
.
tagElement
is not empty. ThetagElement
value can use dot notation to specify subproperties; for example,ifvalue:body
, orifvalue:attr.op
.ifbody
-- Generate iftagIdentifier
.
body
is not empty. Shorthand forifvalue:body
.If a parent tag is not generated, none of its child tags are generated, regardless of the values of the child tags generate directives.