Skip to content

Instantly share code, notes, and snippets.

@mohamnag
Last active May 25, 2017 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohamnag/eac5f5413b0fff83bf55abd57651fec0 to your computer and use it in GitHub Desktop.
Save mohamnag/eac5f5413b0fff83bf55abd57651fec0 to your computer and use it in GitHub Desktop.
Kotlin+JSF SPA Framework: Call for comments

Kotlin + JSF in browser as SPA

Now that Google is officially setting Kotlin as Anroid's language and knowing that Kotlin can be cross-compiled to both Java and JavaScript, I came to the idea to build up a Kotlin based framework for making Single Page Applications for web. Idea is to reuse as much code as possible. Pretty much like what GWT and many many similar frameworks have tried to achieve too.

As for templating language, there are a lot of options out there, but if we are talking about winning over the Java community, then why not JSF? It is well-known in Java EE community and could take us one more step toward resuability of the code as it can be used by any JEE container supporting JSF. Considering the fact that Kotlin could also be used in JEE containers!

While current widely used SPA frameworks like EmberJS and Angular are dealing with the problem of cold boot and server-side rendering, a Kotlin+JSF solution could simply have both client and server side rendering.

Pros:

  • Kotlin and JSF could both be used on server side and client
  • Kotlin is a typesafe language with all advantages of it
  • The core (business logic) could be shared between web client (as both SPA and server side) and android client
  • JSF is a well-known UI descriptive language for Java devs

Cons:

  • Existing strong rivals, like Ember.JS and Angular
  • All the shared code should be pure Kotlin to be JavaScript-able
  • Developer should stick with JSF only tags, use of JSP tags and similar has to be really restricted, probably a lot of third party JSF libraries will not work due to Java code as logic on behind.

Sample architectural design:

Backend:

  • Java/Kotlin
  • Java EE, JAX-RS, RESTFul API (can be JSON or XML based, as XML is preferred in enterprise environments)

API-Common:

  • Kotlin
  • A shared code base containing all DTOs (~ beans) used by API for sending and receiving data. Also a client-side library for accessing data from RESTFul API in Kotlin.

Client-Common:

  • Kotlin
  • Use DTOs from API-Common and add clientside b-logic to them as a layer on top

Serverside and SPA Web Client:

  • Kotlin + JSF
  • Use Client-Common and add additional b-logic as controllers written in Kotlin. UI made in JSF, CSS and HTML

Android Client:

  • Kotlin + Native UI
  • Use Client-Common and add additonal b-logic. UI made as native android.

Missing components/functionality

  • A template engine for JSF support in browser (written in JavaScript or preferrable in Kotlin)
  • All the serverside functionality and logic that JSF has (binding values, formatting, action management, ...), should be also reproduced in Kotlin
  • The Faces Servlet (routing, request processing, ...), should be reproduced in Kotlin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment