Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I now see why I couldn't reproduce this yesterday. In my playground environment I had accidentally the following context param set differently from the default value:</p> <pre class="lang-xml prettyprint-override"><code>&lt;context-param&gt; &lt;param-name&gt;javax.faces.PARTIAL_STATE_SAVING&lt;/param-name&gt; &lt;param-value&gt;false&lt;/param-value&gt; &lt;/context-param&gt; </code></pre> <p>This problem is related to JSF <a href="http://java.net/jira/browse/JAVASERVERFACES-1492" rel="nofollow noreferrer">issue 1492</a>. A <code>&lt;f:validateDoubleRange&gt;</code> whose attributes are by EL bound to a view scoped bean property will implicitly recreate the whole bean due to a nasty chicken-egg issue, because validators are created on a per-request basis and those properties are to be passed on validator's construction.</p> <hr> <p>If you do not want to disable partial state saving (very reasonable), then your best bet is to create and hold the validator in the view scoped managed bean yourself:</p> <pre><code>public Validator getValidator() { return new DoubleRangeValidator(foo.getMaximum(), foo.getMinimum()); } </code></pre> <p><em>(note, doing this stuff in a getter is a bad design, but since you're preparing <code>foo</code> in a setter instead of a <code>preRenderView</code> listener method, there's no other way, otherwise it would be done right in the same listener method)</em></p> <p>with</p> <pre class="lang-html prettyprint-override"><code>&lt;h:inputText validator="#{fooController.validator.validate}" ...&gt; </code></pre> <hr> <p>Or, alternatively, to create a custom validator for that which replaces the <code>&lt;f:validateDoubleRange&gt;</code>:</p> <pre class="lang-html prettyprint-override"><code>&lt;f:validator validatorId="bindableDoubleRangeValidator" /&gt; &lt;f:attribute name="minimum" value="#{fooController.foo.minAmount}" /&gt; &lt;f:attribute name="maximum" value="#{fooController.foo.maxAmount}" /&gt; </code></pre> <p>with</p> <pre><code>package com.example; import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; import javax.faces.validator.DoubleRangeValidator; import javax.faces.validator.FacesValidator; import javax.faces.validator.ValidatorException; @FacesValidator("bindableDoubleRangeValidator") public class BindableDoubleRangeValidator extends DoubleRangeValidator { @Override public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { setMinimum((Double) component.getAttributes().get("minimum")); setMaximum((Double) component.getAttributes().get("maximum")); super.validate(context, component, value); } } </code></pre> <hr> <p><strong>Update</strong>: the chicken-egg issue 1492 is fixed since Mojarra 2.1.18 (January 2013). So if you stumble upon this these days, then you could also consider to just upgrade.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload