Showing posts with label primefaces. Show all posts
Showing posts with label primefaces. Show all posts

Saturday, May 26, 2018

Spring Boot 2 and Primefaces 6..... JoinFaces

http://joinfaces.org/ and https://github.com/joinfaces/joinfaces

Their started app is https://joinfaces-example.herokuapp.com/starter.jsf admin is persapiens/123)

git clone https://github.com/joinfaces/joinfaces-maven-jar-example.git
cd joinfaces-maven-jar-example
mvn clean install
(there are some test errors.... ignore them)

java -jar target/joinfaces-example-3.2.1-SNAPSHOT.jar

http://localhost:8080/starter.jsf


Unfortunately they use a parent pom....in Maven you can use only 1 parent pom (another reason to HATE MAVEN who is BROKEN BY DESIGN).... so if your application is already based on a parent pom, you are royally screwed.

Problem is, when I generate a project from Spring Boot Starters, the parent pom is:

<parent>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-parent</artifactId>
 <version>2.0.2.RELEASE</version>
 <relativePath/> <!-- lookup parent from repository -->
</parent>


while using joinfaces it's


<parent>
        <groupId>org.joinfaces</groupId>
        <artifactId>joinfaces-parent</artifactId>
        <version>3.2.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>


you can clearly see from http://central.maven.org/maven2/org/joinfaces/joinfaces-parent/3.2.1/joinfaces-parent-3.2.1.pom that joinfaces includes all these dependencies http://central.maven.org/maven2/org/joinfaces/joinfaces-dependencies/3.2.1/joinfaces-dependencies-3.2.1.pom which entail also a parent:

<parent>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-parent</artifactId>
 <version>2.0.2.RELEASE</version>
 <relativePath/>
 <!-- lookup parent from repository -->
</parent>

No doubt, they have sorted out for you a massive dependency tree, saving a lot of time.

When I see such massive dependency tree, the question arises, why the Java world in 2018 is so ridiculously complicated and only getting worse. Please stop proliferation, focus on consolidation.











Thursday, April 5, 2018

primefaces cookbook on wildfly

The book is covering in depth many examples available on the official PF showcase. Don't expect advanced programming techniques, it's purely about implement not-so-common use cases in PF


sample code is here https://github.com/ova2/primefaces-cookbook

git clone git://github.com/ova2/primefaces-cookbook.git
cd primefaces-cookbook
mvn install

copy $MAVEN_REPO/org/primefaces/cookbook/showcase/2.0.0/showcase-2.0.0.war to /opt/wildfly12/standalone/deployments

http://localhost:8180/pf-cookbook/ (or http://localhost:8080/pf-cookbook/ )



Friday, March 30, 2018

Wildfly file upload and download with Primefaces

Sample application available here https://github.com/vernetto/pffile

https://www.primefaces.org/docs/api/6.2/org/primefaces/model/UploadedFile.html


https://stackoverflow.com/a/8880083/651288 read BalusC comments


in pom.xml add this:
<dependency>
 <groupId>commons-fileupload</groupId>
 <artifactId>commons-fileupload</artifactId>
 <version>1.3</version>
</dependency>
<dependency>
 <groupId>commons-io</groupId>
 <artifactId>commons-io</artifactId>
 <version>2.2</version>
</dependency>

in web.xml add this:

<filter>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>



If you get this error:

io.undertow.server.RequestTooBigException: UT000020: Connection terminated as request was larger than 10485760

change the max-post-size parameter:

Configuration: Subsystems Subsystem: Web/HTTP - Undertow Settings: HTTP


<subsystem xmlns="urn:jboss:domain:undertow:5.0">
<buffer-cache name="default"/>
<server name="default-server">
<http-listener name="default" socket-binding="http" max-post-size="1000000000" redirect-socket="https" enable-http2="true"/>


Missing features: enable streaming for large files, show progress bar




Tuesday, December 19, 2017

Primefaces PushEndpoint for WebSockets

https://www.primefaces.org/docs/api/6.1/org/primefaces/push/annotation/PushEndpoint.html


"An Endpoint for Push operation executed from by RemoteEndpoint or using an EventBus. A class annotated with this annotation must at least have one method annotated with OnOpen, OnClose or OnMessage."


https://www.primefaces.org/primefaces-push-2-0/


https://github.com/Atmosphere/atmosphere



https://www.primefaces.org/showcase/push/notify.xhtml



Wednesday, December 6, 2017

Primefaces themes

see https://stackoverflow.com/questions/30253826/how-to-do-themeswitcher-using-primefaces

see https://www.primefaces.org/showcase/ui/misc/themeSwitcher.xhtml


add this to your pom.xml


<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>all-themes</artifactId>
<version>1.0.10</version>
</dependency>


in the web.xml the primefaces.THEME should be dynamically assigned:

<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>#{guestPreferences.theme}</param-value>
</context-param>

use this themeSwitcher in a page

<h:form>
<p:outputLabel for="basic" value="Basic:" />
<p:themeSwitcher id="basic" style="width:165px">
<f:selectItem itemLabel="Choose Theme" itemValue="" />
<f:selectItems value="[afterdark, afternoon, afterwork, aristo, black-tie, blitzer, bluesky, bootstrap, casablanca, cupertino, cruze, dark-hive, delta, dot-luv, eggplant, excite-bike, flick, glass-x, home, hot-sneaks, humanity, le-frog, midnight, mint-choc, omega, overcast, pepper-grinder, redmond, rocket, sam, smoothness, south-street, start, sunny, swanky-purse, trontastic, ui-darkness, ui-lightness, vader]" var="theme" itemLabel="" itemValue=""/>
</p:themeSwitcher>
</h:form>




Saturday, December 2, 2017

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




Saturday, November 25, 2017

Primefaces gmap

<h:head>
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>


<p:gmap center="41.381542, 2.122893" zoom="15" type="HYBRID" style="width:100%;height:400px" />


https://developer.mozilla.org/en-US/docs/Mozilla/Debugging/Debugging_JavaScript enable browser console:
about:config
devtools.chrome.enabled set it to true

then Ctrl-Shift-J (in firefox)


"Google Maps API error: MissingKeyMapError https://developers.google.com/maps/documentation/javascript/error-messages#missing-key-map-error" js:38
"Google Maps API warning: NoApiKeys https://developers.google.com/maps/documentation/javascript/error-messages#no-api-keys" util.js:246
"Google Maps API warning: SensorNotRequired https://developers.google.com/maps/documentation/javascript/error-messages#sensor-not-required"


in reality one should provide a key

<script src="http://maps.google.com/maps/api/js?key=MY_API_KEY" type="text/javascript"></script>

https://developers.google.com/maps/documentation/javascript/get-api-key?utm_source=geoblog&utm_medium=social&utm_campaign=2016-geo-na-website-gmedia-blogs-us-blogPost&utm_content=TBC



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.