Showing posts with label jsf. Show all posts
Showing posts with label jsf. Show all posts

Sunday, December 3, 2017

Mojarra 2.2.13.SP4 in Wildfly 11 debugging

I get a message "The form component needs to have a UIForm in its ancestry. Suggestion: enclose the necessary components within <h:form> ". After some mucking (basically, exclude stuff and see if it still breaks) I discovered the fix: enclose a p:menubar in a h:form <h:form><p:menubar>

A few things leave me really disappointed: this warning should be issued by Eclipse editor, not runtime... and the warning message should be accompanied by the exact location and identity of the offending element.

And in Mojarra 2.2.13.SP4 (Wildfly 11) there doesn't seem to be any debugging flag to get more information.

RANT ON once more, ui development has made huge steps BACKWARDS in the last 20 years RANT OFF Using Delphi in 1995 I was able to put together a very decent and complex UI in MINUTES - with JSF/HTML/Mojarra/CSS/Bootstrap it takes MONTHS and it's no fun. That's why whenever I have to do a UI I keep it MINIMALISTIC, I hate wasting my time in such poorly engineered products.





Saturday, December 2, 2017

JSF facelets, composition, layouts, templates

https://docs.oracle.com/javaee/7/javaserver-faces-2-2/vdldocs-facelets/toc.htm this is the Facelets documentation

and this https://docs.oracle.com/javaee/7/javaserver-faces-2-2/vdldocs-facelets/ui/composition.html is the ui:composition documentation



RANT ON

Let's admit it, HTML UI development is sheer mess.
In OOP you learn about nice encapsulation, separation of concerns, tidy APIs, design-time validation, convention over configuration... in HTML it's exactly the other way round, everything mixed up and it's just a verbose visually incomprehensible jungle, tons of implicit stuff has to be explicitly stated over and over, tons of useless boilerplate fluff make the code unreadable. It makes me really sick. With some better designed standard, the size of this crap could be reduced by a factor of 10 without any loss, actually gaining a lot in readability and maintainability. It's so evident.


RANT OFF

Here a decent tutorial (a bit too complicated) on templates:



code is here:

https://github.com/discospiff/JavaFullStackEnterpriseWeb


in a JSF application you use a template, in which you insert contents defined in pages.

In a template, to insert the content, you use div+insert (=insertContent) ,

In a page, to use a template, you use composition (=useTemplate)

In a page, to define the content, you use define (=defineContent).

Again: a template inserts stuff; a page defines stuff and uses a template to arrange it on a layout.


for a page, look here https://github.com/discospiff/JavaFullStackEnterpriseWeb/blob/master/PlantPlaces/WebContent/index.xhtml

and the corresponding template is https://github.com/discospiff/JavaFullStackEnterpriseWeb/blob/master/PlantPlaces/WebContent/template.xhtml





Netbeans rocks, Eclipse sucks

With Eclipse, setting up a simple Web Application with JSF and deploying it to Wildfly is a long, frustrating struggle.

With Netbeans, it takes 10 seconds.

File / New Project, Java Web / Web Application, project name "WebApplication1", server : select Wildfly server, Java EE Version: Java EE 7 Web, context path: /WebApplication1, Frameworks: select JavaServer Faces, in the components tab select Primefaces (the first time iyou haveto wait 10 seconds while it fetches the dependencies "JSF library Primefaces not setup correctly..." )

Right click on the Project, Run... it will open http://localhost:8080/WebApplication1/ and you are ready to go.


What Netbeans generates is:







BEWARE: to run on Wildfly 11, you should change the version of primefaces in pom.xml from 5.0 to 6.0, otherwise you get an error "wildfly This page calls for XML namespace http://primefaces.org/ui declared with prefix p but no taglibrary exists for that namespace"

The only issue I had with Netbeans 8.2 is that it's not compatible with Java 9, I had to edit netbeans.conf and change netbeans_jdkhome to point to JDK 8.

Incidentally, check out this AWESOME video on how to generate a Primefaces crud application from Entities with Netbeans

https://netbeans.org/kb/docs/javaee/maven-primefaces-screencast.html

You can simply forget that with Eclipse. A Total Eclipse of the Heart



"every now and then I fall apart
I don't know what to do and I am always in the dark
There is nothing I can do, a total Eclipse of the heart
Once upon a time there was light in my life"

hahaha




Friday, November 24, 2017

Primefaces Showcase

no better way to learn Primefaces as to use their showcase


https://github.com/primefaces/showcase

git clone https://github.com/primefaces/showcase.git
cd showcase
git checkout tags/6_1
mvn clean package
mvn jetty:run

http://localhost:8080/showcase/

However, the official showcase is here https://www.primefaces.org/showcase/index.xhtml but the published code can be incomplete, so better get it from github.


The examination of all these components can be really educational... nothing better to learn something than seeing it in action.

Friday, November 17, 2017

JSF crash course

Home page http://www.oracle.com/technetwork/java/javaee/javaserverfaces-139869.html , particularly this introduction https://docs.oracle.com/javaee/5/tutorial/doc/bnaph.html

Decent introduction https://www.youtube.com/watch?v=KwUAA4L_9AA&list=PLEAQNNR8IlB4S8nNUlS0ArfgU1nXlhdRu&index=1 (a bit too verbose, skip the central videos on how to install sw).

The helloworld code is here https://github.com/vernetto/JavaMonAmour/tree/master/pvjsfhello


Primefaces https://www.primefaces.org/

Richfaces http://richfaces.jboss.org/


Great collection of books on JSF http://www.javatechblog.com/java/best-books-to-learn-jsf-for-java-developers/ (mostly very ancient)


An excellent book is Core JavaServer Faces http://corejsf.com/ by David Geary and Cay Horstmann, 3rd edition



Sunday, November 1, 2015

Book: Pro JSF and HTML5



The book does a very good job at explaining the intricate history and structure of JSF framework, particularly regarding the CDI aspects. So definitely I would recommend it as an introduction to JSF.

However, I shake in terror at the idea of having to use JSF to develop font end application. The whole EL stuff reminds me of the days I have wasted trying to make JSTL tag library code work which fails silently... and JEE CDI seems to me another "magic under the hood" that becomes quite impossible to debug once anything goes wrong.

Besides, any attempt to write anything dynamic in a XML-like fashion should be straight away punished with 25 lashes on the back bottom. And any attempt to build complex expressions in a xhtml page using a combination of {, #, :, . , not validated by a compiler, is bound only to waste your life troubleshooting.

So, the learning curve is steep and the ways you can break the structure and waste days without any progress, infinite. It's a pity that frameworks like Vaadin don't get much attention and investment from big companies...

IMHO the root issue is that anybody with 2 hands and without at least a PhD in Mathematics can hack together a makeshift framework - glue, duct tape and some strings - and, if he hits the right market at the right time, find people who adopt it - for lack of a better alternative.



Saturday, October 31, 2015

Getting started with JSF and CDI and Primefaces

I have followed this tutorial http://reka-neva.blogspot.ch/2014/08/weblogic-jsf-2-tutorial.html


Deploy the application to a running WLS and test with http://localhost:7001/JSFWeb

You can login using this username/pw: ADMIN/password



The Java code uses the annotations
javax.enterprise.context.SessionScoped
javax.enterprise.inject.Model
javax.inject.Inject
javax.enterprise.inject.Produces


On the other hand, much more efficient if this approach https://www.mkyong.com/jsf2/primefaces/primefaces-hello-world-example/

and the code is https://github.com/vernetto/primefaces

Excellent article on JSF and CDI: https://dzone.com/articles/in-practice-dependency-injection-with-java-ee