com.day.cq.wcm.foundation.forms
Class FormsHelper

java.lang.Object
  extended by com.day.cq.wcm.foundation.forms.FormsHelper

public class FormsHelper
extends Object

Helper class for the forms components.


Field Summary
static String REQ_ATTR_CLIENT_VALIDATION
           
static String REQ_ATTR_FORMID
           
static String REQ_ATTR_FORWARD_PATH
           
static String REQ_ATTR_GLOBAL_LOAD_RSRC
           
static String REQ_ATTR_IS_INIT
           
static String REQ_ATTR_WRITTEN_JAVASCRIPT
           
 
Method Summary
static org.apache.sling.api.resource.Resource checkFormStructure(org.apache.sling.api.resource.Resource rsrc)
          Fix the form.
static String decodeValue(String value)
          Url decode the value.
static boolean doClientValidation(org.apache.sling.api.SlingHttpServletRequest req)
          Are we generating client validation?
static String encodeValue(String value)
          Url encode the value.
static void endForm(org.apache.sling.api.SlingHttpServletRequest req)
          Signal the end of the form.
static Iterator<String> getContentRequestParameterNames(org.apache.sling.api.SlingHttpServletRequest req)
          Return a list of content fields.
static Iterator<org.apache.sling.api.resource.Resource> getFormElements(org.apache.sling.api.resource.Resource formResource)
          Return all form elements for this form.
static String getFormId(org.apache.sling.api.SlingHttpServletRequest req)
          Return the formid
static String getFormsPreCheckMethodName(org.apache.sling.api.SlingHttpServletRequest req)
          Return the name of the check method
static String getForwardPath(org.apache.sling.api.SlingHttpServletRequest req)
          Get the forward path for processing the form.
static org.apache.sling.api.resource.ValueMap getGlobalFormValues(org.apache.sling.api.SlingHttpServletRequest req)
          Return the form values to load.
static Map<String,String> getOptions(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.resource.Resource elementResource)
          Return the options for a form element
static String getParameterName(org.apache.sling.api.resource.Resource rsrc)
          Return the parameter name for the field
static String getTitle(org.apache.sling.api.resource.Resource formElement, String defaultTitle)
          Return the title for the field.
static String getValue(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.resource.Resource elementResource)
          Return the value for the element.
static String[] getValues(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.resource.Resource elementResource)
          Return the values for the element.
static List<String> getValuesAsList(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.resource.Resource elementResource)
          Return the values for the element as a list This method
static boolean hasMultiSelection(org.apache.sling.api.resource.Resource formElement)
          Is this a field with multi selection?
static void includeResource(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response, org.apache.sling.api.resource.Resource resource, String selectorString)
          Include the resource with the given selector with method GET
static boolean isRequired(org.apache.sling.api.resource.Resource formElement)
          Is this field required?
static void redirectToReferrer(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse res)
          Redirect to the referrer.
static void redirectToReferrer(org.apache.sling.api.SlingHttpServletRequest req, org.apache.sling.api.SlingHttpServletResponse res, Map<String,String[]> params)
          Redirect to the referrer.
static void setFormLoadResource(org.apache.sling.api.SlingHttpServletRequest req, org.apache.sling.api.resource.Resource rsrc)
          Set the load resource for the form.
static void setForwardPath(org.apache.sling.api.SlingHttpServletRequest req, String path)
          Set the forward path for processing the form.
static void startForm(org.apache.sling.api.SlingHttpServletRequest req, org.apache.sling.api.SlingHttpServletResponse response, javax.servlet.jsp.JspWriter out)
          Signal the start of the form.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REQ_ATTR_GLOBAL_LOAD_RSRC

public static final String REQ_ATTR_GLOBAL_LOAD_RSRC
See Also:
Constant Field Values

REQ_ATTR_CLIENT_VALIDATION

public static final String REQ_ATTR_CLIENT_VALIDATION
See Also:
Constant Field Values

REQ_ATTR_FORMID

public static final String REQ_ATTR_FORMID
See Also:
Constant Field Values

REQ_ATTR_WRITTEN_JAVASCRIPT

public static final String REQ_ATTR_WRITTEN_JAVASCRIPT
See Also:
Constant Field Values

REQ_ATTR_FORWARD_PATH

public static final String REQ_ATTR_FORWARD_PATH
See Also:
Constant Field Values

REQ_ATTR_IS_INIT

public static final String REQ_ATTR_IS_INIT
See Also:
Constant Field Values
Method Detail

startForm

public static void startForm(org.apache.sling.api.SlingHttpServletRequest req,
                             org.apache.sling.api.SlingHttpServletResponse response,
                             javax.servlet.jsp.JspWriter out)
                      throws IOException,
                             javax.servlet.ServletException
Signal the start of the form. Prepare the request object

Parameters:
req - Request
Throws:
IOException
javax.servlet.ServletException

endForm

public static void endForm(org.apache.sling.api.SlingHttpServletRequest req)
Signal the end of the form.

Parameters:
req - Request

setForwardPath

public static void setForwardPath(org.apache.sling.api.SlingHttpServletRequest req,
                                  String path)
Set the forward path for processing the form.

Parameters:
req - The current request.
path - The forward path.

getForwardPath

public static String getForwardPath(org.apache.sling.api.SlingHttpServletRequest req)
Get the forward path for processing the form.

Parameters:
req - The current request.
Returns:
The forward path or null.

setFormLoadResource

public static void setFormLoadResource(org.apache.sling.api.SlingHttpServletRequest req,
                                       org.apache.sling.api.resource.Resource rsrc)
Set the load resource for the form.

Parameters:
req - The current request.
rsrc - The load resource

getFormsPreCheckMethodName

public static String getFormsPreCheckMethodName(org.apache.sling.api.SlingHttpServletRequest req)
Return the name of the check method

Parameters:
req - The current request.
Returns:
The m,ethod name

includeResource

public static void includeResource(org.apache.sling.api.SlingHttpServletRequest request,
                                   org.apache.sling.api.SlingHttpServletResponse response,
                                   org.apache.sling.api.resource.Resource resource,
                                   String selectorString)
                            throws IOException,
                                   javax.servlet.ServletException
Include the resource with the given selector with method GET

Parameters:
request - The current request.
response - The current response.
resource - The resource to include.
selectorString - The selector string to use for inclusion.
Throws:
IOException
javax.servlet.ServletException

getGlobalFormValues

public static org.apache.sling.api.resource.ValueMap getGlobalFormValues(org.apache.sling.api.SlingHttpServletRequest req)
Return the form values to load.

Parameters:
req - The request
Returns:
The values or null

doClientValidation

public static boolean doClientValidation(org.apache.sling.api.SlingHttpServletRequest req)
Are we generating client validation?

Parameters:
req - Request
Returns:
true or false

getFormId

public static String getFormId(org.apache.sling.api.SlingHttpServletRequest req)
Return the formid

Parameters:
req - Request
Returns:
The form id or null

getParameterName

public static String getParameterName(org.apache.sling.api.resource.Resource rsrc)
Return the parameter name for the field

Parameters:
rsrc -
Returns:
The parameter name.

getFormElements

public static Iterator<org.apache.sling.api.resource.Resource> getFormElements(org.apache.sling.api.resource.Resource formResource)
Return all form elements for this form.

Parameters:
formResource - The form resource-
Returns:
An iterator for all form elements.

getContentRequestParameterNames

public static Iterator<String> getContentRequestParameterNames(org.apache.sling.api.SlingHttpServletRequest req)
Return a list of content fields. This method returns all field names (= request parameter names) that contain actually content by filtering out special request parameters like those starting with a ":", "_charset_" etc.

Returns:
Iterator for the field names.

getValue

public static String getValue(org.apache.sling.api.SlingHttpServletRequest request,
                              org.apache.sling.api.resource.Resource elementResource)
Return the value for the element. This method invokes getValues(SlingHttpServletRequest, Resource) and returns if available the first value from the array.

Parameters:
request - The current request.
elementResource - The element resource.
Returns:
The value for the form element or null.

getValues

public static String[] getValues(org.apache.sling.api.SlingHttpServletRequest request,
                                 org.apache.sling.api.resource.Resource elementResource)
Return the values for the element. This method

Parameters:
request - The current request.
elementResource - The element resource.
Returns:
The values for the form element or null.

getValuesAsList

public static List<String> getValuesAsList(org.apache.sling.api.SlingHttpServletRequest request,
                                           org.apache.sling.api.resource.Resource elementResource)
Return the values for the element as a list This method

Parameters:
request - The current request.
elementResource - The element resource.
Returns:
The values for the form element or an empty list.

getOptions

public static Map<String,String> getOptions(org.apache.sling.api.SlingHttpServletRequest request,
                                            org.apache.sling.api.resource.Resource elementResource)
Return the options for a form element

Parameters:
request -
elementResource -
Returns:
A map of options (key-value) or null.

isRequired

public static boolean isRequired(org.apache.sling.api.resource.Resource formElement)
Is this field required?

Parameters:
formElement - The form element.
Returns:
true if the field is required, false otherwise.

getTitle

public static String getTitle(org.apache.sling.api.resource.Resource formElement,
                              String defaultTitle)
Return the title for the field.

Parameters:
formElement - The form element.
defaultTitle - The default title.
Returns:
The title to display.

hasMultiSelection

public static boolean hasMultiSelection(org.apache.sling.api.resource.Resource formElement)
Is this a field with multi selection?

Parameters:
formElement - The form element

redirectToReferrer

public static void redirectToReferrer(org.apache.sling.api.SlingHttpServletRequest req,
                                      org.apache.sling.api.SlingHttpServletResponse res,
                                      Map<String,String[]> params)
                               throws IOException
Redirect to the referrer. This method redirects to the referer and adds optional request parameters.

Parameters:
req - The current request
res - The current response
Throws:
IOException

redirectToReferrer

public static void redirectToReferrer(org.apache.sling.api.SlingHttpServletRequest request,
                                      org.apache.sling.api.SlingHttpServletResponse res)
                               throws IOException
Redirect to the referrer. This method redirects to the referrerand copies the request parameters.

Parameters:
request - The current request
res - The current response
Throws:
IOException
Since:
5.2

checkFormStructure

public static org.apache.sling.api.resource.Resource checkFormStructure(org.apache.sling.api.resource.Resource rsrc)
Fix the form. When a form start is added, add automatically a forms end (if missing) When only a form end is on the page remove it

Since:
5.2

encodeValue

public static String encodeValue(String value)
Url encode the value. The value is encoded with character set UTF-8.

Parameters:
value - The value
Returns:
The encoded value.
Since:
5.2

decodeValue

public static String decodeValue(String value)
Url decode the value. The value is decoded with character set UTF-8.

Parameters:
value - The value
Returns:
The decoded value.
Since:
5.2


Copyright © 2009 Day Management AG. All Rights Reserved.