Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does f:validateDoubleRange only work for @SessionScoped?
    text
    copied!<p>Can someone explain to me why Foo in my example is always null when it gets to the validateDoubleRange class? The end result is the min value for the validator is always 0. The number 3 displays just fine on the page when in the outputText element. It validates fine if I make the bean <code>@SessionScoped</code> instead of <code>@ViewScoped</code></p> <p>Controller:</p> <pre><code>import java.io.Serializable; import java.math.BigDecimal; import javax.faces.bean.ManagedBean; import javax.faces.bean.ViewScoped; @ViewScoped @ManagedBean(name = "fooController") public class FooController implements Serializable { private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(FooController.class); private static final long serialVersionUID = 1L; private Foo foo; private BigDecimal amount; private Long fooId; public Long getFooId() { return fooId; } public void setFooId(Long fooId) { this.fooId = fooId; this.foo = new Foo(); foo.setFooId(fooId); foo.setMinAmount(Double.valueOf(3)); foo.setMaxAmount(Double.valueOf(10)); } public Foo getFoo() { return foo; } public void sendAmount() { log.debug("sendAmount: " + amount); } public BigDecimal getAmount() { return amount; } public void setAmount(BigDecimal amount) { this.amount = amount; } public static class Foo { private Long fooId; private Double minAmount; private Double maxAmount; public Foo() { } public void setFooId(Long fooId) { this.fooId = fooId; } public void setMinAmount(Double minAmount) { this.minAmount = minAmount; } public void setMaxAmount(Double maxAmount) { this.maxAmount = maxAmount; } public Long getFooId() { return fooId; } public Double getMaxAmount() { return maxAmount; } public Double getMinAmount() { return minAmount; } } } </code></pre> <p>JSP: </p> <pre><code>&lt;ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" &gt; &lt;f:metadata&gt; &lt;f:viewParam name="fooId" value="#{fooController.fooId}" /&gt; &lt;/f:metadata&gt; &lt;h:form id="myForm"&gt; &lt;h:outputText value="This is correctly displayed: '#{fooController.foo.minAmount}'"/&gt;&lt;br/&gt; &lt;h:outputText value="My Input:" /&gt; &lt;h:inputText id="myInput" value="#{fooController.amount}" required="true" &gt; &lt;f:convertNumber maxFractionDigits="2"/&gt; &lt;f:validateDoubleRange minimum="#{fooController.foo.minAmount}" maximum="80"/&gt; &lt;/h:inputText&gt; &lt;h:message for="myInput"/&gt; &lt;br/&gt; &lt;h:commandButton id="myButton" value="Save Amount" action="#{fooController.sendAmount}" &gt; &lt;/h:commandButton&gt; &lt;/h:form&gt; &lt;/ui:composition&gt; </code></pre> <p>I am using JSF 2 on JBoss 6.1</p> <p>If you are out there @BalusC, this is the simplest example I could come up with, and is the same problem as yesterday, just, I hope, clarified and simpler to replicate.</p> <p>-- edit, I should add that fooId is set via a view param, so you need ?fooId=3 at the end of your URL.</p>
 

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