バッキング付きの複合コンポーネントを作成しましたUIInput
。数字スピナーが含まれています。スピナーが変更されると、新しい値はバッキング コンポーネントに送信されません。
状況を単純化しました (バッキングは不要に思えますが、それでも問題は発生します)。
はSytem.out.println
問題を浮き彫りにします。
複合コンポーネント:
<cc:interface componentType="periodInput" >
<cc:attribute name="value" type="org.joda.time.Period" />
</cc:interface>
<cc:implementation>
<p:spinner id="count" min="0" binding="#{cc.countComponent}" converter="javax.faces.Integer" label="Every "/>
</cc:implementation>
バッキング コンポーネント:
@FacesComponent("periodInput")
public class PeriodBacking extends UIInput implements NamingContainer {
private UIInput countComponent;
// And getter & setter.
@Override
public void encodeBegin(FacesContext context) throws IOException {
Period period = (Period) getValue();
if(period == null) {
period = Period.weeks(1).withPeriodType(PeriodType.weeks());
}
int count;
count = period.get(period.getFieldTypes()[0]);
countComponent.setValue(count);
super.encodeBegin(context);
}
@Override
public Object getSubmittedValue() {
return this;
}
@Override
protected Object getConvertedValue(FacesContext context, Object newSubmittedValue) {
// PROBLEM: Always prints out '1':
System.out.println("Count: " + count);
int count = (Integer) countComponent.getValue();
Period totalPeriod = new Period(0).withDays(count);
return totalPeriod;
}
@Override
public String getFamily() {
return UINamingContainer.COMPONENT_FAMILY;
}
}
複合コンポーネントは次のように使用されます。
<custom:Period value="#{cc.attrs.trackedproduct.samplePeriod}" />
Beanのどこtrackedproduct
に存在するか。@ViewScoped