One way would be to create a backing component extending UIInput
and do the job in UIInput#getSubmittedValue()
. The child inputs are just directly available by findComponent()
.
<cc:interface componentType="inputPeriodicity">
...
</cc:interface>
<cc:implementation>
...
<p:spinner id="value_spinner" ... />
<p:selectOneMenu id="type_menu" ... />
...
</cc:implementation>
with
@FacesComponent("inputPeriodicity")
public class InputPeriodicity extends UIInput implements NamingContainer {
@Override
public String getFamily() {
return UINamingContainer.COMPONENT_FAMILY;
}
@Override
public Object getSubmittedValue() {
UIInput typeMenu = (UIInput) findComponent("type_menu");
String type = (String) typeMenu.getSubmittedValue();
if (type == null || type.isEmpty()) {
UIInput valueSpinner = (UIInput) findComponent("value_spinner");
valueSpinner.setSubmittedValue("0"); // Don't use int/Integer here!
}
return super.getSubmittedValue();
}
}
See also:
- Split java.util.Date over two h:inputText fields representing hour and minute with f:convertDateTime
Unrelated to the concrete problem, the <h:panelGrid id="#{cc.id}">
really isn't right. Give it a fixed ID instead if you really need to.