You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Harish Krishnaswamy <hk...@comcast.net> on 2003/08/25 15:30:45 UTC
Re: Help with the DirectLink example please
Does it throw an exception? Have you declared the Visit class in your
application specification? I am not sure if the Visit class can have the
"friendly" modifier, try making it public.
-Harish
Mindaugas Genutis wrote:
>Hello,
>
>I'm trying to run the example from the Tapestry Component
>DirectLink documentation. When I run it, it doesn't show the customer list
>- the list is empty. The visit.getCustomerList() isn't invoked. Here's the
>code of the example, what have I done wrong?:
>
>I think the SalesPage class has to somehow be connected with the Visit
>class from which the customers are loaded. The whole concept of the
>example is unclear to me.
>
>+---------------------------------------------------+
>The SalesPage.java code:
>
>public class SalesPage extends BasePage
>{
> private User user;
>
> public User getUser()
> {
> return user;
> }
>
> public void setUser(User value)
> {
> user = value;
> }
>
> public void customerSelectAction(IRequestCycle cycle)
> {
> Visit visit = (Visit) getVisit();
> Object[] parameters = cycle.getServiceParameters();
> User user = visit.findCustomerByPrimaryKey((Integer)
>parameters[0]);
> // Perform some action with the selected customer.
>
> }
>
> public void customerDeleteAction(IRequestCycle cycle)
> {
> Visit visit = (Visit) getVisit();
> Object[] parameters = cycle.getServiceParameters();
> User user = visit.findCustomerByPrimaryKey((Integer)
>parameters[0]);
> visit.deleteCustomer(user);
> }
>
> protected void initialize()
> {
> user = null;
> }
>}
>+---------------------------------------------------+
>
>+---------------------------------------------------+
>The Visit.java class:
>
>class Visit implements Serializable
>{
> public List getCustomerList()
> {
> ManagerFactory managerFactory = new ManagerFactory();
> UserManager userManager = managerFactory.createUserManager();
>
> Iterator users = userManager.loadUsers();
>
> List customerList = new ArrayList();
>
> while (users.hasNext())
> {
> User user = (User) users.next();
> customerList.add(user);
> }
>
> return customerList;
> }
>
> public User findCustomerByPrimaryKey(Integer id)
> {
> User user = null;
> // Retrieve the customer from the database with given the customer
>ID.
>
> return user;
> }
>
> public void deleteCustomer(User user)
> {
> // Delete customer from the database.
>
> }
>}
>+---------------------------------------------------+
>
>
>+---------------------------------------------------+
>The SalesPage.html:
>
><span jwcid="@Border">
>
><table cellspacing="6">
> <tr>
> <td>ID</td>
> <td> </td>
> <td>First Name</td>
> <td> </td>
> <td>Last Name</td>
> <td> </td>
> </tr>
> <tr>
> <td colspan="6"><hr></td>
> </tr>
> <tr jwcid="@Foreach" source="ognl:visit.customerList" value="ognl:user"
>element="tr">
> <td><span jwcid="@Insert" value="ognl:user.id"/></td>
> <td> </td>
> <td><a jwcid="@DirectLink"
>listener="ognl:listeners.customerSelectAction" parameters="ognl:user.id">
><span jwcid="@Insert" value="ognl:user.firstName"/> </a></td>
> <td> </td>
> <td><span jwcid="@Insert" value="ognl:user.lastName"/></td>
> <td>
> <a jwcid="@DirectLink" listener="ognl:listeners.customerDeleteAction"
>parameters="ognl:user.id" onclick="return window.confirm('Are you sure you
>want remove this customer?');">
> Delete
> </a>
> </td>
> </tr>
></table>
>
></span>
>+---------------------------------------------------+
>
>+---------------------------------------------------+
>The page SalesPage.page specification
>
><page-specification class="lt.ktu.distance.elearn.pages.SalesPage">
>
></page-specification>
>+---------------------------------------------------+
>
>
>Thanks,
>
>
>