[Wicket-user] composite component

2006-05-10 Thread Ittay Dror

after troubling many people here, and thankful for their help, here is the 
CompositeComponent component.

you just overwrite two methods, and voila!

hope it is useful for someone else.

it is part of the product i'm working on, so it's MPL licensed. 


public abstract class CompositeComponent extends FormComponent{


public CompositeComponent(String id) {
this(id, null);
}

public CompositeComponent(String id, IModel model) {
// XXX: can make it in omModelChanged, but then i have to do 
some ugly checks
super(id);
setModel(new PartialModel(model));
}

abstract protected String[] getCompositeInput(ListString[] list);

abstract protected Object getPartialObject(Component component, Object 
modelObject);

/* (non-Javadoc)
 * @see wicket.markup.html.form.FormComponent#getInput()
 */
@Override
public String[] getInputAsArray() {
// go over all children, and create a list.
		final ListString[] list = null; 
		visitChildren(FormComponent.class, new Component.IVisitor(){


public Object component(Component component) {

list.add(((FormComponent)component).getInputAsArray());
return Component.IVisitor.CONTINUE_TRAVERSAL;
}

});
		return getCompositeInput(list); 
	}



private CompositeComponent getThis() {
return this;
}

private class PartialModel implements ICompoundModel {

private IModel selfModel;

public PartialModel(IModel model) {
selfModel = model;
}

public IModel getNestedModel() {
return null;
}

public Object getObject(Component component) {
resolveSelfModel();
return getPartialObject(component, 
selfModel.getObject(getThis()));
}

public void setObject(Component component, Object object) {
if (component == null) {
resolveSelfModel();
selfModel.setObject(getThis(), object);
}
}

private void resolveSelfModel() {
if (selfModel == null) {
selfModel = getParent().getModel();
}
}

public void detach() {
// TODO Auto-generated method stub

}

}


}


--
===
Ittay Dror 
Chief architect, openQRM TL, 
RD, Qlusters Inc.

[EMAIL PROTECTED]
+972-3-6081994 Fax: +972-3-6081841

http://www.openQRM.org
- Keeps your Data-Center Up and Running


---
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnkkid=120709bid=263057dat=121642
___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


Re: [Wicket-user] composite component

2006-05-10 Thread Johan Compagner
Yes and that is essentially only one formcomponent (youre composite) that has intenally its own markup/componentsAnd it gets the input directly from themFor example see the CheckGroup and the Check classes. Check classes aren't also FormComponents.
johan And are the children you put in that composite also again formcomponents?
 Why why aren't that just Check or Radio classes normal webcontainers Because you are now creating a hierchy in FormComponents?i didn't understand you. i use getInputAsArray(), which is defined in FormComponent. I'm trying to acheive an effect of several form components acting, for the model (set/get) as one.