-
1. Re: validateDoubleRange in rich:extendedDataTable?
nbelaevski Sep 14, 2009 6:35 AM (in response to tobi04)Hi Tobi,
Does this work outside rich:extendedDataTable? -
2. Re: validateDoubleRange in rich:extendedDataTable?
tobi04 Sep 14, 2009 8:07 AM (in response to tobi04)Hi nbelaevski,
no, the following example does not work, too. In the second column #{bean.max} has the right value:<h:dataTable value="#{bean.testList}" var="bean" binding="#{bean.testTable}"> <h:column> <h:inputText id="price" value="#{bean.value}" size="5"> <f:validateDoubleRange minimum="0" maximum="#{bean.max}"/> <rich:ajaxValidator event="onblur"/> </h:inputText> <rich:message for="price" /> </h:column> <h:column> <h:outputText value="#{bean.max}" /> </h:column> </h:dataTable>
Best regards
Tobi -
3. Re: validateDoubleRange in rich:extendedDataTable?
nbelaevski Sep 14, 2009 8:39 AM (in response to tobi04)Hi Tobi,
The second code snippet sheds some light on the problem - f:validateDoubleRange won't work correctly with the dynamic range, because range values are evaluated when the validator is created and "bean" iteration variable is not available at this point. Workarounds: call some method that will validate the value of "bean" object or try providing validator using EL-expression and create new instance of validator according to the allowed range each time. -
4. Re: validateDoubleRange in rich:extendedDataTable?
tobi04 Sep 14, 2009 11:34 AM (in response to tobi04)Hi nbelaevski,
thanks for your replys!
Can you please give an short example of your first approach "call some method that will validate"?
In your second approach (own validator) I see the the difficulty to get the value of #{bean.max) in the java code:
ManagedBean orderBean:
------------public void myValidateDoubleRange(FacesContext cxt, UIComponent comp, Object obj) throws ValidatorException {
...
xhtml:
------<h:inputText id="price" value="#{bean.value}" size="5" validator="orderBean.myValidateDoubleRange" />
On the jsf site I am working with<rich:ajaxValidator event="onblur"/>
, so the java method myValidateDoubleRange() get called every time I leave the input field.
So, in myValidateDoubleRange() I have to know, which #{bean.max) value belongs to the current input field.
How can I get access to #{bean.max) in the java method myValidateDoubleRange()? With FacesContext, ...?
Best regards
Tobi -
5. Re: validateDoubleRange in rich:extendedDataTable?
nbelaevski Sep 15, 2009 6:42 AM (in response to tobi04)Either check "eval" method from this article: http://www.ilikespam.com/blog/el-vs-dependency-injection or create method that will validate content in "bean" itself - http://www.ibm.com/developerworks/library/j-jsf3/ - "Validation methods in backing beans".
-
6. Re: validateDoubleRange in rich:extendedDataTable?
tobi04 Sep 15, 2009 2:01 PM (in response to tobi04)Hi nbelaevski,
thanks for the links!
With the eval("#{bean.max)") method I got what I want in myValidateDoubleRange() validation method in the backing bean.
http://www.ilikespam.com/blog/el-vs-dependency-injection
"eval" method:/** * Shorthand for Application.evaluateExpressionGet(...) which automatically casts the result to * expected type and uses the current FacesContext for evaluating the expression. * * @param expression * the EL expression to evaluate * @param clazz * the expected resultant class */ @SuppressWarnings("unchecked") public static <T extends Object> T eval(String expression, Class<T> clazz) { return (T) FacesContext.getCurrentInstance().getApplication().evaluateExpressionGet( FacesContext.getCurrentInstance(), expression, clazz); }
Best regards
Tobi