BBJSP CommandTags (Deprecated)
The BBJSP system is deprecated. For new development, use BBxServlet.
Description
In BBj 17.0 and higher, the BBJSP Command library provides a common
set of tags that can be used to access information following the execution
of a BBjspCommand.
Creation
Tag libraries need specifically importing into a BBJSP page by using
the taglib directive. Here's an example of how to register this
tag library in your page:
<%@ taglib uri='/WEB-CFG/tld/command.tld' prefix='cmd' %>
The uri
points to the tag library definition within the
web application and the prefix
defines how the tag will be
prefixed in the markup.
Tags
Tag
Name
|
Description
|
Errors
|
Gets the Errors arising from previous
Command execution |
ErrorsAbsent
|
Checks for the absence
of Errors |
ErrorsPresent
|
Checks for the presence
of Errors |
Messages
|
Gets the Messages
arising from previous Command execution |
MessagesAbsent
|
Checks for the absence
of Messages |
MessagesPresent
|
Checks for the presence
of Messages |
Example
<!DOCTYPE html/>
<%-- Import the tag libraries --%>
<%@ taglib uri='/WEB-CFG/tld/core.tld' prefix='c' %>
<%@ taglib uri='/WEB-CFG/tld/command.tld' prefix='cmd' %>
<bbj:widget id="data" source="widgets/Form.bbj" class="Form" />
<html>
<head>
<title><cmd:messages></cmd:messages></title>
<style>
.error {
background-color:#EE0000;
}
</style>
</head>
<body>
<cmd:errorsPresent>
<fieldset>
<legend>The following errors are present</legend>
<ul>
<cmd:errors id="error">
<li>${error}</li>
</cmd:errors>
</ul>
</fieldset>
</cmd:errorsPresent>
<cmd:errorsAbsent>Please complete the Form</cmd:errorsAbsent>
<form action="${ROOT}/demo/validatingCommand.cmd" method="post">
<input type="text" name="forname" id="forname" value="${data["Forname"]}" placeholder="First Name"><cmd:errorsPresent key="forname"> class='error' </cmd:errorsPresent>
/>
<cmd:messages id="msg" key="forname">${msg}</cmd:messages> <br /><br />
<input type="text" name="surname" id="surname" value="${data["Surname"]}" placeholder="Last Name"><cmd:errorsPresent key="surname"> class='error' </cmd:errorsPresent>
/>
<cmd:messages id="msg" key="surname">${msg}</cmd:messages> <br /><br />
<input type="text" name="address1" id="address1" value="${data["Address1"]}" placeholder="Address line 1"><cmd:errorsPresent key="address1"> class='error' </cmd:errorsPresent>
/>
<cmd:messages id="msg" key="address1">${msg}</cmd:messages> <br /><br />
<input type="text" name="address2" id="address2" value="${data["Address2"]}" placeholder="Address line 2" /> <br /><br />
<input type="text" name="city" id="city" value="${data["City"]}" placeholder="City"><cmd:errorsPresent key="city"> class='error' </cmd:errorsPresent>
/>
<cmd:messages id="msg" key="city">${msg}</cmd:messages> <br /><br />
<input type="text" name="state" id="state" value="${data["State"]}" placeholder="State"><cmd:errorsPresent key="state"> class='error' </cmd:errorsPresent>
/>
<cmd:messages id="msg" key="state">${msg}</cmd:messages> <br /><br />
<input type="text" name="zip" id="zip" value="${data["Zip"]}" placeholder="Zip"><cmd:errorsPresent key="zip"> class='error' </cmd:errorsPresent>
/>
<cmd:messages id="msg" key="zip">${msg}</cmd:messages> <br /><br />
<input type="submit" />
</input></input></input></input></input></input></form>
</body>
</html>
|
class public ValidatingCommand
field public BBjspWebRequest Request!
field public BBjspWebResponse Response!
field public BBjspWebSession Session!
method public BBjspCommandResult execute(BBjspCommandContext context!)
declare BBjspCommandResult result!
#Request! = context!.getRequest()
#Response! = context!.getResponse()
#Session! = #Request!.getSession()
result! = context!.getResult()
result!.setForward("fail")
forname$ = #Request!.getParameter("forname")
if (forname$ = "") then
result!.addError("forname","The required <i>First Name</i> field is missing.")
result!.addMessage("forname","MISSING")
endif
surname$ = #Request!.getParameter("surname")
if (surname$ = "") then
result!.addError("surname","The required <i>Last Name</i> field is missing.")
result!.addMessage("surname","MISSING")
endif
address1$ = #Request!.getParameter("address1")
if (address1$ = "") then
result!.addError("address1","The required <i>Address</i> field is missing.")
result!.addMessage("address1","MISSING")
endif
address2$ = #Request!.getParameter("address2")
city$ = #Request!.getParameter("city")
if (city$ = "") then
result!.addError("city","The required <i>City</i> field is missing.")
result!.addMessage("city","MISSING")
endif
state$ = #Request!.getParameter("state")
if (state$ = "") then
result!.addError("state","The required <i>State</i> field is missing.")
result!.addMessage("state","MISSING")
endif
zip$ = #Request!.getParameter("zip")
if (zip$ = "") then
result!.addError("zip","The required <i>Zip</i> field is missing.")
result!.addMessage("zip","MISSING")
endif
result!.addParameter("forname",#Request!.getParameter("forname"))
result!.addParameter("surname",#Request!.getParameter("surname"))
result!.addParameter("address1",#Request!.getParameter("address1"))
result!.addParameter("address2",#Request!.getParameter("address2"))
result!.addParameter("city",#Request!.getParameter("city"))
result!.addParameter("state",#Request!.getParameter("state"))
result!.addParameter("zip",#Request!.getParameter("zip"))
methodret result!
methodend
classend
|
rem '=== THIS CLASS CONTROLS THE IDE FUNCTIONALITY
class public Form
field public BBjString Forname$
field public BBjString Surname$
field public BBjString Address1$
field public BBjString Address2$
field public BBjString City$
field public BBjString State$
field public BBjString Zip$
method public void open(BBjspPageContext context!)
declare BBjspWebRequest request!
request! = context!.getRequest()
#Forname$ = request!.getParameter("forname")
#Surname$ = request!.getParameter("surname")
#Address1$ = request!.getParameter("address1")
#Address2$ = request!.getParameter("address2")
#City$ = request!.getParameter("city")
#State$ = request!.getParameter("state")
#Zip$ = request!.getParameter("zip")
methodend
classend
|
See Also
BBJSP
BBJSP Tag Libraries