validation - Validator in composite throws ClassCastException when using java.lang.Double value -


i had 2 field validator working without composite 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 composite java.lang.classcastexception: java.lang.string cannot cast java.lang.double: on

double firstdouble = (double) value; , not on

double seconddouble = (double) component.getattributes().get("seconddouble");

here 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 weird 1 value comes on string , other double. change double firstdouble = double.parsedouble(value); first double , not worry why component.getattributes() still passed validator double (the actual type of attribute in java bean) though composite seems same far 2 fields go , move on?

edit

here composite interface. after specifying type, still 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>    ... 

i can't reproduce problem. works me mojarra 2.2.10 on tomcat 8.0.21 without explicit type attribute in <cc:attribute type="java.lang.double">.

as workaround explicitly declare converter below in composite's input component:

<p:inputtext ... converter="javax.faces.double"> 

but mojarra 2.1.7 old (feb 2012). should consider upgrading latest 2.1.x, 2.1.29 (jul 2014) or perhaps 2.2.x. can find jboss server mojarra upgrade instructions in answer: upgrade jsf / mojarra in jboss / eap / wildfly.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -