You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Geoff Clitheroe <G....@gns.cri.nz> on 2005/05/18 04:45:00 UTC

RE: Hibernate domain objects - how to load before parameter application

Hi,

I hope I have understood your question.  You can have page properties that are
beans and edit the property directly (validation can require another property).
The only possibly tricky bit is checking where you are at in the editing process
which I take care of in the pageBeginRender.

I have a page that is called EditPlace.  It may be editing a new or existing
place. Place and placeAddress are beans with a 1..0 between them.  There is a
little hidden logic in that Place and PlaceAddress are edited on separate tabs
and we don't let them add a PlaceAddress until there is a Place (hence the
conditional on the hidden field getPlaceId() only). I'll include just the
snippets that sound relevant to me, let me know if you want all the code.

As an aside we're using Hibernate + Spring + Tapestry which is working really
well and gives a very natural divide point for working with the other developer.
Spring was very fast to get up to speed with.

Cheers,
Geoff

// From EditPlace.page

<property-specification name="place" type="nz.org.geonet.delta.domain.Place"/>
<property-specification name="placeAddress"
type="nz.org.geonet.delta.domain.PlaceAddress"/>
...

// From EditPlace.java
....
  public void pageBeginRender(
                        PageEvent event
                        )
  {
    if (getPlace() == null) {
      Place place = new Place();
      PlaceAddress placeAddress = new PlaceAddress();
      setPlace(place);
      setPlaceAddress(placeAddress);
    }

    if (getPlaceId() != null) {
      loadPlace();
    }
  }

 private void loadPlace()
  {
    Long placeId = getPlaceId();
    placeUtil = getPlaceUtil();
    Place place = placeUtil.findPlaceById(placeId);
    setPlace(place);

    // At any point we could be editing a new PlaceAddress for an
    // existing Place, dealing with validation errors, or editing an
    // existing PlaceAddress.
    PlaceAddress placeAddress = getPlaceAddress();

    if (place.getPlaceAddress() == null && placeAddress == null) {
      placeAddress = new PlaceAddress();
    } else if (place.getPlaceAddress() != null) {
      placeAddress = place.getPlaceAddress();
    }

    setPlaceAddress(placeAddress);

    // Load the Set of maps and convert it to a List.
    List maps = new ArrayList();
    Set currMaps = place.getNzms260Sheets();
    for (Iterator iter = currMaps.iterator(); iter.hasNext() ; ) {
      Nzms260Sheet sheet = (Nzms260Sheet) iter.next();
      maps.add(sheet);
    }
    setSelectedNzms260Sheets(maps);
  }

  // Persists to DB
  public void addPlace(IRequestCycle cycle) {
    IValidationDelegate delegate = getValidationDelegate();

    if (delegate.getHasErrors()) {
      return;
    }

    Place place = getPlace();

      // Check that the notes field is not >500 in length
    if (place.getNotes().length() > 500) {

            setErrorField("inputTextArea", getMessage("textarea-length"));
            return;
      }

    placeUtil = getPlaceUtil();
    placeUtil.storePlace(place);

    setPlaceId(place.getPlaceId());
    cycle.activate(this);

    return;
  }

...

// From EditPlace.html
...
<input type="text" jwcid="@TextField" value="ognl:placeAddress.addressLine3"
size="50" maxlength="50" />

...



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