This content has been marked as final.
Show 1 reply
-
1. Re: Help required in passing primary key for getting list of values corresponding to key
sappo Apr 27, 2010 5:34 PM (in response to vasukihn)Hi Vasuki,
a possible solution for your problem is to create a list and push it via @DataModel to your view. If an action is executed on the table the selected customer is automatically pushed into the beans selecedCustomer attribute.
And I guess that your entites have a relationship so it should be no problem for you to obtain the location data from a customer entity like the function 'showLocations' does.@Name("customerAction") @Scope(ScopeType.SESSION) public class CustomerAction implements Serializable { @In private EntityManager entityManager; @DataModel private List<Customer> customerList; @DataModelSelection(value = "customerList") @Out(required = false) private Customer selectedCustomer; @DataModel private List<Location> locationList; @Factory(value="customerList") public List<Customer> initCustomerList() { return (ArrayList<Customer>) entityManager.createQuery("SELECT e FROM EnglishDictionary e") .getResultList(); } public void showLocations() { locationList = selectedCustomer.getLocations(); }
To display the location result in your home.xhtml you wont render the locationsPanel until a customer has been selected and his locations are loaded.
<rich:panel id="custerPanel"> <rich:dataTable id="customerTable" value="#{customerList}" var="_customer"> <rich:column> <f:facet value="header">Customer name</f:facet> <h:outputText value="#{_customer.name}" /> </rich:column> <rich:column> <f:facet> value="header">Action</f:facet> <h:commandButton action="#{customerAction.showLocation}" /> </rich:column> </rich:dataTable> </rich:panel> <rich:panel id="locationPanel" rendered="#{not empty locationList}"> <f:facet name="header">selectedCustomer.name</f:facet> <rich:dataTable id="locationTable" value="#{locationList}" var="_location"}"> <rich:column> <f:facet value="header">Location name</f:facet> <h:outputText value="#{_location.name}" /> </rich:column> </rich:dataTable> </rich:panel>
//Kevin