tags:

views:

57

answers:

1

Hello All! Now i'm working with EJB 3 in Stateless Bean i create method get all instance of entity About

public List<About> retrieveAllAbout(){

       return em.createNameQuery("About.findAll").getResultList();
    }

Now i want get one row of list to pass to js page. How can i do it

in jsf page ( xhtml) i want show one value of list example

<h:outputText value="#{bean.value}" />

(in database i have one row only one row i want select, otherway if i have many row how can i select and get one row and show it to JSF page)

+1  A: 

Try using getSingleResult method and get your "retrieveAllAbout" method to return "About" object instead of List. In case there are more rows in database and you are trying to get the first one use getFirstResult. Otherwise you would have to be more specific when defining the query.

javax.persistence.Query

cbaby
i try using getSingleResult method but not work for me, in JSF ManagedBean i create new instance in constructor of JSF Manage bean sample `public Constructor(){ About = new About(statelessbean.retreiveAllAbout)}` in about entity i create constructor sample `public About(String value){ this.value = value}` please help me
MYE
@MYE: About is not a String, so your constructor is never getting called. Besides, there is no need to call a constructor. In Java all variables are passed by value, but all object variables are actually references. There are a few things wrong with your code: "About" is your class name and therefor cannot be used as a variable; There is no need to call a constructor as your function is returning an object reference. So your code should look something like this: public Constructor(){ about = statelessbean.retriveAllAbout;}. You need to have default constructor in your bean.
cbaby
@MYE: changing `getResultList()` to `getFirstResult()` in the code as you posted in the question will work. If you'd like to call it only once, use `@PostConstruct`, because `em` is not yet injected when constructed is called. If still in vain, ask a new question. This is unrelated to the problem as in the current question.
BalusC
thank two you i can do it :D but i have new question i will post it , please help me :D with new question
MYE