net

Java / Servlets

jasty.web source code is available on GitHub

To make jasty.web work in your project you should go through the following steps:

  • create your own form engine servlet version

    Inherit from FormEngineServlet, override createFormEngineFactory method and configure your custom FormEngine. Example below shows basic configuration for JSP rendering. You can create your own implementations for FormPersister, MethodInvoker, ViewRenderer and (very unlikely) ParameterProvider.

                    public class JspFormEngineServlet
                        extends FormEngineServlet {
    
                        @Override
                        protected FormEngineFactory createFormEngineFactory(ServletConfig config) {
                            return new JspFormEngineFactory();
                        }
                    }
    
                    class JspFormEngineFactory extends FormEngineFactory {
    
                        FormPersister formPersister = new ClientSideFormPersister();
                        MethodInvoker methodInvoker = new SimpleExceptionHandler(new DefaultMethodInvoker());
    
                        @Override
                        public FormEngine getFormEngine(ServletRequest request, ServletResponse response) {
                            ParameterProvider parameterProvider = new RequestParameterProvider(request);
                            ViewRenderer viewRenderer = new JspViewRenderer(request, response);
                            return new FormEngine(parameterProvider, viewRenderer, formPersister, methodInvoker);
                        }
                    }
                
  • configure your form engine servlet in web.xml

                        <servlet>
                            <servlet-name>AppServlet</servlet-name>
                            <servlet-class>com.jasty.jsp.JspFormEngineServlet</servlet-class>
                            <load-on-startup>1</load-on-startup>
                        </servlet>
    
                        <servlet-mapping>
                            <servlet-name>AppServlet</servlet-name>
                            <url-pattern>/formEngine</url-pattern>
                        </servlet-mapping>
                    

    This snippet configures Form Engine to be available under /formEngine.

  • reference tag libraries in web.xml

    This example references standard tags from the jasty.jsp-module. But you can create and reference your own tag libraries.

                        <jsp-config>
                            <taglib>
                                <taglib-uri>http://textorius.net/jsp</taglib-uri>
                                <taglib-location>/WEB-INF/lib/jasty-jsp-1.0.jar</taglib-location>
                            </taglib>
                        </jsp-config>
                    
  • create entry page

    This is the only page of your single-page application. It references all necessary JS-libraries, configures the form engine servlet URI and places application portlet on the page (formViewer-tag).

                        <%@ taglib prefix="jst" uri="http://textorius.net/jsp" %>
                        <html>
                        <head>
                            <title>Guess a number</title>
                            <script src="resources/jquery-1.7.min.js" type="text/javascript"></script>
                            <script src="resources/jquery.form.js" type="text/javascript"></script>
                            <script src="resources/jasty-core.js" type="text/javascript"></script>
                            <script src="resources/jasty-components.js" type="text/javascript"></script>
                        </head>
                        <body>
                            <script>
                                jasty.settings.formEngineUrl = "formEngine";
                            </script>
                            <jst:formViewer id="guessnum" entryPointClass="guessnumber.MainForm" />
                        </body>
                        </html>
                    

    The application is then running inside the specified location.