Skip to content

Commit 13d226c

Browse files
IvanLjubicicdaoire
authored andcommitted
BAEL-1303 Intro to Primefaces (eugenp#3874)
* ivan.ljubicic.app.developer@gmail.com * Added unit tests, configuration class and minor adjustments * primefaces intro module added * deleted primefaces old module * deleted different bean injection types sample project * deleted addition different bean injection types file * Renaming archetype in web.xml * Added primefaces in jsf module * Primefaces improvements * Added commandButton and dialog * Added PFM * Code formatting * Update pom.xml * Formatting changes
1 parent a86f9de commit 13d226c

6 files changed

Lines changed: 259 additions & 1 deletion

File tree

‎jsf/pom.xml‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@
7373
<scope>provided</scope>
7474
<version>${javax.servlet.version}</version>
7575
</dependency>
76+
77+
<!-- Primefaces -->
78+
<dependency>
79+
<groupId>org.primefaces</groupId>
80+
<artifactId>primefaces</artifactId>
81+
<version>6.2</version>
82+
</dependency>
7683
</dependencies>
7784

7885
<build>
@@ -103,6 +110,6 @@
103110

104111
<!-- maven plugins -->
105112
<maven-war-plugin.version>2.6</maven-war-plugin.version>
106-
</properties>
107113

114+
</properties>
108115
</project>
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package com.baeldung.springintegration.controllers;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import javax.annotation.PostConstruct;
7+
import javax.el.ELContextEvent;
8+
import javax.el.ELContextListener;
9+
import javax.faces.bean.ManagedBean;
10+
import javax.faces.bean.ViewScoped;
11+
12+
@ManagedBean(name = "helloPFBean")
13+
@ViewScoped
14+
public class HelloPFBean {
15+
16+
private String firstName;
17+
private String lastName;
18+
19+
private String componentSuite;
20+
21+
private List<Technology> technologies;
22+
23+
private String inputText;
24+
private String outputText;
25+
26+
@PostConstruct
27+
public void init() {
28+
firstName = "Hello";
29+
lastName = "Primefaces";
30+
31+
technologies = new ArrayList<Technology>();
32+
33+
Technology technology1 = new Technology();
34+
technology1.setCurrentVersion("10");
35+
technology1.setName("Java");
36+
37+
technologies.add(technology1);
38+
39+
Technology technology2 = new Technology();
40+
technology2.setCurrentVersion("5.0");
41+
technology2.setName("Spring");
42+
43+
technologies.add(technology2);
44+
}
45+
46+
public void onBlurEvent() {
47+
outputText = inputText.toUpperCase();
48+
}
49+
50+
public String getFirstName() {
51+
return firstName;
52+
}
53+
54+
public void setFirstName(String firstName) {
55+
this.firstName = firstName;
56+
}
57+
58+
public String getLastName() {
59+
return lastName;
60+
}
61+
62+
public void setLastName(String lastName) {
63+
this.lastName = lastName;
64+
}
65+
66+
public String getComponentSuite() {
67+
return componentSuite;
68+
}
69+
70+
public void setComponentSuite(String componentSuite) {
71+
this.componentSuite = componentSuite;
72+
}
73+
74+
public List<Technology> getTechnologies() {
75+
return technologies;
76+
}
77+
78+
public void setTechnologies(List<Technology> technologies) {
79+
this.technologies = technologies;
80+
}
81+
82+
public String getInputText() {
83+
return inputText;
84+
}
85+
86+
public void setInputText(String inputText) {
87+
this.inputText = inputText;
88+
}
89+
90+
public String getOutputText() {
91+
return outputText;
92+
}
93+
94+
public void setOutputText(String outputText) {
95+
this.outputText = outputText;
96+
}
97+
98+
public class Technology {
99+
private String name;
100+
private String currentVersion;
101+
102+
public String getName() {
103+
return name;
104+
}
105+
106+
public void setName(String name) {
107+
this.name = name;
108+
}
109+
110+
public String getCurrentVersion() {
111+
return currentVersion;
112+
}
113+
114+
public void setCurrentVersion(String currentVersion) {
115+
this.currentVersion = currentVersion;
116+
}
117+
118+
}
119+
120+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.baeldung.springintegration.controllers;
2+
3+
import javax.faces.bean.ManagedBean;
4+
import javax.faces.bean.SessionScoped;
5+
6+
@ManagedBean(name = "helloPFMBean")
7+
@SessionScoped
8+
public class HelloPFMBean {
9+
10+
private String magicWord;
11+
12+
public String getMagicWord() {
13+
return magicWord;
14+
}
15+
16+
public void setMagicWord(String magicWord) {
17+
this.magicWord = magicWord;
18+
}
19+
20+
public String go() {
21+
if (this.magicWord != null && this.magicWord.toUpperCase()
22+
.equals("BAELDUNG")) {
23+
return "pm:success";
24+
}
25+
return "pm:failure";
26+
}
27+
28+
}

‎jsf/src/main/webapp/WEB-INF/faces-config.xml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
</var>
2626
</resource-bundle>
2727
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
28+
29+
<navigation-handler>
30+
org.primefaces.mobile.application.MobileNavigationHandler
31+
</navigation-handler>
32+
33+
<!-- <default-render-kit-id>PRIMEFACES_MOBILE</default-render-kit-id> -->
2834
</application>
2935

3036
<navigation-rule>

‎jsf/src/main/webapp/pf_intro.xhtml‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4+
<html xmlns="http://www.w3.org/1999/xhtml"
5+
xmlns:h="http://java.sun.com/jsf/html"
6+
xmlns:f="http://java.sun.com/jsf/core"
7+
xmlns:ui="http://java.sun.com/jsf/facelets"
8+
xmlns:p="http://primefaces.org/ui">
9+
10+
<h:head>
11+
<title>Hello Primefaces</title>
12+
</h:head>
13+
<h:body>
14+
<h:form id="primeForm">
15+
16+
<p:panelGrid columns="2">
17+
<h:outputText value="#{helloPFBean.firstName}" />
18+
<h:outputText value="#{helloPFBean.lastName}" />
19+
</p:panelGrid>
20+
21+
<h:panelGrid columns="2">
22+
<p:outputLabel for="jsfCompSuite" value="Component Suite" />
23+
<p:selectOneRadio id="jsfCompSuite"
24+
value="#{helloPFBean.componentSuite}">
25+
<f:selectItem itemLabel="ICEfaces" itemValue="ICEfaces" />
26+
<f:selectItem itemLabel="RichFaces" itemValue="RichFaces" />
27+
</p:selectOneRadio>
28+
</h:panelGrid>
29+
30+
<p:dataTable var="technology" value="#{helloPFBean.technologies}">
31+
<p:column headerText="Name">
32+
<h:outputText value="#{technology.name}" />
33+
</p:column>
34+
35+
<p:column headerText="Version">
36+
<h:outputText value="#{technology.currentVersion}" />
37+
</p:column>
38+
</p:dataTable>
39+
40+
<h:panelGrid columns="3">
41+
<h:outputText value="Blur event " />
42+
<p:inputText id="inputTextId" value="#{helloPFBean.inputText}">
43+
<p:ajax event="blur" update="outputTextId"
44+
listener="#{helloPFBean.onBlurEvent}" />
45+
</p:inputText>
46+
<h:outputText id="outputTextId" value="#{helloPFBean.outputText}" />
47+
<p:commandButton value="Open Dialog" icon="ui-icon-note"
48+
onclick="PF('exDialog').show();">
49+
</p:commandButton>
50+
</h:panelGrid>
51+
52+
<p:dialog header="Example dialog" widgetVar="exDialog" minHeight="40">
53+
<h:outputText value="Hello Baeldung!" />
54+
</p:dialog>
55+
56+
</h:form>
57+
58+
</h:body>
59+
</html>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<html xmlns="http://www.w3.org/1999/xhtml"
2+
xmlns:ui="http://java.sun.com/jsf/facelets"
3+
xmlns:h="http://java.sun.com/jsf/html"
4+
xmlns:f="http://java.sun.com/jsf/core"
5+
xmlns:p="http://primefaces.org/ui"
6+
xmlns:pm="http://primefaces.org/mobile">
7+
<f:view renderKitId="PRIMEFACES_MOBILE" />
8+
<h:head>
9+
</h:head>
10+
<h:body>
11+
<pm:page id="enter">
12+
<pm:header>
13+
<p:outputLabel value="Introduction to PFM"></p:outputLabel>
14+
</pm:header>
15+
<pm:content>
16+
<h:form id="enterForm">
17+
<pm:field>
18+
<p:outputLabel value="Enter Magic Word"></p:outputLabel>
19+
<p:inputText id="magicWord" value="#{helloPFMBean.magicWord}"></p:inputText>
20+
</pm:field>
21+
<p:commandButton value="Go!" action="#{helloPFMBean.go}"></p:commandButton>
22+
</h:form>
23+
</pm:content>
24+
</pm:page>
25+
<pm:page id="success">
26+
<pm:content>
27+
<p:outputLabel value="Correct!"></p:outputLabel>
28+
<p:button value="Back" outcome="pm:enter?transition=flow"></p:button>
29+
</pm:content>
30+
</pm:page>
31+
<pm:page id="failure">
32+
<pm:content>
33+
<p:outputLabel value="That is not the magic word"></p:outputLabel>
34+
<p:button value="Back" outcome="pm:enter?transition=flow"></p:button>
35+
</pm:content>
36+
</pm:page>
37+
</h:body>
38+
</html>

0 commit comments

Comments
 (0)