Class EditDataFormHandler<T extends Data>

  • Type Parameters:
    T - the type of the value being boxed
    All Implemented Interfaces:
    JcmsConstants, JaliosConstants

    public abstract class EditDataFormHandler<T extends Data>
    extends JcmsUploadFormHandler
    This class is the super class of all FormHandlers which manage stored data.
    Author:
    Nicolas Dos Santos
    • Field Detail

      • FORM_HANDLER_ATTR

        public static final java.lang.String FORM_HANDLER_ATTR
        See Also:
        Constant Field Values
    • Constructor Detail

      • EditDataFormHandler

        public EditDataFormHandler()
      • EditDataFormHandler

        public EditDataFormHandler​(java.lang.Class<T> dataClass)
    • Method Detail

      • getDataClass

        protected java.lang.Class<T> getDataClass()
      • getData

        protected T getData()
      • setRequest

        public void setRequest​(javax.servlet.http.HttpServletRequest request)

        Setter for the request. Will initialize all the variable of the JcmsContext if available in the request. (Therefore, it must be called after all the treatements done in doInitPage)

        Overridden to set form handler in the Request Attribute 'formHandler'.

        Overrides:
        setRequest in class JcmsContext
        Parameters:
        request - the HttpServletRequest from twhich to retrieve all jcms context information.
      • getFormHandlerRequestAttributeKey

        protected java.lang.String getFormHandlerRequestAttributeKey()
        Override this method to set another request attribute key for the FormHandler than the default.
        If it returns null, the form handler will not be stored in request attribute.
        Returns:
        request attribute key
      • setData

        public void setData​(javax.servlet.http.HttpServletRequest request)
        Initialize the Data Object
        Parameters:
        request - HttpServletRequest
      • getDataFromRequest

        protected T getDataFromRequest​(javax.servlet.http.HttpServletRequest request)
      • doCreateData

        protected abstract T doCreateData​(javax.servlet.http.HttpServletRequest request)
        Create a new Data object. This method is called in $setData(HttpServletRequest) when the Data is initialized.
        Parameters:
        request - HttpServletRequest
        Returns:
        Data
      • doInitData

        protected void doInitData​(T data,
                                  javax.servlet.http.HttpServletRequest request)
        Prepare the temporary extra(DB)Data maps, it's possible to initialize the given data before calling the setters of the request parameters.
        Parameters:
        data - Data
        request - HttpServletRequest
      • getExtraData

        protected java.lang.String getExtraData​(java.lang.String name)
        Returns the extraData value from the specified name, stored in the temporary extraData map with the setExtraData(String, String) method.
        Parameters:
        name - extraData name
        Returns:
        extraData value
      • setExtraData

        protected void setExtraData​(java.lang.String name,
                                    java.lang.String value)
        Stores a new extraData in the temporary extraData map. If the map previously contained a mapping for the name, the old value is replaced by the specified value.
        Parameters:
        name - extraData name
        value - extraData value
      • removeExtraData

        protected java.lang.String removeExtraData​(java.lang.String name)
        Removes an extraData from the temporary extraData map.
        Parameters:
        name - extraData name
        Returns:
        previous value associated with specified name, or null if there was no mapping for name. A null return can also indicate that null was associated
      • supportsExtraData

        protected boolean supportsExtraData​(java.lang.String name)
        Override this method to specify the supported extraData, and remove the others.
        Parameters:
        name - extraData name
        Returns:
        true if the given extraData name is supported, false instead
      • getExtraDBData

        protected java.lang.String getExtraDBData​(java.lang.String name)
        Returns the extraDBData value from the specified name, stored in the temporary extraDBData map with the setExtraDBData(String, String) method.
        Parameters:
        name - extraDBData name
        Returns:
        extraDBData value
      • setExtraDBData

        protected void setExtraDBData​(java.lang.String name,
                                      java.lang.String value)
        Stores a new extraData in the temporary extraDBData map. If the map previously contained a mapping for the name, the old value is replaced by the specified value.
        Parameters:
        name - extraDBData name
      • removeExtraDBData

        protected java.lang.String removeExtraDBData​(java.lang.String name)
        Removes an extraDBData from the temporary extraDBData map.
        Parameters:
        name - extraData name
        Returns:
        previous value associated with specified name, or null if there was no mapping for name. A null return can also indicate that null was associated
      • supportsExtraDBData

        protected boolean supportsExtraDBData​(java.lang.String name)
        Override this method to specify the supported extraDBData, and remove the others.
        By default, this method has the same behavior as supportsExtraData(String).
        Parameters:
        name - extraDBData name
        Returns:
        true if the given extraDBData name is supported, false instead
      • getDataParamId

        protected java.lang.String getDataParamId()
        Returns the parameter name used to get the Data id from the request. This method is called in $setData(HttpServletRequest) when we get the Data from its id found in the request.
        Returns:
        parameter name of the data id
      • prepare

        public void prepare​(javax.servlet.http.HttpServletRequest request)
        Prepare the form handler before calling JcmsFormHandler.validate() method. Call this method in the JSP before calling the JcmsFormHandler.validate() method.
        Parameters:
        request - HttpServletRequest
      • doPrepareData

        protected T doPrepareData​(T data,
                                  javax.servlet.http.HttpServletRequest request)
        Initialize data after calling the setters of the request parameters.
        This method is called in prepare(HttpServletRequest) method.
        Parameters:
        data - data to update
        request - HttpServletRequest
        Returns:
        updated data
      • processAction

        public final boolean processAction()
                                    throws java.io.IOException
        Description copied from class: JcmsFormHandler
        Method to be implemented to check/validate action to be performed and process them.

        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.

        Overrides:
        processAction in class JcmsFormHandler
        Returns:
        false if no redirection is needed, true otherwise
        Throws:
        java.io.IOException - IO Exception
      • validateMandatoryRequirements

        protected boolean validateMandatoryRequirements()
        Override this method whether any mandatory requirements must be defined and checked before any actions.
        If the this method return false, doPerformMandatoryRequirements() is called, and the processing stops at the end of the call to this latter.
        Returns:
        true mandatory requirements are all valids, false. Default method returns true
      • doPerformMandatoryRequirements

        protected boolean doPerformMandatoryRequirements()
      • isOpPrevious

        protected boolean isOpPrevious()
      • setOpPrevious

        protected void setOpPrevious​(boolean opPrevious)
      • doPerformPrevious

        protected boolean doPerformPrevious()
      • isOpNext

        protected boolean isOpNext()
      • setOpNext

        protected void setOpNext​(boolean opNext)
      • doPerformNext

        protected boolean doPerformNext()
      • isOpCancel

        protected boolean isOpCancel()
      • setOpCancel

        protected void setOpCancel​(boolean opCancel)
      • setOpCancel

        public void setOpCancel​(java.lang.String v)
      • validateCancel

        protected boolean validateCancel()
      • doPerformCancel

        protected boolean doPerformCancel()
      • isOpFinish

        protected boolean isOpFinish()
      • setOpFinish

        protected void setOpFinish​(boolean opFinish)
      • doPerformCreate

        protected boolean doPerformCreate​(T data,
                                          Member member)
        Creates the specified Data.
        Parameters:
        data - Data to save
        member - Member who saves the Data
        Returns:
        true the date was saved successfully
      • doPerformUpdate

        protected boolean doPerformUpdate​(T data,
                                          Member member)
        Updates the specified Data.
        Parameters:
        data - Data to update
        member - Member who updates the Data
        Returns:
        true the date was updated successfully
      • isOpDelete

        protected boolean isOpDelete()
      • setOpDelete

        protected void setOpDelete​(boolean opDelete)
      • setOpDelete

        public void setOpDelete​(java.lang.String v)
      • validateDelete

        protected boolean validateDelete()
      • doPerformDelete

        protected boolean doPerformDelete​(T data,
                                          Member member)
        Deletes the specified Data.
        Parameters:
        data - Data to delete
        member - Member who deletes the Data
        Returns:
        true the date was deleted successfully
      • isOpRefresh

        protected boolean isOpRefresh()
      • setOpRefresh

        protected void setOpRefresh​(boolean opRefresh)
      • setOpRefresh

        public void setOpRefresh​(java.lang.String v)
      • validateRefresh

        protected boolean validateRefresh()
      • doPerformRefresh

        protected boolean doPerformRefresh()
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • doProcessAction

        protected boolean doProcessAction()
        Override this method to add custom actions.
        Returns:
        true if the action was performed successfully, false instead
      • showCancelButton

        public boolean showCancelButton()

        Check if the "Cancel" button should be displayed in step modal form.

        The default implementation of this method is to always return true.

        Overrides:
        showCancelButton in class JcmsFormHandler
        Returns:
        true to display the "Cancel" button, false to hide it
        See Also:
        "jcore/doStepButtons.jspf for use of this method."
      • showNextButton

        public boolean showNextButton()

        Check if the "Next" button should be displayed in step modal form.

        Overrides:
        showNextButton in class JcmsFormHandler
        Returns:
        true to display the "Next" button, false to hide it
        See Also:
        "jcore/doStepButtons.jspf for use of this method."
      • showPreviousButton

        public boolean showPreviousButton()

        Check if the "Previous" button should be displayed in step modal form.

        The default implementation of this method is to return true if the current step (as returned by getFormStep() is higher than 0.

        Overrides:
        showPreviousButton in class JcmsFormHandler
        Returns:
        true to display the "Previous" button, false to hide it
        See Also:
        "jcore/doStepButtons.jspf for use of this method."
      • showFinishButton

        public boolean showFinishButton()

        Check if the "Finish" button should be displayed in step modal form.

        The default implementation of this method is to return true if the current step (as returned by getFormStep() is the last one (as compared with getFormStepCount().

        Overrides:
        showFinishButton in class JcmsFormHandler
        Returns:
        true to display the "Finish" button, false to hide it
        See Also:
        "jcore/doStepButtons.jspf for use of this method."
      • getFormStepCount

        public int getFormStepCount()

        Retrieve the total number of steps used for edition when invoking this form handler.

        The default implementation of this method is to return 1, corresponding to one step (which means only 1 screen being displayed).

        Overrides:
        getFormStepCount in class JcmsFormHandler
        Returns:
        the total number of steps in this form handler
        See Also:
        "jcore/doStepButtons.jspf for use of this method."
      • setFormStepCount

        public void setFormStepCount​(int formStepCount)

        Set the total number of steps used for edition when invoking this form handler.

        Parameters:
        formStepCount - the total number of steps in this form handler
      • getFormStep

        public int getFormStep()
        Retrieve the current step of edition when invoking this form handler.
        Overrides:
        getFormStep in class JcmsFormHandler
        Returns:
        the current steps in this form handler (starting at 0 and ending at getFormStepCount() - 1)
        See Also:
        "jcore/doStepButtons.jspf for use of this method."
      • setFormStep

        public void setFormStep​(int step)
        Set the current step of edition when invoking this form handler.
        Overrides:
        setFormStep in class JcmsFormHandler
        Parameters:
        step - the current step (0 being the first one and getFormStepCount() - 1 being the last one)
      • getFormHiddenFields

        public java.lang.String getFormHiddenFields()
        Method used to add hidden fields in the form.
        Overrides:
        getFormHiddenFields in class JcmsUploadFormHandler
        Returns:
        String representing the input[hidden] to add in the form
      • getMLMapArray

        protected java.util.HashMap<java.lang.String,​java.lang.String[]> getMLMapArray​(java.lang.String[] array,
                                                                                             boolean trim,
                                                                                             boolean escape)
        Description copied from class: JcmsFormHandler
        Returns the ML map (i.e. the additionnal languages) filled with the values contained in the given array (multivalued ML fields).
        Overrides:
        getMLMapArray in class JcmsFormHandler
        Parameters:
        array - the array
        trim - if true trim the values
        escape - if true escape the values
        Returns:
        the ML map filled with the values contained in the given array.
      • getHiddenFieldML

        protected java.lang.String getHiddenFieldML​(java.lang.String name,
                                                    java.util.Map<java.lang.String,​java.lang.String[]> map)
        Adds hidden multivalued multilingual field.
        Parameters:
        name - field name
        map - map of values
        Returns:
        String representing the hidden field
      • getHiddenField

        protected java.lang.String getHiddenField​(java.lang.String name,
                                                  java.lang.Object value)
      • validateData

        protected abstract boolean validateData​(T data)
        Validates the Data fields.
        Parameters:
        data - Data
        Returns:
        true if the given data has been validated, false instead