|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.jalios.jcms.context.JcmsContext com.jalios.jcms.context.JcmsJspContext com.jalios.jcms.handler.JcmsFormHandler
public abstract class JcmsFormHandler
This abstract class is the super class of all the Form Handler classes (i.e. JavaBean classes used in JSP pages for processing form).
To implement a custom form handler :
processAction()
to check for any operation, validate precondition and perform action,The following example demonstrate uses of a form handler to receive a firstname as an input and when validated display a Hello World message to the user
Java filecom.example.jcmsplugin.hello.HelloWorldHandler.java
:
package com.example.jcmsplugin.hello; import java.io.IOException; import com.jalios.jcms.HttpUtil; import com.jalios.jcms.context.JcmsMessage; import com.jalios.jcms.context.JcmsMessage.Level; import com.jalios.jcms.handler.JcmsFormHandler; import com.jalios.util.Util; public class HelloWorldHandler extends JcmsFormHandler { // Possible operations private boolean opSayHello = false; private boolean opCancel = false; // Member variables private String firstname = null; @Override public boolean processAction() throws IOException { if (validateSayHello()) { return performSayHello(); } if (validateCancel()) { return performCancel(); } return false; } // --------------------------------------------------------------- // Say Hello // --------------------------------------------------------------- public boolean validateSayHello() { if (!opSayHello) { return false; } if (Util.isEmpty(this.firstname)) { addMsg(new JcmsMessage(Level.WARN, glp("jcmsplugin.myplugin.myhandler.missing-firsname"))); return false; } return true; } public boolean performSayHello() throws IOException { // In I18N properties : // jcmsplugin.myplugin.myhandler.say-hello: Hello {0} ! // addMsgSession(request, new JcmsMessage(Level.INFO, glp("jcmsplugin.myplugin.myhandler.say-hello", HttpUtil.encodeForHTML(firstname)))); return false; } // --------------------------------------------------------------- // Cancel // --------------------------------------------------------------- public boolean validateCancel() { return opCancel; } public boolean performCancel() throws IOException { sendRedirect(Util.notEmpty(redirect) ? redirect : "index.jsp"); return true; } // --------------------------------------------------------------- // Setters // --------------------------------------------------------------- public void setOpSayHello(String opSayHello) { this.opSayHello = true; } public void setOpCancel(String opCancel) { this.opCancel = true; } public String getFirstname() { return this.firstname; } public void setFirstname(String firstname) { this.firstname = firstname; } }JSP
sayHello.jsp
:
<%@ include file='/jcore/doInitPage.jsp' %><% %><jsp:useBean id="formHandler" scope="page" class="com.example.jcmsplugin.hello.HelloWorldHandler"><% %><jsp:setProperty name="formHandler" property="request" value="<%= request %>" /><% %><jsp:setProperty name="formHandler" property="response" value="<%= response %>" /><% %><jsp:setProperty name="formHandler" property="*" /><% %></jsp:useBean><% if (formHandler.validate()) { return; } %><%@ include file='/jcore/doEmptyHeader.jsp' %><% %><%@ include file='/jcore/doMessageBox.jsp' %> <div id='hello'> <form action="sayHello.jsp" name="sayHelloForm" method="post"> <%-- Inputs --%> <jalios:widget editor ='<%= AbstractWidget.UI_EDITOR_TEXTFIELD %>' widgetName ='<%= "firstname" %>' formName ='<%= "sayHelloForm" %>' value ='<%= formHandler.getFirstname() %>' label ='<%= glp("ui.adm.mbr-edit.lbl.f-name") %>' printLabel ='<%= true %>' /> <%-- Hidden Inputs --%> <% if (Util.notEmpty(formHandler.getRedirect())) { %> <input type="hidden" name="redirect" value="<%= encodeForHTMLAttribute(formHandler.getRedirect()) %>" /> <% } %> <%-- Buttons --%> <%= WidgetUtil.printHtmlButton("opSayHello", glp("jcmsplugin.btn.sayhello"), true, null, true) %> <%= WidgetUtil.printHtmlButton("opCancel", glp("ui.com.btn.cancel"), true, null, false) %> </form> </div>Data Handlers (handlers inheriting from
EditDataHandler
) must perform
additionnal operation, see corresponding JavaDoc.
Field Summary | |
---|---|
protected HashMap<String,Object> |
contextMap
|
protected HashSet |
editFieldSet
|
protected boolean |
noRedirect
|
protected boolean |
noSendRedirect
|
protected boolean |
popupEdition
|
protected String |
redirect
|
protected boolean |
redirectOnClosePopup
|
static String |
REVISION
|
protected boolean |
workspaceForced
|
Fields inherited from class com.jalios.jcms.context.JcmsJspContext |
---|
AJAX_REQUEST_ATTRIBUTES, BODY_HEADER, CSS_HEADER, cssboMap, cssfoMap, CUSTOM_HEADER, editIcon, HTTPEQUIV_HEADER, httpequivMap, HTTPNAME_HEADER, httpnameMap, initEditIcon, JAVASCRIPT_CODE_SET_ATTRIBUTE, JAVASCRIPT_SET_ATTRIBUTE, jsboSet, jsfoSet, out, pageContext, SHOW_EDIT_ICON, STYLE_HEADER |
Fields inherited from class com.jalios.jcms.context.JcmsContext |
---|
browser, caddy, channel, inFO, initDone, initWorkspace, isAdmin, isAjaxRequest, isDBMember, isDebug, isLogged, loggedMember, request, response, userCountry, userLang, userLocale, workspace |
Fields inherited from interface com.jalios.util.JaliosConstants |
---|
CRLF, MILLIS_IN_ONE_DAY, MILLIS_IN_ONE_HOUR, MILLIS_IN_ONE_MINUTE, MILLIS_IN_ONE_MONTH, MILLIS_IN_ONE_SECOND, MILLIS_IN_ONE_WEEK, MILLIS_IN_ONE_YEAR |
Constructor Summary | |
---|---|
JcmsFormHandler()
|
Method Summary | |
---|---|
protected boolean |
afterValidation(boolean result)
|
protected boolean |
checkMissingField(Object obj,
String prop)
|
protected HashMap<String,Object> |
getControllerContext()
Build a controller context. |
HashSet |
getEditFieldSet()
|
String |
getHiddenField(String name,
boolean value)
|
String |
getHiddenField(String name,
boolean[] array)
|
String |
getHiddenField(String name,
Data value)
|
String |
getHiddenField(String name,
Data[] datas)
|
String |
getHiddenField(String name,
Date value)
|
String |
getHiddenField(String name,
Date[] array)
|
String |
getHiddenField(String name,
double value)
|
String |
getHiddenField(String name,
double[] array)
|
String |
getHiddenField(String name,
int value)
|
String |
getHiddenField(String name,
int[] array)
|
String |
getHiddenField(String name,
long value)
|
String |
getHiddenField(String name,
long[] array)
|
String |
getHiddenField(String name,
String value)
|
String |
getHiddenField(String name,
String[] array)
|
String |
getHiddenFieldML(String name,
HashMap<String,String> map)
|
protected String |
getMainLangValue(String[] array,
boolean trim,
boolean escape)
Returns the first value (i.e. |
protected String[] |
getMainLangValueArray(String[] array,
boolean trim,
boolean escape)
Returns the first values (i.e. |
protected HashMap<String,String> |
getMLMap(String[] array,
boolean trim,
boolean escape)
Returns the ML map (i.e. |
protected HashMap<String,String[]> |
getMLMapArray(String[] array,
boolean trim,
boolean escape)
Returns the ML map (i.e. |
String |
getRedirect()
Get the value of redirect. |
boolean |
getRedirectOnClosePopup()
Return the value indicating whether the redirect value should be applied to the opener when closing the popup edition. |
Workspace |
getWorkspace()
Retrieve the current Workspace variable for this context either from request if inFO or from session if in back office. |
protected void |
init()
Method to implement if you need to initialize your handler from parameter received, prior to all security validation. |
boolean |
isFieldEdition(String field)
|
protected boolean |
isFieldMissing(String field)
Check if the given parameter is present in the query parameters |
boolean |
isPartialFieldEdition()
Returns true if this is a partial field edition (i.e. |
boolean |
isPopupEdition()
|
boolean |
isWorkspaceForced()
|
boolean |
processAction()
Method to be implemented to check/validate action to be performed and process them. |
protected boolean |
processStatus(ControllerStatus status)
Process the ControllerStatus: do nothing if OK, or send on forbidden, or put a warning message in the request. |
void |
sendRedirect(String url)
Redirect current request to given URL. Overrides JcmsContext.sendRedirect(String) to use behavior
provided by sendRedirect(String, boolean) . |
void |
sendRedirect(String url,
boolean checkRedirect)
Set the redirect in the response. |
void |
setEditField(String[] v)
|
void |
setNoRedirect(boolean noRedirect)
Set the value of noRedirect. |
void |
setNoSendRedirect(boolean noSendRedirect)
Set the value of noSendRedirect. |
void |
setPopupEdition(boolean v)
Set where this form handler is being invoked in a popup. |
void |
setRedirect(String url)
Set the value of redirect. |
void |
setRedirectOnClosePopup(boolean redirectOnClosePopup)
Set whether the redirect value should be applied to the opener when closing the popup edition. The value set by this method will be used only when using popup edition ( setPopupEdition(boolean) ). |
void |
setWorkspace(Workspace wspc)
|
void |
setWs(String v)
|
protected String |
updateUploadedField(String fieldName,
String value,
boolean isFileDocument,
boolean override)
Perform upload then, return value of the real File realtive path. |
protected void |
updateUploadedFields(String fieldName,
String[] values,
boolean isFileDocument,
boolean override)
Perform upload then, replace all values with value MultipartRequest.MULTIPART_UPLOAD with the real File realtive path. |
boolean |
validate()
Method invoked by JSP to validate all conditions (authorization, parameters, ...), and eventualy trigger the action that was requested to the handler. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String REVISION
protected String redirect
protected boolean noRedirect
protected boolean noSendRedirect
protected boolean redirectOnClosePopup
protected boolean workspaceForced
protected boolean popupEdition
protected HashSet editFieldSet
protected HashMap<String,Object> contextMap
Constructor Detail |
---|
public JcmsFormHandler()
Method Detail |
---|
protected void init()
You must absolutely not perform any action which modify data or site configuration.
Therefore it is strongly recommend NOT TO implement this method, or use
very wisely.
public boolean validate() throws IOException
You MUST not override this method to validate and perform your action, instead
implement processAction()
if you need to provide custom actions.
As of current implementation, this method is NOT final to ensure backward compatibility with older handler which may have had a validate() method. But it WILL end as a final method.
IOException
- if error occured during validateprotected boolean afterValidation(boolean result) throws IOException
IOException
public boolean processAction() throws IOException
Default implementation is to return false. No need to call super method.
This method may NOT be invoked at all if security validation are not met.
You must ensure your handler and JSP can work properly without any code invoked
in this method.
IOException
public Workspace getWorkspace()
JcmsContext
getWorkspace
in class JcmsContext
public boolean isWorkspaceForced()
public void setWorkspace(Workspace wspc)
public void setWs(String v)
public void sendRedirect(String url, boolean checkRedirect) throws IOException
url
- the url to redirect to.checkRedirect
- if true and if redirect attribute has been set, redirect on this url
IOException
public void sendRedirect(String url) throws IOException
JcmsContext.sendRedirect(String)
to use behavior
provided by sendRedirect(String, boolean)
.
sendRedirect
in class JcmsContext
url
- the url to redirect to.
IOException
- if an error occured while writing in response headersJcmsContext.sendRedirect(String, HttpServletRequest, HttpServletResponse)
public String getRedirect()
public void setRedirect(String url)
url
- Value to assign to redirect.public void setNoRedirect(boolean noRedirect)
noRedirect
- Value to assign to noRedirect.public void setNoSendRedirect(boolean noSendRedirect)
noSendRedirect
- Value to assign to noSendRedirect.public final void setRedirectOnClosePopup(boolean redirectOnClosePopup)
setPopupEdition(boolean)
).
redirectOnClosePopup
- if true, the redirect value (setRedirect(String)
)
will be provided to closePopup.jsp to redirect the opener. if false,
the popup will simply be closed and the opener refreshed.public final boolean getRedirectOnClosePopup()
setRedirect(String)
)
will be provided to closePopup.jsp to redirect the opener. false,
if the popup will simply be closed and the opener refreshed.protected boolean processStatus(ControllerStatus status) throws IOException
status
- the ControllerStatus to be processed
IOException
protected HashMap<String,Object> getControllerContext()
protected boolean isFieldMissing(String field)
field
- the field to be checked
public void setPopupEdition(boolean v)
v
- true if handler is invoked in popup, false otherwisepublic boolean isPopupEdition()
public void setEditField(String[] v)
v
- a set of field names to editepublic HashSet getEditFieldSet()
public boolean isFieldEdition(String field)
field
-
getEditFieldSet()
public boolean isPartialFieldEdition()
protected String updateUploadedField(String fieldName, String value, boolean isFileDocument, boolean override)
fieldName
- the field namevalue
- the field fake valueprotected void updateUploadedFields(String fieldName, String[] values, boolean isFileDocument, boolean override)
fieldName
- the field namevalues
- the field fake valuesprotected String getMainLangValue(String[] array, boolean trim, boolean escape)
array
- the arraytrim
- if true trim the valueescape
- if true escape the value
protected HashMap<String,String> getMLMap(String[] array, boolean trim, boolean escape)
array
- the arraytrim
- if true trim the valuesescape
- if true escape the values
protected String[] getMainLangValueArray(String[] array, boolean trim, boolean escape)
array
- the arraytrim
- if true trim the valuesescape
- if true escape the values
protected HashMap<String,String[]> getMLMapArray(String[] array, boolean trim, boolean escape)
array
- the arraytrim
- if true trim the valuesescape
- if true escape the values
public String getHiddenField(String name, String value)
public String getHiddenFieldML(String name, HashMap<String,String> map)
public String getHiddenField(String name, Data value)
public String getHiddenField(String name, boolean value)
public String getHiddenField(String name, int value)
public String getHiddenField(String name, double value)
public String getHiddenField(String name, long value)
public String getHiddenField(String name, Date value)
public String getHiddenField(String name, Data[] datas)
public String getHiddenField(String name, boolean[] array)
public String getHiddenField(String name, int[] array)
public String getHiddenField(String name, long[] array)
public String getHiddenField(String name, double[] array)
public String getHiddenField(String name, String[] array)
public String getHiddenField(String name, Date[] array)
protected boolean checkMissingField(Object obj, String prop)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |