title: Calling methods in jsf
body: <p>I wanted to make the possibility of booking /remove  booking the product page.
  Reservations is ok, removing unfortunately not ...</p>
  
  <pre><code>@ManagedBean(name = "wardrobeDetailsBean")
  @SessionScoped
  //@RequestScoped
  public class WardrobeDetailsBean implements Serializable {
  
      @Inject
      WardrobeService wardrobeService;
      @Inject
      AuthBean authBean;
  
      // other fields + setters, getters
  
      @ManagedProperty("#{param.id}")
      private Long id;
  
      public Long getId() {
          return id;
      }
  
      public void setId(Long id) {
          this.id = id;
      }
  
      public String getUsernameReserving() {
          this.selectedWardrobe = wardrobeService.getWardrobeById(id);
          String usernameById = selectedWardrobe.getReservingUserId().getUsername();
          StringBuilder sb = new StringBuilder();
          sb.append(usernameById.substring(0, 2));
          sb.append("...");
          sb.append(usernameById.substring(usernameById.length() - 2, usernameById.length()));
          return sb.toString();
      }
  
      @PostConstruct
      public void init() {
          if (FacesContext.getCurrentInstance().getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
              dbImage1 = new DefaultStreamedContent();
          } else if (id != null) {
              this.selectedWardrobe = wardrobeService.getWardrobeById(id);
              }
          }
      }
  
      public String reserve() {
          this.selectedWardrobe = wardrobeService.getWardrobeById(id);
          if (authBean.getUser() != null &amp;&amp; authBean.getUser().getId() != null) {
              selectedWardrobe.setReservingUserId(authBean.getUser());
              wardrobeService.reserveProduct(selectedWardrobe);
              return null;
          } else {
              return "/login.xhtml?faces-redirect=true";
          }
      }
  
      public void unreserve() {
          this.selectedWardrobe = wardrobeService.getWardrobeById(id);
          selectedWardrobe.setReservingUserId(null);
          wardrobeService.reserveProduct(selectedWardrobe);
      }
  }
  </code></pre>
  
  <p><em>productView.xhtml</em></p>
  
  <pre><code>&lt;h:commandButton id="reserve" styleClass="btn-u btn-u-sea-shop btn-u-lg" rendered="#{wardrobeDetailsBean.selectedWardrobe.reservingUserId eq null}"
      value="Reserve" action="#{wardrobeDetailsBean.reserve()}"&gt;
          &lt;f:ajax execute="@form" render="reservePanel"/&gt;
  &lt;/h:commandButton&gt;
  
  &lt;h:outputText value="This product has been reserved by #{wardrobeDetailsBean.usernameReserving}" rendered="#{wardrobeDetailsBean.selectedWardrobe.reservingUserId ne null}"/&gt;
  &lt;br /&gt;
   &lt;input type="hidden" name="remoteUser" value="#{request.remoteUser}"/&gt; 
  // added using guidance from the answers
  &lt;h:commandButton id="unreserve" styleClass="btn-u btn-u-red btn-u-lg" rendered="#{request.remoteUser eq wardrobeDetailsBean.selectedWardrobe.reservingUserId.username}"
      value="Unreserve" action="#{wardrobeDetailsBean.unreserve()}"&gt;
          &lt;f:ajax execute="@form" render="reservePanel"/&gt;
  &lt;/h:commandButton&gt;
  </code></pre>
  
  <p>When I removed the <code>rendered="#{request.remoteUser eq wardrobeDetailsBean.selectedWardrobe.reservingUserId.username}"</code>, it works.</p>
  
  <p>When the reservation is clicked it should only be visible button for removal.
  What is wrong, it does not work? The log any errors I have not.</p>
  
  <p>After using guidance from the answers, application works like this.
  <a href="https://i.stack.imgur.com/Gxvd6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Gxvd6.png" alt="enter image description here"></a></p>
  
  <p>I click "Reserve". The product has been reserved, the button will be swapped.</p>
  
  <p><a href="https://i.stack.imgur.com/BoQ1O.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BoQ1O.png" alt="enter image description here"></a></p>
  
  <p>I click "Unreserve" and still the method is not called, I lose the information about the product (refresh the page returns information about the product, but the product is still reserved)</p>
  
  <p><a href="https://i.stack.imgur.com/NKth2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NKth2.png" alt="enter image description here"></a></p>