|
Version 4.10.0 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Object SimpleTagSupport hirondelle.web4j.ui.tag.TagHelper hirondelle.web4j.ui.tag.Populate
public final class Populate
Custom tag which populates form controls in a simple, elegant way.
From the point of view of this tag, there are 3 sources of data for a form control:
For reference, here is the logic that defines which data source is used, and related naming conventions :
if a Model Object of the given name is in any scope { override the default HTML for each control use the Model Object (match control names to getXXX methods of the Model Object) } else if the request is a POST { override the default HTML for each control must populate every control using request parameter values (match control names to request param names) } else if the request is a GET { if control name has a matching req param name { override the default HTML for each control populate control using request parameter values (match control names to request param names) } else { use the default HTML for that control } }
This tag simply wraps static HTML forms. This is very economical since it does not force the page author to completely replace well-known static HTML with a large set of custom tags.
ActionTemplateListAndEdit
action.)
<c:url value="RestoAction.do" var="baseURL"/> <form action='${baseURL}' method="post" class="user-input"> <w:populate using="itemForEdit"> <input name="Id" type="hidden"> <table align="center"> <tr> <td><label>Name</label> *</td> <td><input name="Name" type="text"></td> </tr> <tr> <td><label>Location</label></td> <td><input name="Location" type="text"></td> </tr> <tr> <td><label>Price</label></td> <td><input name="Price" type="text"></td> </tr> <tr> <td><label>Comment</label></td> <td><input name="Comment" type="text"></td> </tr> <tr> <td align="center" colspan=2> <input type='submit' value="Edit"> </td> </tr> </table> </w:populate> <tags:hiddenOperationParam/> </form>Here, the itemForEdit Model Object has the following methods, corresponding to the above populated controls :
public Id getId() {...} public SafeText getName() {...} public SafeText getLocation() {...} public BigDecimal getPrice() {...} public SafeText getComment() {...}
Operation
is performed. In this case, a form with method="GET" is used
to specify parameters to a SELECT statement.
Here is an example of a form used only for 'add' operations :
<w:populate> <c:url value="AddMessageAction.do?Operation=Apply" var="baseURL"/> <form action='${baseURL}' method=post class="user-input"> <table align="center"> <tr> <td> <label>Message</label> * </td> </tr> <tr> <td> <textarea name="Message Body"> </textarea> </td> </tr> <tr> <td colspan=2> <label>Preview First ?</label> <input type="radio" name="Preview" value="true"> Yes </td> </tr> <tr> <td align="center" colspan=2> <input type="submit" value="Add Message"> </td> </tr> </table> </form> </w:populate>
The following form input items are called supported controls here, and include all items which undergo population by this class :
Population is implemented by editing these supported control attributes :
The body of this tag is HTML, with the following minor restrictions:
Warning: unfortunately, INPUT controls of type color and range can't represent nullable items in a database. This is because the (draft) HTML5 specification doesn't allow such controls to POST non-empty values when forms are submitted. The only workaround for this defect of the specification is to define magic values which map to null. Use such controls with caution.
RequestParameter
.
Formats.objectToText(java.lang.Object)
method is then used to
translate the object into text. If the return value of the getXXX is a
Collection, then the above is applied to each element.
EscapeChars.forHTML(String)
.
Constructor Summary | |
---|---|
Populate()
|
Method Summary | |
---|---|
protected String |
getEmittedText(String aOriginalBody)
Emit the possibly-changed body of this tag, by possibly editing supported form controls contained in the body of this tag. |
void |
setUsing(String aModelObjectKey)
Key for the Model Object to be used for form population. |
Methods inherited from class hirondelle.web4j.ui.tag.TagHelper |
---|
checkForContent, crossCheckAttributes, doTag, getPageContext, getPageName, getRequest, getResponse |
Methods inherited from class SimpleTagSupport |
---|
findAncestorWithClass, getJspBody, getJspContext, getParent, setJspBody, setJspContext, setParent |
Methods inherited from class Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Populate()
Method Detail |
---|
public void setUsing(String aModelObjectKey)
This attribute is specified only if the form can be used to edit or change an existing Model Object. If the Model Object is present, then it will be used by this tag to populate supported controls.
This tag searches for the Model Object in the same way as JspContext.findAttribute(String), by searching scopes in a specific order : page scope, request scope, session scope, and finally application scope.
aModelObjectKey
- satisfies Util.textHasContent(String)
.protected String getEmittedText(String aOriginalBody) throws JspException
getEmittedText
in class TagHelper
aOriginalBody
- is the evaluated body of this tag. If there is no body, or
if the body is present but empty, then it is null.
JspException
|
Version 4.10.0 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |