Class FormUtil
- java.lang.Object
-
- jetbrains.buildServer.controllers.FormUtil
-
public class FormUtil extends Object
Utility methods for working with Java beans representing web forms on the server side.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
FormUtil.FormCreator<T>
Form bean factory
-
Constructor Summary
Constructors Constructor Description FormUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.springframework.validation.BindingResult
bindFromRequest(javax.servlet.http.HttpServletRequest request, Object form)
Fills properties of the specified form bean from the request.static <T extends StatefulObject>
TcreateNewFormIfNotModified(javax.servlet.http.HttpServletRequest request, Class<T> clazz, String customKey, FormUtil.FormCreator<T> formCreator)
Obtains a form bean from the session if it exists and if was modified, returns it.static <T> T
getFromSession(javax.servlet.http.HttpSession session, Class<T> clazz)
Obtains the form bean of the specified class from the sessionstatic <T> T
getFromSession(javax.servlet.http.HttpSession session, Class<T> clazz, String customKey)
Obtains the form bean of the specified class with specified custom key from the sessionstatic <T> T
getOrCreateForm(javax.servlet.http.HttpServletRequest request, Class<T> clazz, 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 <T> T
getOrCreateForm(javax.servlet.http.HttpServletRequest request, 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 boolean
isInitPageRequest(javax.servlet.http.HttpServletRequest request)
Returns true if the specified request contains 'init' parameterstatic void
removeAllFromSession(javax.servlet.http.HttpSession session, Class<?>... classes)
Removes all form beans from the session of the specified classesstatic void
removeFromSession(javax.servlet.http.HttpSession session, Class<?> clazz)
Removes form bean with specified class from the sessionstatic void
removeFromSession(javax.servlet.http.HttpSession session, Class<?> clazz, String customKey)
Removes form bean with specified class and custom key from the sessionstatic <T> void
removeFromSession(javax.servlet.http.HttpSession session, Class<T> clazz, Filter<T> formBeansFilter)
Removes form beans of the specified class and matched by the filter from the sessionstatic void
removeFromSession(javax.servlet.http.HttpSession session, Filter formBeansFilter)
Removes form beans matched by the filter from the sessionstatic void
storeInSession(javax.servlet.http.HttpSession session, Object form)
Stores the specified form bean in the session.static void
storeInSession(javax.servlet.http.HttpSession session, Object form, String customKey)
Stores the specified form bean in the session.
-
-
-
Method Detail
-
bindFromRequest
@NotNull public static org.springframework.validation.BindingResult bindFromRequest(@NotNull javax.servlet.http.HttpServletRequest request, @NotNull Object form)
Fills properties of the specified form bean from the request.- Parameters:
request
- requestform
- form bean
-
storeInSession
public static void storeInSession(@NotNull javax.servlet.http.HttpSession session, @NotNull Object form)
Stores the specified form bean in the session.- Parameters:
session
- HTTP sessionform
- form bean
-
storeInSession
public static void storeInSession(@NotNull javax.servlet.http.HttpSession session, Object form, String customKey)
Stores the specified form bean in the session.- Parameters:
session
- HTTP sessionform
- form beancustomKey
- additional key
-
getFromSession
@Nullable public static <T> T getFromSession(@NotNull javax.servlet.http.HttpSession session, @NotNull Class<T> clazz)
Obtains the form bean of the specified class from the session- Parameters:
session
- HTTP sessionclazz
- class of the form bean- Returns:
- form bean or null
-
getFromSession
@Nullable public static <T> T getFromSession(@NotNull javax.servlet.http.HttpSession session, @NotNull Class<T> clazz, String customKey)
Obtains the form bean of the specified class with specified custom key from the session- Parameters:
session
- HTTP sessionclazz
- class of the form beancustomKey
- additional key- Returns:
- form bean or null
-
removeFromSession
public static void removeFromSession(@NotNull javax.servlet.http.HttpSession session, @NotNull Class<?> clazz)
Removes form bean with specified class from the session- Parameters:
session
- HTTP sessionclazz
- class of the form bean
-
removeFromSession
public static <T> void removeFromSession(@NotNull javax.servlet.http.HttpSession session, @NotNull 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 sessionclazz
- class of the form beanformBeansFilter
- 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 sessionformBeansFilter
- filter which should return true if form must be removed and false otherwise
-
removeAllFromSession
public static void removeAllFromSession(@NotNull javax.servlet.http.HttpSession session, @NotNull Class<?>... classes)
Removes all form beans from the session of the specified classes- Parameters:
session
- HTTP sessionclasses
- form beans classes
-
removeFromSession
public static void removeFromSession(@NotNull javax.servlet.http.HttpSession session, @NotNull Class<?> clazz, String customKey)
Removes form bean with specified class and custom key from the session- Parameters:
session
- HTTP sessionclazz
- class of the form beancustomKey
- additional key
-
getOrCreateForm
@Nullable public static <T> T getOrCreateForm(@NotNull javax.servlet.http.HttpServletRequest request, @NotNull Class<T> clazz, @NotNull 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 requestclazz
- class of the form beanformCreator
- 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(@NotNull javax.servlet.http.HttpServletRequest request, @NotNull Class<T> clazz, String customKey, @NotNull 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 requestclazz
- class of the form beancustomKey
- additional keyformCreator
- 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
-
createNewFormIfNotModified
@Nullable public static <T extends StatefulObject> T createNewFormIfNotModified(@NotNull javax.servlet.http.HttpServletRequest request, @NotNull Class<T> clazz, String customKey, @NotNull FormUtil.FormCreator<T> formCreator)
Obtains a form bean from the session if it exists and if was modified, returns it. Otherwise returns the newly created form 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.- Type Parameters:
T
- a type of the form that implementsStatefulObject
- Parameters:
request
- HTTP requestclazz
- class of the form beancustomKey
- additional keyformCreator
- 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 - Since:
- 2020.2
-
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
-
-