I use this questions to create a composite component with the behaviour of a time selector.
This is my composite xhtml
<ui:composition xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:cc="http://java.sun.com/jsf/composite"
xmlns:rich="http://richfaces.org/rich">
<cc:interface componentType="customTimeBean">
<cc:attribute name="date" type="java.util.Date" required="true" />
</cc:interface>
<cc:implementation>
<rich:inputNumberSpinner value="#{cc.hours}" minValue="0"
maxValue="23" />
<h:outputLabel value=":" />
<rich:inputNumberSpinner value="#{cc.minutes}" minValue="0"
maxValue="59" />
</cc:implementation>
</ui:composition>
This is my Faces Component
@FacesComponent(value = "customTimeBean")
public class CustomTimeBean extends UINamingContainer {
private Date getDate() {
Date d = (Date) getAttributes().get("date");
if (d == null) {
//throw new RuntimeException("Date no debe ser nulo");
d = new date();
}
return d;
}
public void setMinutes(int value) {
getDate().setMinutes(value);
}
public void setHours(int value) {
getDate().setHours(value);
}
public int getMinutes() {
return getDate().getMinutes();
}
public int getHours() {
return getDate().getHours();
}
public void setSeconds(int value) {
getDate().setHours(value);
}
public int getSeconds() {
return getDate().getSeconds();
}
}
And the usage
<sigh:time date="#{bean.date}" hasSeconds="false"/>
My test case:
<h:outputLabel value="#{controller.date}" id="date" />
<sigh:time date="#{controller.date}" />
<a4j:commandButton render="date" />
The "controller":
@ManagedBean
public class Controller {
Date date;
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
}
This works well, but, this doesn't work when I pass a null Date as attribute, how can I update the value in the Bean (controller.date)?
In my test case, when I press the a4j:commandButton and date in the controller is null, the outputlabel dont show nothing (date is null), when the date is not null, the date is update everytime I click the Button.
Sorry for my bad english.
Thanks!