THIS PAGE IS INCOMPLETE. AFTER PLAYING I DECIDED I HATE JSF.

I ran away from it back to JavaFx as a training aim.

===============

So, what to use, Spring web, JSP, Servlets, JSF. Last time I was in this space Struts and Velocity were all the rage and Wickit looked fun. Now I see it’s all AngularJS, Meteor and other JavaScript stuff all fighting against Twitter ’server side is faster’ argument.

I am not a web designer, and I dont need to do a huge site. My preference is servlets and JSP, since I remember that stuff, but I guess I have to go JSF or Spring. And having used spring for the last 10 years I really really want a break from it. Which means JSF. The JSF tutorial is rubbish - makes me want to drink heavily, about as exciting as stabbing myself. OTOH, I only have 8 hours so here goes….

Basics: Maven yes, Glassfish No, Tomcat Yes, Eclipse Yes, JDK 7. jsk has to be 2.2 - see below. With 2.2 you can use html 5 and skip the stupid JSF tags.


  org.glassfish
  javax.faces
  2.2.3

1) Mojarra is the oracle reference implementation, becos they wanted a name. jsf-api-xxx.jar and jsf-impl-xxx.jar are now merfed from JSK 2.2 into javax-faces-xxx.jar which is maven group-id org.glassfish. To quote LAN at stack overflow:

“So what should you use for your development? Actually you can use both.  But the recommended way is to include jsf-api-xxx.jar only in the compilation classpath. Thus your own application does not depend on any classes under com.sun.faces package to achieve the portability to other JSF implementations. If you are using an application such as GlassFish, the container should already provide the JSF implementation at runtime. You should not package the above JSF jar files with your war or ear file, as server will provide all of them. If you use a container that does not come with a JSF implementation by default such as Tomcat, you need to package javax.faces-xxx.jar or (jsf-api-xxx.jar + jsf-impl-xxx.jar) in the WEB-INF/lib”

2) Each page has a managed bean associated with it., @ManagedBean @SessionScoped.

Other beans - ie classes, can be accessed if they use the annotation @Named

Oh. Oh. h: tags are like html but mean you can’t use a decent html editor.  Why do people keep doing this. Not only that but the fields have stupid auto id’s (you can change that).

A google and a chance later and JSK2.2, html 5 and we are back on track. So its version 2.2 and a decent html editor.

http://docs.oracle.com/javaee/7/tutorial/doc/jsf-facelets009.htm

So, providing that you stick jsf:id=”foo” then we can now ignore all of the facelet tags. hurrah. eg

Copied from here

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:jsf="http://xmlns.jcp.org/jsf"> 
<head jsfid="head"><title>boo</title></head>
<body jsfid="body">
  <form jsf:id="form">
  <input type="text" jsf:id="name" placeholder="Enter name" jsf:value="#{bean.name}" />
  <button jsf:action="#{bean.save}">Save</button>
  </form>
</body>
</html>

3) EL the expression language is all about how JSP and JSF pages get to data.  Now, I likes to embed java in my JSP’s, rather than use a stupid EL, because I am not a web developer. Sadly that is only JSP. grrr.

${} evaluated immediately, right value (rvalue) only.

#{} are deferred - which is the one JSF uses the most. Can be rvalue and lvalue.