-1

I have a function that I derclare beans in my manager and I want to return the value in inputText but when I put the name of my function in the value attribute of inputText tag like this:

<p: inputText value = "#{ticketBean.getLastIndexTache} "/> 

this error appear:

Etat HTTP 500 - /pages/test.xhtml @13,106 value="#{ticketBean.getLastIndexTache}": Property 'getLastIndexTache' not found on type com.bean.TicketBean

here is the java code

@ManagedBean(name="ticketBean") 
public class TicketBean {
public int getLastIndexTache() {
        Session session =  HibernateUtil.getSessionFactory().getCurrentSession();
            int index = 0;
            try {
                session.beginTransaction();
                String sql = "select MAX(t.IDTICKET) from ticket t ";
                Query query = session.createSQLQuery(sql);
                if( query.uniqueResult()==null){

                    index=0;
                }else{

                    index=(int) query.uniqueResult();
                    index=index+1;
                }
            } catch (HibernateException e) {
                // TODO: handle exception
                session.getTransaction().rollback();
                e.printStackTrace();
            }
                return index;
            }
}
user3850191
  • 29
  • 1
  • 6

1 Answers1

2

You should use the bean property in value like

<p:inputText value="#{ticketBean.lastIndexTache}"/> 

as JSF by itself adds "get" to the property name. Currently it will look for the method getGetLastIndexTache().

Besides its very bad practice to have logic in any getter as they are called multiple times by JSF. Instead you should make an property like

private Integer lastIndexTache; // +getter/setter

and set the value in a @PostConstruct method:

@PostConstruct
public void init() {
    Session session =  HibernateUtil.getSessionFactory().getCurrentSession();
    // etc....
    lastIndexTache = index;
 }

The getter would then simply be

public Integer getLastIndexTache() {
    return lastIndexTache;
}

and don't forget a setter:

public void setLastIndexTache(Integer newValue) {
   lastIndexTache = newValue;
}

Also you should probably put a scope on the bean (for example @ViewScoped).

Jaqen H'ghar
  • 4,305
  • 2
  • 14
  • 26