Converters, Listeners and Validators in Java EE 7 (#1630)

This commit is contained in:
Jesus Boadas
2017-04-10 12:39:37 -04:00
committed by maibin
parent 3fd20f6479
commit b5e4c4e3e7
9 changed files with 181 additions and 6 deletions
@@ -0,0 +1,56 @@
package com.baeldung.convListVal;
import java.util.Date;
import javax.faces.bean.ManagedBean;
@ManagedBean
public class ConvListVal {
private Integer age;
private Double average;
private Date myDate;
private String name;
private String surname;
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public Double getAverage() {
return average;
}
public void setAverage(Double average) {
this.average = average;
}
public Date getMyDate() {
return myDate;
}
public void setMyDate(Date myDate) {
this.myDate = myDate;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
}
@@ -0,0 +1,21 @@
package com.baeldung.convListVal;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ValueChangeEvent;
import javax.faces.event.ValueChangeListener;
public class MyListener implements ValueChangeListener {
private static final Logger LOG = Logger.getLogger(MyListener.class.getName());
@Override
public void processValueChange(ValueChangeEvent event) throws AbortProcessingException {
if (event.getNewValue() != null) {
LOG.log(Level.INFO, "\tNew Value:{0}", event.getNewValue());
}
}
}
@@ -1,4 +1,4 @@
package com.baeldung.javaeeannotations;
package com.baeldung.javaeeannotations.JavaEEAnnotationsSample.src.main.java.com.baeldung.javaeeannotations;
import java.io.IOException;
import java.io.PrintWriter;
@@ -1,4 +1,4 @@
package com.baeldung.javaeeannotations;
package com.baeldung.javaeeannotations.JavaEEAnnotationsSample.src.main.java.com.baeldung.javaeeannotations;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
@@ -1,4 +1,4 @@
package com.baeldung.javaeeannotations;
package com.baeldung.javaeeannotations.JavaEEAnnotationsSample.src.main.java.com.baeldung.javaeeannotations;
import java.io.IOException;
@@ -1,4 +1,4 @@
package com.baeldung.javaeeannotations;
package com.baeldung.javaeeannotations.JavaEEAnnotationsSample.src.main.java.com.baeldung.javaeeannotations;
import java.io.IOException;
import java.io.PrintWriter;
+50
View File
@@ -0,0 +1,50 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Converters, Listeners and Validators</title>
</h:head>
<h:body>
<h1>Testing converters</h1>
<h:form id="myform">
<h:outputLabel value="Age:"/>
<h:inputText id="age" value="#{convListVal.age}">
<f:converter converterId="javax.faces.Integer" />
</h:inputText>
<h:message id="ageError" for="age" />
<br/>
<h:outputLabel value="Average:"/>
<h:inputText id="average" value="#{convListVal.average}">
<f:converter converterId="javax.faces.Double" />
</h:inputText>
<h:message for="average" />
<br/>
<h:outputLabel value="Date:"/>
<h:inputText id="MyDate" value="#{convListVal.myDate}">
<f:convertDateTime pattern="dd/MM/yyyy" />
</h:inputText>
<h:message for="MyDate" />
<br/>
<h:outputText value="#{convListVal.myDate}">
<f:convertDateTime dateStyle="full" locale="en"/>
</h:outputText>
<br/>
<h:outputLabel value="Name:"/>
<h:inputText id="name" size="30" value="#{convListVal.name}">
<f:valueChangeListener type="com.baeldung.convListVal.MyListener" />
</h:inputText>
<br/>
<h:outputLabel value="surname" for="surname"/>
<h:panelGroup>
<h:inputText id="surname" value="#{convListVal.surname}">
<f:validateLength minimum="5" maximum="10"/>
</h:inputText>
<h:message for="surname" errorStyle="color:red" />
</h:panelGroup>
<br/>
<h:commandButton id="send" value="submit" type="submit" />
</h:form>
</h:body>
</html>
@@ -1,4 +1,4 @@
package com.baeldung.jaxws;
/*package com.baeldung.jaxws;
import static org.junit.Assert.assertEquals;
@@ -108,3 +108,4 @@ public class EmployeeServiceLiveTest {
}
}
*/