I had a two field validator working without the composite as follows
public class DoubleMustBeGreaterThanSecondDouble implements Validator {
@Override
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
Double firstDouble = (Double) value;
Double secondDouble = (Double) component.getAttributes().get("secondDouble");
if (firstDouble <= secondDouble) {
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, null, null);
throw new ValidatorException(msg);
}
}
}
<p:inputText size="5"
validatorMessage="Plate maximum thickness must exceed plate minimum thickness"
value="#{calculator.boltAnalysis.plate1.maximum_thickness}">
<f:validator
validatorId="doubleMustBeGreaterThanSecondDouble" />
<f:attribute name="secondDouble"
value="#{calculator.boltAnalysis.plate1.minimum_thickness}" />
<p:ajax event="change" update="@this" />
</p:inputText>
But after converting to a composite I get java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Double:
on just the
Double firstDouble = (Double) value;
and not on the
Double secondDouble = (Double) component.getAttributes().get("secondDouble");
here it is as the composite
<p:inputText size="5"
validatorMessage="Plate maximum thickness must exceed plate minimum thickness"
value="#{cc.attrs.plateMaximumThickness}">
<f:validator
validatorId="doubleMustBeGreaterThanSecondDouble" />
<f:attribute name="secondDouble"
value="#{cc.attrs.plateMinimumThickness}" />
<p:ajax event="change" update="@this" />
</p:inputText>
<stk:plate
plateLabel="3"
plateMinimumThickness="#{calculator.boltAnalysis.plate3.minimum_thickness}"
plateMaximumThickness="#{calculator.boltAnalysis.plate3.maximum_thickness}"
/>
It is weird that one value comes over as a String and the other as a Double. Do I just change to Double firstDouble = Double.parseDouble(value);
for my first double and not worry why the component.getAttributes()
is still passed to the validator as a double (the actual type of the attribute in the Java Bean) even though the composite seems the same as far as those two fields go and just move on?
EDIT
Here is my composite interface. Even after specifying the type, I still get class cast exception
<composite:interface>
<composite:attribute name="plateLabel" />
<composite:attribute name="plateMinimumThickness" type="java.lang.Double" />
<composite:attribute name="plateMaximumThickness" type="java.lang.Double" />
</composite:interface>
<composite:implementation>
...