この質問を使用して、時間セレクターの動作を備えた複合コンポーネントを作成します。
これは私の複合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>
これは私のFacesコンポーネントです
@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();
}
}
そして使い方
<sigh:time date="#{bean.date}" hasSeconds="false"/>
私のテストケース:
<h:outputLabel value="#{controller.date}" id="date" />
<sigh:time date="#{controller.date}" />
<a4j:commandButton render="date" />
「コントローラー」:
@ManagedBean
public class Controller {
Date date;
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
}
これはうまく機能しますが、null Date を属性として渡すと機能しません。どうすれば Bean (controller.date) の値を更新できますか?
私のテストケースでは、コントローラーの a4j:commandButton を押して日付が null の場合、出力ラベルに何も表示されません (日付が null)。日付が null でない場合、ボタンをクリックするたびに日付が更新されます。
私の悪い英語でごめんなさい。
ありがとう!