Any Seam example using JSF binding attribute?
dxxvi Feb 24, 2009 10:39 AMMy SFSB
@Stateful
@Name("customerList")
public class CustomerListImpl implements CustomerList {
@Logger
protected Log log;
@PersistenceContext(type= PersistenceContextType.EXTENDED)
protected EntityManager entityManager;
@DataModel
protected List<Customer> customers;
protected HtmlScrollableDataTable dataTable;
protected SimpleSelection selection;
public void viewSelectedRows() {
Iterator<Object> iterator = selection.getKeys();
while (iterator.hasNext()) {
Object key = iterator.next();
dataTable.setRowKey(key);
Object customer = dataTable.getRowData();
customer = null;
}
}
@SuppressWarnings("unchecked")
public void findCustomers() {
customers = entityManager.createQuery("select c from Customer c").getResultList();
}
@Destroy
@Remove
public void destroy() {
}
public HtmlScrollableDataTable getDataTable() {
return dataTable;
}
public void setDataTable(HtmlScrollableDataTable dataTable) {
this.dataTable = dataTable;
}
public SimpleSelection getSelection() {
return selection;
}
public void setSelection(SimpleSelection selection) {
this.selection = selection;
}
}My local interface:
@Local
public interface CustomerList {
void viewSelectedRows();
void findCustomers();
void destroy();
HtmlScrollableDataTable getDataTable();
void setDataTable(HtmlScrollableDataTable dataTable);
SimpleSelection getSelection();
void setSelection(SimpleSelection selection);
}My xhtml (I know that this is not suggested because the dataTable and selection are conversational-scoped):
<a4j:form>
<rich:scrollableDataTable value="#{customers}" var="customer" width="70px" height="200px"
selectedClass="selectedRow" binding="#{customerList.dataTable}"
selection="#{customerList.selection}">
<rich:column width="48px">
<f:facet name="header">ID</f:facet>
<h:outputText value="#{customer.id}"/>
</rich:column>
</rich:scrollableDataTable>
<p/>
<a4j:commandLink value="View Selected Rows" action="#{customerList.viewSelectedRows}"
reRender="selectedRowBox"/>
</a4j:form>
<p/>
<h:panelGroup id="selectedRowBox">
</h:panelGroup>When I accessed that xhtml page, I got exceptions:
javax.servlet.ServletException: /customers.xhtml @16,73 binding=#{customerList.dataTable}
: Target Unreachable, identifier 'customerList' resolved to null
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:277)
at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:427)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:333)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
If I don't use binding and selection attributes in the <rich:scrollableDataTable>, I don't see exceptions and I can click on the View Selected Box and go to the viewSelectedRows method.
What did I do wrong?