Switch component for existing instances
Switch component for existing instances
- Subject: Switch component for existing instances
- From: Jarvis Cochrane <email@hidden>
- Date: Thu, 30 Jun 2005 12:33:45 +0800
Hi,
Does anyone know of a Java version of a "WOSwitchComponent" component
that can switch between existing, instantiated components, rather
than switching between named components as WOSwitchComponent does?
This question seems to have come up a few times previously in the
list archives, and while there are pointers to Webobjects Objective C
components that do this (eg OWOReplacementComponent, and a couple of
others), but none in Java that I've been able to find.
As a couple of other people seem to have done, I've gone a long way
down the track of re-implementing a custom component (subclass of
WODynamicElement) to do this. And I've now reached a point where it
*almost* works.
So - a couple of questions!
Firstly, is trying to instantiate WOComponents outside of the normal
flow of page creation (ie Instantiating subcomponents 'manually' in
the constructor of a page rather than allowing them to be
instantiated by WO as it generates the page) either a really bad
design, or likely to break something?
(What I'm trying to do is implement a menu/navigation component that
queries the subcomponents that it's switching between for their state
in order to display enabled/disabled links. Instantiating the
components 'outside' is an attempt to avoid having to create and
destroy each component 'inside' the menu component just to be able to
read its state.
I've considered creating static class methods on subcomponents to
allow their state to be queried without the overhead of instantiating
them twice. But java doesn't allow static methods in interfaces,
which is a frustration. I'm also toying with using notifications,
somehow....)
Secondly, assuming it is a reasonable design, has anyone else been
able to get it to work? Or know of a working implementation?
Thirdly, assuming the answers to the previous two questions are 'no'
and 'no'... can someone please help me work out why I'm getting
com.webobjects.foundation.NSKeyValueCoding$UnknownKeyException: [;
2.5.2.0.1 = ; } > valueForKey()]: lookup of unknown key:
'repetitionList'. This WOComponent does not have an instance
variable of the name repetitionList or _repetitionList, nor a
method of the name repetitionList, _repetitionList,
getRepetitionList, or _getRepetitionList
from this code (see below)? The exception is being thrown at the line
" r = c.invokeAction(request, context); " in "invokeAction", and I've
confirmed that the bindings are correctly set up for the subcomponent...
Thanks heaps in advance,
Jarvis
public class WOKInstanceSwitcher extends WODynamicElement {
protected WOAssociation _component;
public WOKInstanceSwitcher(String name, NSDictionary associations,
WOElement template) {
super(name, associations, template);
_component = (WOAssociation) associations.objectForKey
("selectedComponent");
if (_component==null) {
throw new IllegalArgumentException("No component
binding");
}
}
/** pass the takeValuesFromRequest phase to the subcomponent
*/
public void takeValuesFromRequest(WORequest request, WOContext
context) {
WOComponent c = (WOComponent) _component.valueInComponent
(context.component());
if (c!=null) {
context.appendZeroElementIDComponent();
c.takeValuesFromRequest(request, context);
context.deleteLastElementIDComponent();
}
}
/** handle actions by passing to the subcomponent
*/
public WOActionResults invokeAction(WORequest request,
WOContext context) {
ListAndFormController c = (ListAndFormController)
_component.valueInComponent(context.component());
WOActionResults r = null;
if (c!=null) {
context.appendZeroElementIDComponent();
r = c.invokeAction(request, context);
context.deleteLastElementIDComponent();
}
return r;
}
/** Generate content by passing request to sub-component
*/
public void appendToResponse(WOResponse response, WOContext
context) {
WOComponent c = (WOComponent) _component.valueInComponent
(context.component());
if (c!=null) {
context.appendZeroElementIDComponent();
c.appendToResponse(response, context);
context.deleteLastElementIDComponent();
}
}
}
_______________________________________________
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