jetbrains.buildServer.controllers
Class FormUtil

java.lang.Object
  extended by jetbrains.buildServer.controllers.FormUtil

public class FormUtil
extends java.lang.Object

Utility methods for working with Java beans representing web forms on the server side.


Nested Class Summary
static interface FormUtil.FormCreator<T>
          Form bean factory
 
Constructor Summary
FormUtil()
           
 
Method Summary
static org.springframework.validation.BindingResult bindFromRequest(javax.servlet.http.HttpServletRequest request, java.lang.Object form)
          Fills properties of the specified form bean from the request.
static
<T> T
getFromSession(javax.servlet.http.HttpSession session, java.lang.Class<T> clazz)
          Obtains the form bean of the specified class from the session
static
<T> T
getFromSession(javax.servlet.http.HttpSession session, java.lang.Class<T> clazz, java.lang.String customKey)
          Obtains the form bean of the specified class with specified custom key from the session
static
<T> T
getOrCreateForm(javax.servlet.http.HttpServletRequest request, java.lang.Class<T> clazz, FormUtil.FormCreator<T> formCreator)
          Obtains a form bean from the session if it exists or creates a new form bean and stores it in the session.
static
<T> T
getOrCreateForm(javax.servlet.http.HttpServletRequest request, java.lang.Class<T> clazz, java.lang.String customKey, FormUtil.FormCreator<T> formCreator)
          Obtains a form bean from the session if it exists or creates a new form bean and stores it in the session.
static boolean isInitPageRequest(javax.servlet.http.HttpServletRequest request)
          Returns true if the specified request contains 'init' parameter
static void removeAllFromSession(javax.servlet.http.HttpSession session, java.lang.Class... classes)
          Removes all form beans from the session of the specified classes
static void removeFromSession(javax.servlet.http.HttpSession session, java.lang.Class clazz)
          Removes form bean with specified class from the session
static
<T> void
removeFromSession(javax.servlet.http.HttpSession session, java.lang.Class<T> clazz, Filter<T> formBeansFilter)
          Removes form beans of the specified class and matched by the filter from the session
static void removeFromSession(javax.servlet.http.HttpSession session, java.lang.Class clazz, java.lang.String customKey)
          Removes form bean with specified class and custom key from the session
static void removeFromSession(javax.servlet.http.HttpSession session, Filter formBeansFilter)
          Removes form beans matched by the filter from the session
static void storeInSession(javax.servlet.http.HttpSession session, java.lang.Object form)
          Stores the specified form bean in the session.
static void storeInSession(javax.servlet.http.HttpSession session, java.lang.Object form, java.lang.String customKey)
          Stores the specified form bean in the session.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FormUtil

public FormUtil()
Method Detail

bindFromRequest

public static org.springframework.validation.BindingResult bindFromRequest(@NotNull
                                                                           javax.servlet.http.HttpServletRequest request,
                                                                           @NotNull
                                                                           java.lang.Object form)
Fills properties of the specified form bean from the request.

Parameters:
request - request
form - form bean

storeInSession

public static void storeInSession(@NotNull
                                  javax.servlet.http.HttpSession session,
                                  @NotNull
                                  java.lang.Object form)
Stores the specified form bean in the session.

Parameters:
session - HTTP session
form - form bean

storeInSession

public static void storeInSession(javax.servlet.http.HttpSession session,
                                  java.lang.Object form,
                                  java.lang.String customKey)
Stores the specified form bean in the session.

Parameters:
session - HTTP session
form - form bean
customKey - additional key

getFromSession

@Nullable
public static <T> T getFromSession(@NotNull
                                            javax.servlet.http.HttpSession session,
                                            @NotNull
                                            java.lang.Class<T> clazz)
Obtains the form bean of the specified class from the session

Parameters:
session - HTTP session
clazz - class of the form bean
Returns:
form bean or null

getFromSession

@Nullable
public static <T> T getFromSession(@NotNull
                                            javax.servlet.http.HttpSession session,
                                            @NotNull
                                            java.lang.Class<T> clazz,
                                            java.lang.String customKey)
Obtains the form bean of the specified class with specified custom key from the session

Parameters:
session - HTTP session
clazz - class of the form bean
customKey - additional key
Returns:
form bean or null

removeFromSession

public static void removeFromSession(@NotNull
                                     javax.servlet.http.HttpSession session,
                                     @NotNull
                                     java.lang.Class clazz)
Removes form bean with specified class from the session

Parameters:
session - HTTP session
clazz - class of the form bean

removeFromSession

public static <T> void removeFromSession(@NotNull
                                         javax.servlet.http.HttpSession session,
                                         @NotNull
                                         java.lang.Class<T> clazz,
                                         @NotNull
                                         Filter<T> formBeansFilter)
Removes form beans of the specified class and matched by the filter from the session

Parameters:
session - HTTP session
clazz - class of the form bean
formBeansFilter - filter which should return true if form must be removed and false otherwise

removeFromSession

public static void removeFromSession(@NotNull
                                     javax.servlet.http.HttpSession session,
                                     @NotNull
                                     Filter formBeansFilter)
Removes form beans matched by the filter from the session

Parameters:
session - HTTP session
formBeansFilter - filter which should return true if form must be removed and false otherwise

removeAllFromSession

public static void removeAllFromSession(@NotNull
                                        javax.servlet.http.HttpSession session,
                                        java.lang.Class... classes)
Removes all form beans from the session of the specified classes

Parameters:
session - HTTP session
classes - form beans classes

removeFromSession

public static void removeFromSession(@NotNull
                                     javax.servlet.http.HttpSession session,
                                     @NotNull
                                     java.lang.Class clazz,
                                     java.lang.String customKey)
Removes form bean with specified class and custom key from the session

Parameters:
session - HTTP session
clazz - class of the form bean
customKey - additional key

getOrCreateForm

@Nullable
public static <T> T getOrCreateForm(javax.servlet.http.HttpServletRequest request,
                                             java.lang.Class<T> clazz,
                                             FormUtil.FormCreator<T> formCreator)
Obtains a form bean from the session if it exists or creates a new form bean and stores it in the session. A newly created form bean is placed in the session with name of the form bean class as a key.

Parameters:
request - HTTP request
clazz - class of the form bean
formCreator - form bean factory
Returns:
form bean from the session or newly created form bean if no bean stored in session or null if formCreator returned null

getOrCreateForm

@Nullable
public static <T> T getOrCreateForm(javax.servlet.http.HttpServletRequest request,
                                             java.lang.Class<T> clazz,
                                             java.lang.String customKey,
                                             FormUtil.FormCreator<T> formCreator)
Obtains a form bean from the session if it exists or creates a new form bean and stores it in the session. A newly created form bean is placed in the session with key concatenated from the name of the form bean class and specified custom key.

Parameters:
request - HTTP request
clazz - class of the form bean
customKey - additional key
formCreator - form bean factory
Returns:
form bean from the session or newly created form bean if no bean stored in session or null if formCreator returned null

isInitPageRequest

public static boolean isInitPageRequest(javax.servlet.http.HttpServletRequest request)
Returns true if the specified request contains 'init' parameter

Parameters:
request - request
Returns:
true if request contains 'init' parameter