Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>JSF creates bean instances called managed beans, which you can call from your pages using <code>#{}</code> wrapped expressions, also called <a href="http://docs.oracle.com/javaee/6/tutorial/doc/gjddd.html" rel="nofollow">EL expressions</a>. <code>#{timeBean.time}</code> is actually invoking <code>getTime()</code> getter from <code>timeBean</code> instance. Bean instances are referred by default with classes simple name with their first character lowercased.</p> <p>So having this bean:</p> <pre><code>@ManagedBean @RequestScoped public class TimeBean{ public Date getTime(){ return new Date(); } } </code></pre> <p>With <code>@ManagedBean</code> annotation we tell JSF that it need to be managed by it. With <code>@RequestScoped</code> we're expressing the scope of the bean, actually JSF will create one bean instance per browser request and will call <code>getTime()</code> getter method, each time you specify it in your page.</p> <p>For form fields, you must specify a variable which has both getter and setter methods. That's because JSF will <strong>set</strong> that value when form is processed.</p> <pre><code>@ManagedBean @RequestScoped public class TimeFormBean{ //Initializes time with current time when bean is constructed private Date time = new Date(); public Date getTime(){ //No logic here, just return the field return time; } public void setTime(Date d){ time=d; } public void processTime(){ System.out.println("Time processed: " + time); } } </code></pre> <p>Then you can use it in form inputs that way:</p> <pre class="lang-xml prettyprint-override"><code>&lt;h:form&gt; &lt;h:inputText value="#{timeFormBean.time}"&gt; &lt;f:convertDateTime pattern="yyyy-MM-dd"/&gt; &lt;/h:inputText&gt; &lt;h:commandButton value="process" action="#{timeFormBean.processTime}" /&gt; &lt;/h:form&gt; </code></pre>
    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