A better way than D2W - Children elements communication
A better way than D2W - Children elements communication
- Subject: A better way than D2W - Children elements communication
- From: DevReseune <email@hidden>
- Date: Wed, 23 Apr 2003 00:12:33 +0200
Hi,
I want to create a component that dispatch its contained elements in
many areas in the component, and not in the same one. For example,
imagine the next model / structure of components:
Main.wo
<MyComponentContainer>
<AComponentElement>A data </AComponentElement>
<AComponentElement>Another data</AComponentElement>
</MyComponentContainer>
For each <AComponentElement>, I want to call a method in
MyComponentContainer, for example addData(String data) where data is
the content of the element.
When MyComponentContainer appendToResponse, I want to write this;
MyComponentContainer.wo
<WOString value=elements.count />
<WOREPEAT list=elements item=elementToRepeat>
<WOString value=elementToRepeat />
</WOREPEAT>
or
<IF value=elements.count>
show elements
</IF>
<IFNOT value=elements.count>
No element
</IF>
I know how to do that:
MyComponentContainer.java
public void appendToResponse(WOResponse response, WOContext context) {
WOComponent wocomponent = context.component();
WOElement woelement = wocomponent._childTemplate();
if (woelement != null && woelement != WODynamicGroup.EmptyGroup()) {
woelement.appendToResponse(response, context);
}
super.appendToResponse(response, context);
}
MyComponentElement.java
public void appendToResponse(WOResponse response, WOContext context) {
WOResponse innerResponse = new WOResponse();
super.appendToResponse(innerResponse, context);
WOComponent parent = parent();
if (parent != null && parent instanceof MyComponentContainer) {
String element = new String(innerResponse.content().bytes());
((TestInvertInnerElementsContainer) parent).addElement(element);
}
}
But, perhaps you know a better way The problem is the container has no
WOContentComponent in the API file, but children have to create their
response (during appendToResponse) and call the method in their parent.
It was very interansting to create more reuse components. So, you can
create a FormContainer, and FormInput that were element of a special
graphic form. So you can use to create your real form:
<FormContainer>
<FormInput name="ID" value="dataToEdit.id"/>
<FormInput name="name" value="dataToEdit.name"/>
<FormInput name="password" value="dataToEdit.password"/>
I think is a better solution than DirectToWeb. Why? Because you can't
create a global model for all components with only few elements. You
have to add code in many cases, to test a special condition, to get an
array of elements, etc Your look and feel can be in FormContainer or
FormInput, but, you can create a special component like that:
<FormContainer>
<FormInput name="ID" value="dataToEdit.id"/>
<IF value=condition1>
<FormInput name="name" value="dataToEdit.name"/>
<IFNOT value=condition1>
<FormInput name="firstName" value="dataToEdit.firstName"/>
<FormInput name="lastName" value="dataToEdit.lastName"/>
<FormInput name="password" value="dataToEdit.password"/>
<FormSelectInput name="your choice" value="dataToEdit.group">
<REPEAT list=allGroups item=groupToRepeat>
<FormSelectInput_Item name= groupToRepeat.name value= groupToRepeat/>
</REPEAT>
</FormSelectInput>
And in your java file, you create the method condition() and the
properties allGroups and groupToRepeat. It's very simple, it's fast,
it's powerfull and not limited by a simple model as DirectToWeb.
Thanks
RFred999
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.