• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Hyperlinks and action methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Hyperlinks and action methods


  • Subject: Re: Hyperlinks and action methods
  • From: David LeBer <email@hidden>
  • Date: Sun, 30 Mar 2008 23:11:21 -0400


On 30-Mar-08, at 10:44 PM, Chris Meyer wrote:

One pattern I find myself using often is that I have a page listing my objects (PeopleList) and a detail page (PersonDetail).

In my PeopleList component, I have a WORepetition of WOHyperlink's linking to specific PersonDetails.

To facilitate the hyperlink, I have an action in PeopleList.java that creates a new PeopleDetail page and sets the iterated Person in the WORepetition into a variable on that new page.

My questions:

Is this the right design pattern to use?

If so, is there any way to use ognl or some other mechanism to avoid writing the action method in PeopleList.java that loads the new page and sets the Person variable on the new page?

If not, is there any fundamental reason why this cannot be done automatically (with some syntax modifications/improvements in the WOParser, or whatever)?

<cough>DirectToWeb</cough>

Failing that, create some superclasses for you components to inherit from that contain the generic behaviour you want:

ListPage.java

	public EOEnterpriseObject listItem;
	public String detailsPageName; // set in your subclass;

	...

	public WOComponent goToDetailsPage() {
		WOComponent nextPage = pageWithName(detailsPageName);
		nextPage.takeValueForKey(listItem, "detailItem");
		return nextPage;
	}


DetailsPage.java

	private EOEnterpriseObject _detailItem;
	private WOComponent _backPage;

	public DetailsPage(WOContext context) {
		super(context);
		setBackPage(this.context().page());
	}

	public EOEnterpriseObject detailItemt() {
		return _detailsItem;
	}

	public void setDetailItem(EOEnterpriseObject obj) {
		_detailItem = obj;
	}

	public WOComponent backPage() {
		return _backPage;
	}

	public void setBackPage(WOComponent page) {
		_backPage = page;
	}

	public WOComponent saveChanges() {
		WOComponent nextPage = backPage();
		try  {
			detailItem.editingContext().saveChanges();
		} catch (Exception e) {
			// EXAMPLE ONLY :-)
			nextPage = null;
		}
		return nextPage;
	}


PeopleList.wo:

<ul>
<wo:WORepetition list="people" item="person">
<li><wo:WOHyperlink action="gotoPersonDetail"><wo:string value="$person.name"/></wo:WOHyperlink></li>
</wo:WORepetition>
</ul>


PeopleList.java

class PeopleList
{
  public Person person;

// can this be avoided?
public WOComponent gotoPersonDetail()
{
PersonDetail pd = (PersonDetail)pageWithName(PersonDetail.class.getSimpleName());
pd.person = person;
return pd;
}
}


PersonDetail.java

class PersonDetail
{
  public Person person;
}

Code comment: Ooo ick - using public ivars in your api! - wrap that person with accessors!


;david

--
David LeBer
Codeferous Software
'co-def-er-ous' adj. Literally 'code-bearing'
site:   http://codeferous.com
blog: http://davidleber.net
profile: http://www.linkedin.com/in/davidleber
--
Toronto Area Cocoa / WebObjects developers group:
http://tacow.org


_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Hyperlinks and action methods
      • From: "Chris Meyer" <email@hidden>
References: 
 >Hyperlinks and action methods (From: "Chris Meyer" <email@hidden>)

  • Prev by Date: Hyperlinks and action methods
  • Next by Date: Re: Hyperlinks and action methods
  • Previous by thread: Hyperlinks and action methods
  • Next by thread: Re: Hyperlinks and action methods
  • Index(es):
    • Date
    • Thread