jsf 2 - JSF 2.0: h:inputText inside composite component fails with non-String objects when validation is set -
in backing bean:
@min(3) integer foo;
if have form like:
<h:form> <h:commandbutton value="submit" /> <h:inputtext value="#{bean.foo}" /> </h:form>
this works ok. however, if like
<cc:interface> <cc:attribute name="text" /> <cc:editablevalueholder name="text" targets="field" /> <cc:interface> <cc:implementation> <h:inputtext id="field" value="#{cc.attrs.text}" /> </cc:implementation>
and call inside form instead of directly h:inputtext
in:
<!-- <h:inputtext value="#{bean.foo}" /> --> <pref:fieldcomponent text="#{bean.foo}" />
but get:
javax.validation.validationexception: unexpected exception during isvalid call @ org.hibernate.validator.engine.constrainttree.validatesingleconstraint(constrainttree.java:144) @ org.hibernate.validator.engine.constrainttree.validateconstraints(constrainttree.java:118) @ org.hibernate.validator.metadata.metaconstraint.validateconstraint(metaconstraint.java:121) @ org.hibernate.validator.engine.validatorimpl.validatevalueforgroup(validatorimpl.java:655) ...
and root cause is:
caused by: java.lang.classcastexception: java.lang.string cannot cast java.lang.number @ org.hibernate.validator.constraints.impl.minvalidatorfornumber.isvalid(minvalidatorfornumber.java:32) @ org.hibernate.validator.engine.constrainttree.validatesingleconstraint(constrainttree.java:141) ... 69 more
if remove validation, works. also, if foo
of type string
, works validations.
i tried playing cc:editablevalueholder
, defining different types (also omitting it) , few other tricks bit unsure how implement this. or bug? seems it's forgetting use converter? have misunderstood something?
as per comment on your ticket, turns out workaround explicitly specify type converter.
you follows
<pref:fieldcomponent text="#{bean.foo}"> <f:converter converterid="javax.faces.integer" /> </pref:fieldcomponent>
and
<cc:implementation> <h:inputtext id="field" value="#{cc.attrs.text}"> <cc:insertchildren /> </h:inputtext> </cc:implementation>
or maybe
<pref:fieldcomponent text="#{bean.foo}" converter="javax.faces.integer" />
and
<cc:implementation> <h:inputtext id="field" value="#{cc.attrs.text}" converter="#{cc.attrs.converter}" /> </cc:implementation>
Comments
Post a Comment