Author: ppitonak(a)redhat.com
Date: 2011-04-11 11:16:32 -0400 (Mon, 11 Apr 2011)
New Revision: 22411
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichCalendarBean.java
modules/tests/metamer/trunk/application/src/main/webapp/components/richCalendar/simple.xhtml
Log:
https://issues.jboss.org/browse/RF-9178
sample for calendar updated so that it's possible to test attribute validator
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichCalendarBean.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichCalendarBean.java 2011-04-11
15:02:00 UTC (rev 22410)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichCalendarBean.java 2011-04-11
15:16:32 UTC (rev 22411)
@@ -23,13 +23,18 @@
import java.io.Serializable;
import java.text.SimpleDateFormat;
+import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import javax.annotation.PostConstruct;
+import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
import javax.faces.event.ValueChangeEvent;
+import javax.faces.validator.ValidatorException;
import javax.validation.constraints.Future;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;
@@ -163,4 +168,21 @@
RichBean.logToPage("* value changed: " + oldDate + " -> "
+ newDate);
}
+
+ public void validateDate(FacesContext context, UIComponent component, Object value)
throws ValidatorException {
+ if (value == null) {
+ return;
+ }
+
+ Calendar cal = Calendar.getInstance();
+ cal.setTime((Date) value);
+ int componentYear = cal.get(Calendar.YEAR);
+
+ FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Date
too far in the past.",
+ "Select a date from year 1991 or newer.");
+
+ if (componentYear < 1991) {
+ FacesContext.getCurrentInstance().addMessage("form:calendar",
message);
+ }
+ }
}
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/richCalendar/simple.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/richCalendar/simple.xhtml 2011-04-11
15:02:00 UTC (rev 22410)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/richCalendar/simple.xhtml 2011-04-11
15:16:32 UTC (rev 22411)
@@ -158,6 +158,7 @@
tabindex="#{richCalendarBean.attributes['tabindex'].value}"
timeZone="#{richCalendarBean.timeZone}"
todayControlMode="#{richCalendarBean.attributes['todayControlMode'].value}"
+ validator="#{richCalendarBean.validateDate}"
validatorMessage="#{richCalendarBean.attributes['validatorMessage'].value}"
value="#{richCalendarBean.attributes['value'].value}"
valueChangeListener="#{richCalendarBean.valueChangeListener}"
@@ -168,7 +169,7 @@
<a4j:ajax event="change"
render="output, phasesPanel" />
</rich:calendar>
- <rich:message id="msg" for="calendar"/>
+ <rich:message id="msg" for="calendar"
showDetail="true" showSummary="true"/>
</div>
<br/><br/>