Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem binding a bean property to an element in JSF
    text
    copied!<p>I have an input (JSF) that should be bound to a property in my bean. This property represents another bean and has an auxiliar method that checks if it's null (I use this method a lot).</p> <p>The problem is that the binding is failing to get the proper getter and setter. Instead of reading the method that returns the bean, it reads the one that return a boolean value.</p> <p>The property name is <strong>guest</strong>. The methods are:</p> <ul> <li>getGuest;</li> <li>setGuest;</li> <li>isGuest (checks if guest is null).</li> </ul> <p>JSF is trying to bind the object to <em>isGuest</em> and <em>setGuest</em>, instead of <em>getGuest</em> and <em>setGuest</em>.</p> <p>I cannot rename <em>isGuest</em> to <em>guestIsNull</em> or something, because that would'nt make to much sense (see the class below).</p> <p>Finally, my question is: <strong>how can I bind this property to the object without renaming my methods? Is it possible?</strong></p> <p>I also accept suggestions of a better method name (but the meaning must be the same).</p> <hr> <p><strong>Entity</strong></p> <pre><code>@Entity public class Passenger { private Employee employee; private Guest guest; public Passenger() { } @Transient public boolean isEmployee() { return null != this.employee; } @Transient public boolean isGuest() { return null != this.guest; } @OneToOne public Employee getEmployee() { return this.employee; } public void setEmployee(Employee employee) { this.employee = employee; } @OneToOne public Guest getGuest() { return this.guest; } public void setGuest(Guest guest) { this.guest = guest; } } </code></pre> <p><strong>JSF</strong></p> <pre><code>&lt;h:inputText value="#{passenger.employee}" /&gt; &lt;h:inputText value="#{passenger.guest}" /&gt; </code></pre>
 

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