Re: WOHyperlinks following recursive relationships in a component
Re: WOHyperlinks following recursive relationships in a component
- Subject: Re: WOHyperlinks following recursive relationships in a component
- From: LD <email@hidden>
- Date: Sun, 23 Jan 2005 19:06:50 +1100
Hi there,
On 22/01/2005, at 4:43 AM, David Holt wrote:
I have a component that displays images called DisplayImage. It has
WOhyperlinks to previous image, next image, parent image, and child
images.
<...>
Is there a way to set up my WOHyperlinks so that they can pass the
value of the related images? i.e. How do I pass the object that
anImage.prevImage.Image_name points to to the DisplayImage page? Also,
I wanted to call the same action from all of the WOHyperlinks because
they all pass different Image objects to the same component. Is this
possible, or do I have to call a separate action with each link?
Yes, it's possible and logical.
It'd be a good idea to keep the basic logic encapsulated into your
custom ProcessImage class (and accompanying reusable navigational
component if applicable) rather than in each component. It's possibly
more reusable than what you've come up with (based on the other posts)
and can save the user from re-requesting the same page should a next,
previous or parent image not be a valid option (i.e., you instead
either hide the option or display some other place holder).
(a) in your ProcessImage class add the following methods (if you
haven't already got them):
public boolean hasNext() {...}
public boolean hasParent() {...}
public boolean hasPrevious() {...}
these will be bound to the respective WOConditionals that your
WOHyperlinks will appear in (and negated WOConditionals can be used
when the condition is false).
(b) add a WOForm to your Component with binding...
NavForm: WOForm {
action = navigateToRelatedImage;
}
(c) add a single element to your form: a WOHiddenField with bindings:
NavField: WOHiddenField {
name = "navField";
value = nextImageKeyName;
}
(c) add your navigational WOHyperlinks (wrapping each WOHyperlink in
non-negated WOConditionals and whatever you would like to display,
should the condition be false, inside negated WOConditional elements)
laying them out as desired.
e.g., ...
PreviousImageFalse: WOConditional {
condition = currentImage.hasPrevious;
negate = true;
}
PreviousImageTrue: WOConditional {
condition = currentImage.hasPrevious;
}
PreviousLink: WOHyperlink {
href = "javascript:sendNavRequest('previousImage')";
}
... and likewise for your Next and Parent options.
(d) add some javascript to head of your component's html (to set the
value of the hidden field and then to submit the form):
<script type=text/javascript>
<!-- Nav script
function getNavField() {
var fields = document.getElementsByName('navField');
return fields[0];
}
function sendNavRequest(aRequest) {
var navField = getNavField();
navField.value = aRequest;
navField.form.submit();
}
// End of Nav Script -->
</script>
(e) In your WOComponent:
public DisplayImage extends WOComponent
{
ProcessImage currentImage;
String nextImageKeyName;
<...>
public DisplayImage navigateToRelatedImage()
{
DisplayImage nextPage = (DisplayImage)pageWithName("DisplayImage");
ProcessImage nextImage =
(ProcessImage)valueForKeyPath("currentImage." + nextImageKeyName);
nextPage.setImage(nextImage);
return nextPage;
}
<...>
}
HTH
with regards,
--
Lachlan Deck
_______________________________________________
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