You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Learner <ge...@attglobal.net> on 2004/02/07 01:31:24 UTC

Re: Responding to buttons in tables - example please

Ezra Epstein <eepstein <at> prajnait.com> writes:

> 
> Please do post the example either here and/or on the component reference
> page.  I think it would be of use to many.
> 
> == Ezra E.

Yes, please post an example, or perhaps fix up my code, shown below - it 
displays the table OK but can't respond to the button presses because it 
doesn't know the row of the button or the personKey associated with the row.  

Here's what the table should look like

----------------------------
| Name   |        |        |
---------------------------|
| Bob    | Change | Delete |
| Carol  | Change | Delete |
| Ted    | Change | Delete |
| Alice  | Change | Delete |
----------------------------

Snippet from .html
------------------

<table jwcid="<at>contrib:TableView" tableModel="ognl:locationsTableModel"  
class="grid">
     <tr>
          <td jwcid="<at>contrib:TableColumns"/>
          <td></td>
          <td></td>
     </tr>
		
     <tr jwcid="@contrib:TableFormRows" row="ognl:currentPerson">
          <td jwcid="@contrib:TableValues" align="center"/>
          <td><input type="submit" jwcid="@Submit" label="Change..." 
                       listener="ognl:listeners.changePerson"/></td>
          <td><input type="submit" jwcid="@Submit" label="Delete..." 
                       listener="ognl:listeners.deletePerson"/></td>
     </tr>
</table>

Snippet from .page
------------------

<page-specification class="mypackage.WorkWithPersonsPage">
	<property-specification name="personsTableModel" 
type="org.apache.tapestry.contrib.table.model.ITableModel" persistent="yes"/>
	<property-specification name="currentPerson" type="java.lang.String"/>
</page-specification>

Snippet from .java
------------------

public abstract class WorkWithPersonsPage extends MyBasePage {
	public abstract ITableModel getPersonsTableModel();
	public abstract void setPersonsTableModel(ITableModel value);
	
	public void finishLoad() {
		setup();
	}

	public void setup() {

		try {
			// Put a table of all persons onto the page
			setPersonsTableModel(refreshPersonsModel());
		}
		catch (ValidationException e) {
			setErrorMessage(e.toString());
		}
		catch (Exception e) {
			throw new ApplicationRuntimeException(e);
		}

	}

	public SimpleTableModel refreshPersonsModel() throws Exception {
		MyEngine engine = (MyEngine) getEngine();
		PersonFinderBusinessInterface personFinder = engine.getPersonFinder();

		List personsList = personFinder.findAllPersons();
		Object[] personsArray = personsList.toArray();

//>>> How do I get personKey into the rows of the table?

		ITableColumnModel columnModel =
			new ExpressionTableColumnModel(
				new String[] {
					"Name",
					"name" },
				true);

		SimpleTableModel personsTableModel =
			new SimpleTableModel(personsArray, columnModel);

		return personsTableModel;
	}

	public void changePerson(IRequestCycle cycle) {
		
//>>>> How do I get the personKey of the button's rpw?

		ChangePersonPage nextPage = 
                    (ChangePersonPage) cycle.getPage("ChangePerson");
		nextPage.setup(personKey);
		cycle.activate(nextPage);

	}

End of snippet
--------------


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org