|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.taursys.xml.Component com.taursys.xml.Container com.taursys.xml.DispatchingContainer com.taursys.xml.DocumentElement com.taursys.xml.Form com.taursys.servlet.ServletForm
ServletForm is the base container invoked used by Servlet application. It contains all the components that make up the form. The ServletForm is responsible for servicing requests which are routed to it by the ServletApp.
Your servlet forms will typically extend this base class. The ServletForm
provides a default processing cycle within the doGet
method.
The ServletForm is composed of many subcomponents to support the processing of the request: ParameterDispatcher, InputDispatcher, RenderDispatcher, TriggerDispatcher, DocumentAdapter and Responder.
You must supply this ServletForm with a DOM Document. There are a variety of ways you can achieve this: 1) use a DOM parser such as Xerces, 2) use a DOM compiler such as Enhydra's XMLC, 3) build the DOM programatically.
The Document is normally created and attached to this ServletForm in the
initForm
method. This method is normally only called once when
the ServletForm is first invoked. Below is an example using the Xerces
parser:
protected void initForm() throws Exception { super.initForm(); DOMParser parser = new DOMParser(); InputSource is = new InputSource(getClass().getResourceAsStream("MyPage.html")); parser.parse(is); this.setDocument(parser.getDocument()); }In typical applications, you will add Components to this ServletForm and set their properties to bind to the DOM Document elements, http request parameters, and value objects. These components are capable of modifying the DOM Document, storing and retrieving value from bound objects, and reading parameters from the http request, and parsing/converting between text values and java data types. This ServletForm is the base container for these components and contains dispatchers which dispatch events to the components. This ServletForm generates the events within the
doGet
method
in a fixed sequence (see javadoc for doGet).
The below example creates a HTMLInputText component which binds to an HTML form input text field. It also binds to the lastName property of a Java value object class.
public class MyPage extends ServletForm { HTMLInputText lastName = new HTMLInputText(); VOValueHolder person = new VOValueHolder(); public MyPage() { lastName.setPropertyName("lastName"); lastName.setValueHolder(person); lastName.setId("lastName"); this.add(lastName); } ... protected void openForm() throws Exception { // Retrieve or create the value object Person personVO = new Person(1629, "Pulaski", "Katherine", null); // Bind value object to person ValueHolder person.setValueObject(personVO); }There are many components you can use in a ServletForm. These include: Parameter, Template, TextField, Trigger, Button, HTMLAnchorURL, HTMLCheckBox, HTMLInputText, HTMLSelect, HTMLTextArea, and others.
You can control the response of this ServletForm by changing the Responder subcomponent at runtime. The default Responder is an HTMLResponder which sends the DOM Document as the response.
The ServletForm is a reusable object. The ServletApp (master servlet) will
normally recycle ServletForms for an application unless their
recycle
method returns false. The recycle method dispatches
a RecycleEvent to all components.
The ServletForm also supports multipart type requests. A multipart request is sent by the browser when form data contains 1 or more uploaded files. To support this feature, if the incoming request has a content type of "multipart/form-data", the request is wrapped in another request object which is capable of processing multipart requests. The wrapper request is created via the createRequestWrapper method. By default, createRequestWrapper returns a HttpMultiPartServletRequest object which has a maximum file size of 1 megabyte and maximum single line size of 4,096 bytes. You can change this by overriding the createRequestWrapper method:
protected HttpServletRequest createRequestWrapper(HttpServletRequest rq) throws Exception { HttpMultiPartServletRequest multi = new HttpMultiPartServletRequest(rq); // set maximum sizes if defaults if needed multi.setMaxFileSize(2048); multi.setMaxLineLength(80); // parse the request multi.parseRequest(); return multi; }
HttpMultiPartServletRequest
Field Summary |
Fields inherited from class com.taursys.xml.Form |
PARAMETER_MAP |
Constructor Summary | |
ServletForm()
Creates new servlet form and default dispatchers. |
Method Summary | |
protected Responder |
createDefaultResponder()
Creates the default Responder for this component. |
java.util.Map |
createParameterMap()
Create a Map of parameters contained in the request. |
protected javax.servlet.http.HttpServletRequest |
createRequestWrapper(javax.servlet.http.HttpServletRequest rq)
Creates a multipart request wrapper to service a multipart request. |
protected void |
dispatchInitContext()
This method is invoked by run to dispatch the formContext to nested Forms. |
void |
doGet(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
This method is invoked by the application servlet to service the request. |
javax.servlet.http.HttpServletRequest |
getRequest()
Gets the HttpServletRequest object for this ServletForm. |
Responder |
getResponder()
Get the Responder which will provide appropriate response. |
javax.servlet.http.HttpServletResponse |
getResponse()
Gets the HttpServletResponse object for this ServletForm. |
protected void |
handleException(java.lang.Exception ex)
This method is invoked whenever an exception occurs within doGet. |
boolean |
isEnableActions()
Get enableActions flag indicating whether or not to process actions. |
boolean |
isEnableInput()
Get enableInput flag indicating whether or not to process input. |
protected void |
processInitContextEvent(InitContextEvent e)
Processes a given InitContextEvent by setting the formContext ,
parameterMap , request and response
from the given message, then dispatching an InitContextEvent
to the Form's children, and finally propagating the
InitContextEvent to registered listeners. |
boolean |
recycle()
Dispatches a RecycleEvent to all components and returns true if successful. |
protected void |
sendResponse()
Send the appropriate response. |
void |
setEnableActions(boolean newEnableActions)
Set enableActions flag indicating whether or not to process actions. |
void |
setEnableInput(boolean newEnableInput)
Set enableInput flag indicating whether or not to process input. |
void |
setRequest(javax.servlet.http.HttpServletRequest newRequest)
Sets the HttpServletRequest object for this ServletForm. |
void |
setResponder(Responder newResponder)
Set the Responder which will provide appropriate response. |
void |
setResponse(javax.servlet.http.HttpServletResponse newResponse)
Sets the HttpServletResponse object for this ServletForm. |
void |
testFullCycle(java.lang.String outputFile)
Testing method to initialize, open and render the form to the screen and to a file if given. |
java.lang.String |
toString()
Returns a string representation of this object. |
Methods inherited from class com.taursys.xml.DispatchingContainer |
add, createInputDispatcher, createParameterDispatcher, createRecycleDispatcher, createRenderDispatcher, createTriggerDispatcher, dispatchActions, dispatchInput, dispatchParameters, dispatchRecycle, dispatchRender, getParameterMap, processInputEvent, processParameterEvent, processTriggerEvent, setParameterMap |
Methods inherited from class com.taursys.xml.Container |
addDispatcher, contains, get, getComponents, getDispatcher, getDispatchers, getInputDispatcher, getParameterDispatcher, getRecycleDispatcher, getRenderDispatcher, getTriggerDispatcher, remove, removeDispatcher, setComponents |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public ServletForm()
Method Detail |
public boolean recycle()
public void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws java.lang.Exception
req
- the incoming HttpServletRequestresp
- the outgoing HttpServletResponse
java.lang.Exception
- if problem during processing the requestprotected void dispatchInitContext() throws java.lang.Exception
ServletForm's
plus the request, response and
parameterMap.
dispatchInitContext
in class Form
java.lang.Exception
protected void sendResponse() throws java.lang.Exception
java.lang.Exception
protected void handleException(java.lang.Exception ex) throws java.lang.Exception
java.lang.Exception
protected javax.servlet.http.HttpServletRequest createRequestWrapper(javax.servlet.http.HttpServletRequest rq) throws java.lang.Exception
com.taursys.servlet.HttpMultiPartServletRequest
and invokes
its parseRequest()
method.
You can override this method to create and initialize your own default
request wrapper.
java.lang.Exception
- if problem creating or initializing request wrapperprotected Responder createDefaultResponder()
public java.util.Map createParameterMap()
protected void processInitContextEvent(InitContextEvent e) throws java.lang.Exception
formContext
,
parameterMap
, request
and response
from the given message, then dispatching an InitContextEvent
to the Form's
children, and finally propagating the
InitContextEvent
to registered listeners.
processInitContextEvent
in class Form
e
- the InitContextEvent to process
java.lang.Exception
public void setRequest(javax.servlet.http.HttpServletRequest newRequest)
newRequest
- the HttpServletRequest object for this ServletFormpublic javax.servlet.http.HttpServletRequest getRequest()
public void setResponse(javax.servlet.http.HttpServletResponse newResponse)
newResponse
- the HttpServletResponse object for this ServletFormpublic javax.servlet.http.HttpServletResponse getResponse()
public void setEnableInput(boolean newEnableInput)
true
.
newEnableInput
- flag indicating whether or not to process input.public boolean isEnableInput()
true
.
public void setEnableActions(boolean newEnableActions)
true
.
newEnableActions
- flag indicating whether or not to process actions.public boolean isEnableActions()
true
.
public void setResponder(Responder newResponder)
newResponder
- the Responder which will provide appropriate response.public Responder getResponder()
public java.lang.String toString()
toString
in class Form
public void testFullCycle(java.lang.String outputFile) throws java.lang.Exception
outputFile
- full path of file to write to or null
java.lang.Exception
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |