I've never had such a problem getting the simplest stuff to work in Java EE 6. I have an extremely basic project. I've tried debugging. Etc. I don't know what to do.
Here is my bean.
@Named(value = "contactsBean")
@SessionScoped
public class ContactsBean implements Serializable {
@EJB
ContactsFacade contactsEJB;
private List<Contacts> contacts = new ArrayList<Contacts>();
public ContactsBean() {
}
public String next() {
contacts = contactsEJB.findAll();
return "index";
}
/**
* @return the contacts
*/
public List<Contacts> getContacts() {
return contacts;
}
/**
* @param contacts the contacts to set
*/
public void setContacts(List<Contacts> contacts) {
this.contacts = contacts;
}
}
Ok. Pretty basic.
Here is my xhtml page.
<ui:define name="content">
<h:form>
<h:dataTable value="#{contactsBean.contacts}" var="contacts">
<h:column>
<f:facet name="header">
<h:outputText value="Name"/>
</f:facet>
<h:outputText value="#{contacts.name}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Street"/>
</f:facet>
<h:outputText value="#{contacts.street}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="City"/>
</f:facet>
<h:outputText value="#{contacts.city}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="State"/>
</f:facet>
<h:outputText value="#{contacts.state}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Zip"/>
</f:facet>
<h:outputText value="#{contacts.zip}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Country"/>
</f:facet>
<h:outputText value="#{contacts.country}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Sent?"/>
</f:facet>
<h:selectBooleanCheckbox value="#{contacts.sent}" />
</h:column>
</h:dataTable>
<h:commandButton value="next >" action="#{contactsBean.next}"/>
</h:form>
</ui:define>
Ok when I hit the next button my list should populate. At least it always did in Java EE 5 stuff. I'm not sure what I'm doing wrong. I was trying to do a simple paginator but even that wouldn't work. The model never gets updated.
What in the world is going on. I tried it without an EJB and it didn't work either.
I found out the reason.
There are to different packages with SessionScoped annotations.
javax.enterprise.context.SessionScoped and javax.faces.context.SessionScoped.
Since I'm using @Named(value = "contactsBean") injection I need to use javax.enterprise. @ManagedBean(name = "contactsBean") goes with javax.faces.context.
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.