Re: onChange with WOPopUpButton
Re: onChange with WOPopUpButton
- Subject: Re: onChange with WOPopUpButton
- From: LD <email@hidden>
- Date: Sun, 7 Aug 2005 16:25:57 +1000
Hi there,
On 07/08/2005, at 9:48 AM, Baiss Eric Magnusson wrote:
LD wrote:
...Now, instead of having numerous booleans in your code, you can
utilise the cool WOKeyValueConditional to show the relevant
component...
Not having used WOKeyValueConditional's I read your post with
interest but am not sure it will do what I need.
I have several WOPopUpButton's on a page and use the
<onChange = "javascript:this.form.submit();";>
to get to an action binding.
None of the WOPopUpButton's are inside WOConditionals and the only
way I've known how to handle the different WOPopUpButton's is to
put each of them inside their own WOForm so that the particular
action I want will occur with the particular form.
No, WOKeyValueConditional is useful for determining whether or not
some element(s) are displayed or not based on a value (as referenced
by a key). e.g., "if the term 'hairColour' returns the value 'brown'
then the condition is true" - render the items. i.e., in the RR
(request-response) cycle, WOKeyValueConditional is useful in
determining whether some items are appended to the response but
doesn't have any affect on the request from a client.
However., the key-value ideas can be utilised in other ways...
I try to read from your posting that I can somehow name a key-value
pair to tell me which of the WOPopUpButton's was acted on is a
single WOForm's action method.
Is their a way from one action of one form to know which of the
WOPopUpButton's is hit?
My <selection> binding of the WOPopUpButton's is set to a reference
variable of a different class for each of the WOPopUpButton's.
So, let's say we have two WOPopUpButtons/classes, Road-Runner and
Coyote. Each have different choices in life (according to the script).
==Strategy #1 (a single hidden form is submitted)==
__Component.java__
NSArray roadRunners;
NSArray coyotes;
RoadRunner aRoadRunner;
Coyote aCoyote;
String selectionInfo;
public WOComponent MyAction() {
WOComponent nextPage;
NSDictionary selectedCriteria;
NSDictionary itemsPerName;
Object selection;
selectedCriteria = new NSDictionary(
NSArray.componentsSeparatedByString(selectionInfo, "|"),
new NSArray(new String[] { "classArray", "name" })
);
itemsPerName = new NSDictionary(
(NSArray) this.valueForKeyPath( (String)
selectedCriteria.valueForKey("classArray") + ".name" ),
(NSArray) this.valueForKey( (String)
selectedCriteria.valueForKey("classArray") )
);
selection = itemsPerName.valueForKey( (String)
selectedCriteria.valueForKey("name") );
// now you've got the selection
// do something with it
if (selection instanceof RoadRunner) {
<..>
}
return nextPage;
}
__Component.wod__
CoyotePopUp: WOPopUpButton {
list = coyotes;
noSelectionString = "-- select coyote --";
displayString = aCoyote.name;
item = aCoyote;
onChange =
"javascript:'coyotes|'+document.myform.info.value=this.options
[this.selectedIndex].value; document.myform.submit();";
}
MyForm: WOForm {
id = "myform";
name = "myform";
action = <..>
}
MyInfo: WOHiddenField {
value = selectionInfo;
name = "info";
id = "info";
}
RoadRunnerPopUp: WOPopUpButton {
list = roadRunners;
noSelectionString = "-- select road-runner --";
displayString = aRoadRunner.name;
item = aRoadRunner;
onChange =
"javascript:'roadRunners|'+document.myform.info.value=this.options
[this.selectedIndex].value; document.myform.submit();";
}
==Strategy #2 (Using separate forms per pop-up)==
public interface PopUpItem { public String name(); }
public class RoadRunner implements PopUpItem {...}
public class Coyote implements PopUpItem {...}
__Component.java__
NSArray roadRunners;
NSArray coyotes;
PopUpItem aPopUpItem;
PopUpItem selectedItem;
CoyotePopUp: WOPopUpButton {
list = coyotes;
selection = selectedItem;
noSelectionString = "-- select coyote --";
displayString = aPopUpItem.name;
item = aPopUpItem;
onChange = "javascript:this.form.submit();";
}
RoadRunnerPopUp: WOPopUpButton {
list = roadRunners;
selection = selectedItem;
noSelectionString = "-- select road-runner --";
displayString = aPopUpItem.name;
item = aPopUpItem;
onChange = "javascript:this.form.submit();";
}
[etc]
with regards,
--
LD
_______________________________________________
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