2

I have an application being developed in jsf 2.0, primefaces and using Eclipse Kepler IDE. I need to display a string value in dataTable for long value. There could be 6 possible values from 1 to 6. i have followed this question to solve my issue but i cant. my code snipped is

  <p:dataTable var="student" value="#{studentBean.studentList}">
  <p:column headerText="Class">
    <h:outputText value="#{student.studentClass == 1? 'One' :
                           student.studentClass == 2? 'Second' :
                           student.studentClass == 3? 'Third' :
                           student.studentClass == 4? 'Fourth' :
                           student.studentClass == 5? 'Fifth':
                           student.studentClass == 6? 'Sixth':''}" />
  </p:column>
      ....

i also tried:-

   student.studentClass.equals(1l) and  student.studentClass.equals(1L)

but no luck. What am i doing wrong

Community
  • 1
  • 1
jaykio77
  • 379
  • 1
  • 7
  • 22

2 Answers2

1

Wouldn't this approach work too?

<h:outputText rendered="#{student.studentClass == 1}" value="One" />
<h:outputText rendered="#{student.studentClass == 2}" value="Two" />
 ...
<h:outputText rendered="#{student.studentClass == 6}" value="Six" />
raven
  • 2,381
  • 2
  • 20
  • 44
1

I would prefer adding a simple change in the model, say:

Class Pojo/Entity

public class Student{

   ...

   // Add transient annotation only if is an entity class
   @Transient
   private String valueToShow;

   public String getValueToShow(){
     if("1".equals(this.studentClass){
       return "One";
     } else if("2".equals(this.studentClass){
       return "Two";
     }
       ...
  }

}

Then, add this change to the xhtml file (JSF Page):

<p:dataTable var="student" value="#{studentBean.studentList}">
  <p:column headerText="Class">
    <h:outputText value="#{student.valueToShow}" />
  </p:column>
  ....
Rene Enriquez
  • 1,418
  • 1
  • 13
  • 33