Class WebApplication

java.lang.Object
org.apache.empire.jsf2.app.WebApplication

public abstract class WebApplication extends Object
  • Field Details

    • APPLICATION_BEAN_NAME

      public static String APPLICATION_BEAN_NAME
    • textResolvers

      protected TextResolver[] textResolvers
  • Constructor Details

    • WebApplication

      protected WebApplication()
  • Method Details

    • getInstance

      public static <T extends WebApplication> T getInstance()
      Returns the one and only instance of the WebApplication (Singleton)
      Type Parameters:
      T - the application type
      Returns:
      the WebApplication instance
    • init

      protected abstract void init(javax.servlet.ServletContext servletContext)
    • getAppDataSource

      protected abstract DataSource getAppDataSource(DBDatabase db)
    • init

      public final void init(FacesImplementation facesImpl, javax.faces.context.FacesContext startupContext)
      Init the Application
      Parameters:
      facesImpl - the faces implementation
      startupContext - the startup context
    • destroy

      public void destroy()
    • onRequestComplete

      public void onRequestComplete(javax.faces.context.FacesContext ctx)
      handle request cleanup
      Parameters:
      ctx - the faces context
    • onViewNotFound

      public void onViewNotFound(javax.faces.context.FacesContext fc, javax.servlet.http.HttpServletRequest req)
      handle view not found
      Parameters:
      fc - the faces context
      req - the request
    • onChangeView

      public void onChangeView(javax.faces.context.FacesContext fc, String viewId)
      handle view change
      Parameters:
      fc - the faces context
      viewId - the view id
    • addJavascriptCall

      public void addJavascriptCall(javax.faces.context.FacesContext fc, String function)
      adds a Javascript call to the request
      Parameters:
      fc - the faces context
      function - the javascript command
    • getFacesImplementation

      public FacesImplementation getFacesImplementation()
      return the interface for Implementation specific features that are specific for Mojarra or MyFaces
      Returns:
      the faces implementation
    • getWebRoot

      public String getWebRoot()
      returns the web context path as returned from ServletContext.getContextPath()
      Returns:
      the web root
    • getContextLocale

      public Locale getContextLocale(javax.faces.context.FacesContext ctx)
      returns the active locale for a given FacesContext
      Parameters:
      ctx - the faces context
      Returns:
      the context locale
    • getTextResolver

      public TextResolver getTextResolver(Locale locale)
    • getTextResolver

      public TextResolver getTextResolver(javax.faces.context.FacesContext ctx)
    • getFacesMessage

      public javax.faces.application.FacesMessage getFacesMessage(javax.faces.context.FacesContext ctx, javax.faces.application.FacesMessage.Severity severity, String msg, Object... params)
      Returns a FacesMessage
      Parameters:
      ctx - the FacesContext
      severity - the message severity
      msg - the message or message key
      params - the message params
      Returns:
      the FacesMessage or null to ignore
    • getFacesErrorMessage

      public javax.faces.application.FacesMessage getFacesErrorMessage(javax.faces.context.FacesContext ctx, String errorContext, Throwable t)
      Returns a FacesMessage for an Exception
      Parameters:
      ctx - the FacesContext
      errorContext - the error context (optional)
      t - the exception
      Returns:
      the FacesMessage or null to ignore
    • extractErrorMessageDetail

      protected String extractErrorMessageDetail(String errorContext, Throwable e, int stackTraceElements)
    • hasError

      public boolean hasError(javax.faces.context.FacesContext fc)
      checks if the current context contains an error
      Parameters:
      fc - the FacesContext
      Returns:
      true if the context has an error set or false otherwise
    • redirectDirectly

      public void redirectDirectly(javax.faces.context.FacesContext fc, String url)
      Redirects to another page or url
      Parameters:
      fc - the FacesContext
      url - the target url
    • handleException

      public void handleException(javax.faces.context.FacesContext context, Page source, Throwable e)
      Handles an exeption, that could not be handled on the page level The application should redirect to the error page.
      Parameters:
      context - the faces context
      source - the page from which the exception originated
      e - the Exception to handle
    • isPartialSubmit

      public boolean isPartialSubmit(javax.faces.context.FacesContext fc)
      returns true if a form input element has been partially submitted
      Parameters:
      fc - the Faces Context
      Returns:
      the componentId or null if no partial submit was been performed
    • getPartialSubmitComponentId

      public String getPartialSubmitComponentId(javax.faces.context.FacesContext fc)
      returns the componentId for which a partial submit has been performed.
      Parameters:
      fc - the Faces Context
      Returns:
      the componentId or null if no partial submit was been performed
    • findComponent

      public javax.faces.component.UIComponent findComponent(javax.faces.context.FacesContext fc, String componentId, javax.faces.component.UIComponent nearComponent)
      finds the component with the given id that is located in the same NamingContainer as a given component
      Parameters:
      fc - the FacesContext
      componentId - the component id
      nearComponent - a component within the same naming container from which to start the search (optional)
      Returns:
      the component or null if no component was found
    • findChildComponent

      public static javax.faces.component.UIComponent findChildComponent(javax.faces.component.UIComponent parent, String componentId)
      finds a child component with the given id that is located below the given parent component
      Parameters:
      parent - the parent
      componentId - the component id
      Returns:
      the component or null if no component was found
    • registerManagedBean

      public void registerManagedBean(Class<?> beanClass, BeanScope scope)
      Registers a ManagedBean for a particular scope
      Parameters:
      beanClass - the bean class to register
      scope - the bean scope
    • getContextBean

      public Object getContextBean(javax.faces.context.FacesContext context, String beanName, BeanScope scope)
      Returns the bean for a particular scope
      Parameters:
      context - the FacesContext
      beanName - the beanName
      scope - the bean scope
      Returns:
      the bean instance
    • setContextBean

      public void setContextBean(javax.faces.context.FacesContext context, String beanName, Object beanInstance, BeanScope scope)
      Sets a bean for a particular scope
      Parameters:
      context - the FacesContext
      beanName - the beanName
      beanInstance - the bean instance
      scope - the bean scope
    • setContextBean

      public void setContextBean(javax.faces.context.FacesContext context, Object beanInstance, BeanScope scope)
      Sets a bean for a particular scope The beanName will be auto detected from the beanInstance
      Parameters:
      context - the FacesContext
      beanInstance - the bean instance
      scope - the bean scope
    • getDefaultControlType

      public String getDefaultControlType(DataType dataType)
      returns the default input control type for a given data Type
      Parameters:
      dataType - the data type
      Returns:
      an Input Cnotrol type
      See Also:
    • initTextResolvers

      protected void initTextResolvers(javax.faces.application.Application app)
    • createResourceTextResolver

      protected ResourceTextResolver createResourceTextResolver(ResourceBundle bundle)
    • getConnection

      protected Connection getConnection(DBDatabase db)
      Obtains a JDBC-Connection from the connection pool
      Parameters:
      db - the database for which to obtain a connection
      Returns:
      the connection
    • releaseConnection

      protected void releaseConnection(Connection conn, boolean commit, DBRollbackManager dbrm)
      Releases a JDBC-Connection from the connection pool
      Parameters:
      conn - the connection to release
      commit - flag whether to commit changes
      dbrm - the rollback manager
    • getRollbackManagerForRequest

      public DBRollbackManager getRollbackManagerForRequest(javax.faces.context.FacesContext fc, boolean create)
      Obtains a DBRollbackManager for the current request
      Parameters:
      fc - the FacesContext
      create - if true a DBRollbackManager will be created if not already present
      Returns:
      the rollback manager
    • getConnectionForRequest

      public Connection getConnectionForRequest(javax.faces.context.FacesContext fc, DBDatabase db, boolean create)
      Obtains a JDBC-Connection for the current request
      Parameters:
      fc - the FacesContext
      db - the DBDatabase for which to obtain a connection
      create - if true a Connection will be created if not already present
      Returns:
      the connection
    • releaseAllConnections

      public void releaseAllConnections(javax.faces.context.FacesContext fc, boolean commit)
      Releases all connections attached to the current request
      Parameters:
      fc - the FacesContext
      commit - when true changes are committed otherwise they are rolled back
    • releaseAllConnections

      public void releaseAllConnections(javax.faces.context.FacesContext fc)
      Releases all connections attached to the current request If an error is detected in the faces message list, a rollback will automatically be performed insteamd of a commmit
      Parameters:
      fc - the FacesContext
    • releaseConnection

      public void releaseConnection(javax.faces.context.FacesContext fc, DBDatabase db, boolean commit)
      Releases the connection associated with a database from the request
      Parameters:
      fc - the FacesContext
      db - the DBDatabase for which to release the connection
      commit - when true changes are committed otherwise they are rolled back
    • releaseConnection

      public void releaseConnection(javax.faces.context.FacesContext fc, DBDatabase db)
      Releases the connection associated with a database from the request If an error is detected in the faces message list, a rollback will automatically be performed insteamd of a commmit
      Parameters:
      fc - the FacesContext
      db - the DBDatabase for which to release the connection