0

I have a simple xhtml page with:

<h:form>
    <p:dataTable var="customer" value="#{customersTableBackingBean.allCustomers}">
        <p:column headerText="First Name">
            <h:outputText value="#{customer.contactFirstName}" />
        </p:column>

        <p:column headerText="City">
            <h:outputText value="#{customer.city}" />
        </p:column>

    </p:dataTable>
</h:form>

When my CustomersTableBackingBean.java is as follows:

@ManagedBean
@RequestScoped
public class CustomersTableBackingBean {

    @EJB(name = "#{customersService}")
    CustomersService customersService;

    public List<Customers> getAllCustomers(){
        return customersService.getAllCustomers();
    }

    public String sayHello(){
        return "Hello from a managed bean!";
    }

}

I see some data fetched from the database, on index.xhtml as expected.

However when I change the @ManagedBean annotation to @Named and import: javax.inject.Named there is no data in index.xhtml.

What is wrong with this structure?

How can I use a CDI bean instead of a JSF ManagedBean?

( I have a beans.xml file which is empty. )

Koray Tugay
  • 22,894
  • 45
  • 188
  • 319
  • By the way I also keep the @ResuestScoped annotation and import: import javax.enterprise.context.RequestScoped; import javax.inject.Named; – Koray Tugay May 26 '13 at 21:23
  • Seems that you haven't learnt the basics yet: stop having business logic in your getter/setters. Refer to [Why JSF calls getters multiple times](http://stackoverflow.com/q/2090033/1065197) – Luiggi Mendoza May 27 '13 at 02:08

1 Answers1

0

I will answer my own question:

beans.xml goes to web-inf folder not to meta-inf !

Koray Tugay
  • 22,894
  • 45
  • 188
  • 319
  • 3
    Also, you would use `@Named` instead of `@ManagedBean` and the `@RequestScoped` annotation must be from package `javax.enterprise.context`. – Luiggi Mendoza May 27 '13 at 02:10