andy bosch - javaserver faces in the cloud

29
JavaServer Faces in the Cloud Andy Bosch Independent consultant and trainer Using Google App Engine for your JSF 2.x web application

Upload: andy-bosch

Post on 29-Nov-2014

1.155 views

Category:

Technology


5 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Andy Bosch -  JavaServer Faces in the cloud

JavaServer Faces in the Cloud

Andy BoschIndependent consultant and trainer

Using Google App Engine for your JSF 2.x web application

Page 2: Andy Bosch -  JavaServer Faces in the cloud

Agenda

� Clouds and the Google App Engine

� A first HelloWorld with GAE

� Introducing JSF 2.0

� JSF 2.0 and GAE

� Component libraries and GAE

� Conclusion

Page 3: Andy Bosch -  JavaServer Faces in the cloud

Who am I?

� Name: Andy Bosch

� Trainer, coach, developer, …

� Specialized on JSF and portlets

� Expert Group member of JSR-301 and JSR-329

� Working with JSF since 2004

Page 4: Andy Bosch -  JavaServer Faces in the cloud

Agenda

� Clouds and the Google App Engine

� A first HelloWorld with GAE

� Introducing JSF 2.0

� JSF 2.0 and GAE

� Component libraries and GAE

� Conclusion

Page 5: Andy Bosch -  JavaServer Faces in the cloud

Everything is in the Cloud

Software

- SaaS - Platform

- PaaS -- PaaS -

Infrastructure

- IaaS -

Page 6: Andy Bosch -  JavaServer Faces in the cloud

What is GAE?

� Google App Engine

lets you run your web applications

on Google's infrastructure.

Page 7: Andy Bosch -  JavaServer Faces in the cloud

Why should I use it?

� App Engine applications are easy to build, easy to

maintain, and easy to scale as your traffic and data

storage needs to grow.

With App Engine, there are no servers to maintain:

You just upload your application, and it's ready to

serve your users.

Page 8: Andy Bosch -  JavaServer Faces in the cloud

More details, please

� AppServer which supports most of the common

technologies

� Automatic scaling and load balancing

� Transactional and highly scalable database model

� Integration into Google accounts through APIs

Page 9: Andy Bosch -  JavaServer Faces in the cloud

The environment

� In the background, Jetty is used

� To be more precise: 10s of thousands of Jettys

���� A servlet container, not an application server!

Page 10: Andy Bosch -  JavaServer Faces in the cloud

Full Java support?

� Almost, but there are some restrictions:

• Cannot write to the file system

• Cannot open socket connections

• Cannot start new threads• Cannot start new threads

• …

� The restrictions are build into the Java runtime

environment

� If there are security violations, runtime exceptions are

thrown

Page 11: Andy Bosch -  JavaServer Faces in the cloud

Tooling environment

� Eclipse with plug-ins

� SDK with web server application that emulates all of

the App Engine services

� Admin console

� Plenty of online documentations

Page 12: Andy Bosch -  JavaServer Faces in the cloud

Five steps to a hello world

1. Install SDK

2. Create GAE account

3. Create the application3. Create the application

4. Create project

5. Upload project

Page 13: Andy Bosch -  JavaServer Faces in the cloud

Agenda

� Clouds and the Google App Engine

� A first HelloWorld with GAE

� Introducing JSF 2.0

� JSF 2.0 and GAE

� Component libraries and GAE

� Conclusion

Page 14: Andy Bosch -  JavaServer Faces in the cloud

Introducing JSF 2.1

� XHtml instead of JSP

� Ajax Integration

� Resource Handling� Resource Handling

� Annotation Support

� View templating

� Composite Components

Page 15: Andy Bosch -  JavaServer Faces in the cloud

JSF 2.0 and GAE

� During the first months of JSF 2.0, there were several

issues causing some troubles

� Nowadays, both Mojarra and MyFaces can be used

with GAEwith GAE

� A couple of minimal things have to be considered

Page 16: Andy Bosch -  JavaServer Faces in the cloud

A simple JSF page

<html xmlns="http://www.w3.org/1999/xhtml"

xmlns:h="http://java.sun.com/jsf/html"

xmlns:f="http://java.sun.com/jsf/core”>

<h:head>

<title>JSF 2.0 Hello World</title><title>JSF 2.0 Hello World</title>

</h:head>

<h:body>

<h:form>

<h:outputText value=”Hi there” />

</h:form>

</h:body>

</html>

Page 17: Andy Bosch -  JavaServer Faces in the cloud

EL-bug

� Known bug in JSP support

� Google AppEngine Issue 1506 (marked as fixed)

� JSP 2.1 not fully supported� JSP 2.1 not fully supported

� Workaround with explicitly defined el factory

<context-param>

<param-name>com.sun.faces.expressionFactory</param-name>

<param-value>com.sun.el.ExpressionFactoryImpl</param-value>

</context-param>

Page 18: Andy Bosch -  JavaServer Faces in the cloud

Disable multi-threading

� GAE doesn't support multi-threaded applications

<context-param>

<param-name>

com.sun.faces.enableMultiThreadedStartup

</param-name> </param-name>

<param-value>false</param-value>

</context-param>

<context-param>

<param-name>com.sun.faces.enableThreading</param-name>

<param-value>false</param-value>

</context-param>

Page 19: Andy Bosch -  JavaServer Faces in the cloud

Enable sessions

<?xml version="1.0" encoding="utf-8"?>

<appengine-web-app

xmlns="http://appengine.google.com/ns/1.0">

<application></application><application></application>

<version>1</version>

<sessions-enabled>true</sessions-enabled>

...

</appengine-web-app>

Page 20: Andy Bosch -  JavaServer Faces in the cloud

Disable JNDI in Mojarra classes

� JNDI is not supported in GAE

� Patched version of Mojarra

Page 21: Andy Bosch -  JavaServer Faces in the cloud

I want to see it now !

� With those mentioned changes the HelloWorld app

should already be able to be deployed

Page 22: Andy Bosch -  JavaServer Faces in the cloud

Let‘s try out some more: JSF 2.x features

� Composite Components

� Resource Handling

� Systemevents

� Beanvalidation

� Viewparameter

� Ajax

Page 23: Andy Bosch -  JavaServer Faces in the cloud

Composite Components (1)

� DRY – Don‘t repeat yourself

<html xmlns="http://www.w3.org/1999/xhtml"

xmlns:h="http://java.sun.com/jsf/html"

xmlns:f="http://java.sun.com/jsf/core"

xmlns:cc="http://java.sun.com/jsf/composite/helloLib">

<h:head>

<title>CC Demo</title>

</h:head>

<h:body>

<h:form>

<cc:hello value=”Andy Bosch” />

</h:form>

</h:body>

</html>

Page 24: Andy Bosch -  JavaServer Faces in the cloud

Composite Components (2)

� hello.xhtml

<html xmlns="http://www.w3.org/1999/xhtml"

xmlns:h="http://java.sun.com/jsf/html"

xmlns:f="http://java.sun.com/jsf/core"

xmlns:composite="http://java.sun.com/jsf/composite">

<body>

<composite:interface>

<composite:attribute name="value" required="true" />

</composite:interface>

<composite:implementation>

<h:outputText

value=”Hello #{cc.attrs.value}” />

</composite:implementation>

</body>

</html>

Page 25: Andy Bosch -  JavaServer Faces in the cloud

Using Ajax

� “Parrot“ example

� When typing a key, the output should be repeated

<h:panelGrid columns="2">

<h:outputText value=„Your name: " />

<h:inputText value="#{personBean.lastname}">

<f:ajax render="@form" />

</h:inputText>

<h:outputText value=„Again your name: " />

<h:outputText value="#{personBean.lastname}" />

</h:panelGrid>

Page 26: Andy Bosch -  JavaServer Faces in the cloud

Component libraries

� JSF has a powerful ecosystem of additional component

libraries

� Not all of them can be used in combination with the

GAEGAE

� RichFaces and ICEfaces did have some minor

problems, but all entries in Jira are “fixed“ now.

� PrimeFaces is working !

Page 27: Andy Bosch -  JavaServer Faces in the cloud

Links and Resources

� http://bit.ly/8U6Ebn

JSF 2.0 and GAE

� http://in.relation.to/Bloggers/WeldJSF20AndGoogleApp

EngineNavigatingTheMinefieldPart1EngineNavigatingTheMinefieldPart1

� http://myfaces.apache.org/core20/googleappenginesup

port.html

� http://primefaces-rocks.appspot.com/ui/home.jsf

Page 28: Andy Bosch -  JavaServer Faces in the cloud

Q&A? More trainings:www.jsf-academy.com

Contact:[email protected]

Twitter:@andyboschTwitter:@andybosch

Page 29: Andy Bosch -  JavaServer Faces in the cloud

Evaluation Forms:

JavaServer Faces in the Cloud

Presented by: Andy Bosch