简体   繁体   中英

How to bind facelets to CDI beans?

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. )

I will answer my own question:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM