Skip to content

My First Website

Marc Magon edited this page Feb 17, 2017 · 3 revisions

My First Website

This page will detail how to create your first website from scratch, using the core framework.


Creating a new website with JWebSwing is extremely easy.

  • Step 1 – Create new Java Class extending JWebSwingServlet
  • Step 2 – Annotate with @Singleton
  • Step 3 – Override the two required methods, getUrl, and getPage

The code should look something like the below

    @Singleton  
	public class BasicAppTemplate extends JWebSwingServlet  
	{  
		@Override  
		public Page getPage()  
		{  
		   return new Page();  
		}  
  
		@Override  
		public String getUrl()  
		{  
			return "/";  
		}  
	}  

At this point you are ready to run your application and produce a blank page.

You do not need any configuration files for any web server, or EE server in any regard, the application will run.

The framework is intended as a code only implementation (although not restricted at all).
You can generate everything from any component (including the page) and output to a console if need be.

GREAT FOR TESTING and any automated distribution system

Code Explanation

  1. You need to explicitly set the singleton annotation
    a. By default, all servlets are singletons and highly threaded.
    b. When managed with an external injector (such as WELD or CDI) these apply singletons for you, when using an internal dependency injector, the annotation is needed to be applied directly to the class.
    c. Don’t worry, you’ll get a nice error message if you forget to do this
  2. The URL provided is in relation to the context of the war file
    a. If your context is specified as abc, and the url is cba the visiting address is
    i. http://<server>/abc/cba
    b. To map to the same address as your context use “/”
    i. http://<server>/abc/
    c. All URL’s can be appended with query parameters
    d. If you’re specifying custom servlets, remember to append the query regular expression
    i. A protected variable “QueryParametersRegex” is available from any GuiceSiteBinder
  3. It’s usually best for largish applications to have the Page in a separate class.
  4. The page is tightly bound to the body, using getBody() is usually enough.
  5. You can of course use setBody() to have them loosely coupled.

Environment Prep

My First Website

  • Basic Structure
  • Code Explanation
  • Run Everywhere

Bindings

  • The Default Binder
  • The Site Binder
  • Quick User Authentication Filter

Generating Outputs

Persistable Components

  • Serialize to JSON
  • Deserialize from JSON

Create My First Plugin

  • The Page Configurator
  • HTML Only
  • HTML with JS
  • HTML with JS and CSS
  • HTML with Angular, JS, and CSS
  • HTML with All, and a custom servlet
  • A Complete Plugin
Clone this wiki locally