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
, overridecreateFormEngineFactory
method and configure your custom FormEngine. Example below shows basic configuration for JSP rendering. You can create your own implementations forFormPersister
,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.
Groovy / Grails
Source code for the Grails jasty plugin is available on GitHub
To make the plugin work in your web project after installation, you should go through the following steps:
configure form engine factory in Bootstrap.groovy
You can set up a new factory with your own implementations for
FormPersister
,MethodInvoker
,ViewRenderer
andParameterProvider
. Or just use the default one.class BootStrap { def init = { servletContext -> GrailsFormEngineFactory.instance = new DefaultGrailsFormEngineFactory() } }
create main view
This is the only page of your single-page application. It references all necessary JS-libraries, configures the form engine controller URI and places application portlet on the page (
formViewer
-tag).<%@ page contentType="text/html;charset=UTF-8" %> <!DOCTYPE html> <html> <head> <title>Form samples</title> <script src="${'$'}{jasty.resource(dir: 'js', file: 'jquery-1.8.3.js')}" type="text/javascript"></script> <script src="${'$'}{jasty.resource(dir: 'js', file: 'jquery.form.js')}" type="text/javascript"></script> <script src="${'$'}{jasty.resource(dir: 'js', file: 'jasty-core.js')}" type="text/javascript"></script> <script src="${'$'}{jasty.resource(dir: 'js', file: 'jasty-std.js')}" type="text/javascript"></script> </head> <body> <script> jasty.settings.formEngineUrl = "${'$'}{g.createLink([controller: 'app', action: 'doAction'])}"; </script> <jasty:formViewer id="myform" entryPoint="guessnumber.MainForm" /> </body> </html>
The application is then running inside the specified location.
...and go
Author your forms under
controllers
and GSP-views underforms
directory inviews
. The folder structure for the views should match the package of the form.
.NET / MVC
Nasty-Web source code is available on GitHub
To make Nasty-Web work in your web project, you should go through the following steps:
configure form engine factory in Global.asax.cs
You can set up a new factory with your own implementations for
IFormPersister
,IMethodInvoker
,IViewRenderer
andIParameterProvider
. Or just use the default one.public class MvcApplication : System.Web.HttpApplication { protected void Application_Start() { FormEngineFactory.Instance = new DefaultMvcFormEngineFactory(); // etc. } }
create home controller
This is a controller to render the main page, where the application will be embedded in.
ControllerContext
needs to be exposed for theFormViewer
to use it for rendering.public class HomeController : Controller { public ActionResult Index() { FormViewer.ExposeControllerContext(ControllerContext); return View(); } }
create main view
This is the only page of your single-page application. It references all necessary JS-libraries, configures the form engine controller URI and places application portlet on the page (
FormViewer
-tag).<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %> <%@ Register TagPrefix="t" Assembly="Nasty.Mvc" Namespace="Nasty.Mvc" %> <!DOCTYPE html > <html> <head> <title>Guess a number</title> <script src="<%=Url.FormEngineScript("jquery-1.7.min.js")%>" type="text/javascript"></script> <script src="<%=Url.FormEngineScript("jquery.form.js")%>" type="text/javascript"></script> <script src="<%=Url.FormEngineScript("jasty-core.js")%>" type="text/javascript"></script> <script src="<%=Url.FormEngineScript("jasty-std.js")%>" type="text/javascript"></script> </head> <body> <script> jasty.settings.formEngineUrl = "<%=Url.FormEngine()%>"; </script> <t:FormViewer runat="server" ID="myform" EntryPointClass="Nasty.Samples.Forms.MainForm, Nasty.Samples"/> </body> </html>
The application is then running inside the specified location.
...and go
Author your forms and views under
Forms
directory of your web project.