Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF <c:if <c:choose problem

I'm new in JSF and I have some strange problems in displaying conditional parts in form.

My Facelet:

<h:form id="animalForm">
    <h:selectOneRadio id="animal" onchange="submit()" value="#{index.animal}">
      <f:selectItem itemLabel="Cat" itemValue="1"/>
      <f:selectItem itemLabel="Dog" itemValue="2"/>
    </h:selectOneRadio>
  </h:form>
  <h:outputText value="#{index.animal}"/>
  <c:if test="#{index.animal eq 1}">
    <h:outputText value="Cat"/>
  </c:if>
  <c:if test="#{index.animal eq 2}">
    <h:outputText value="Dog"/>
  </c:if>

And My Bean:

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;


@ManagedBean(name = "index")
@RequestScoped
public class IndexBean {
  public static final int CAT = 1;
  public static final int DOG = 2;
  private int animal;

  public IndexBean() {

  }

  public int getAnimal() {
    return animal;
  }

  public void setAnimal(int animal) {
    this.animal = animal;
  } 

}

When I select one item the value will be displayed for exampel (1 or 2) but nothing else will display on the form??? What is wrong with my code???

like image 670
ehsun7b Avatar asked Feb 25 '23 12:02

ehsun7b


1 Answers

Use the rendered attribute (<h:outputText rendered="#{index.animal eq 1}" />) for conditional displaying of components. Using JSTL is tricky with JSF.

like image 132
Bozho Avatar answered Mar 02 '23 18:03

Bozho