you need to make your models pull, no need for all this fancy event
listenting
class mypage extends webpage {
private boolean green=false;
public mypage() {
add(new link("gogreen") { onclick() { green=true; }});
add(new panel("p1").add(new attributemodifier("class",true,new
greenmodel()));
add(new panel("p2").add(new attributemodifier("class",true,new
greenmodel()));
...
}
private class greenmodel extends abstractreadonlymodel {
object getobject() { return (green)?"green":""; }
}
-igor
On 10/12/07, Per Newgro <[EMAIL PROTECTED]> wrote:
>
> Hi *,
>
> i would like to implement a testing issue for me. I add three panels with
> a link on every panel. If i click one panel-link all panels should become
> green. But i dont get that to work. The model in the AttributeModifier cant
> be refreshed. What am i missing here?
>
> Thank you for helping me understanding this great framework.
> Per
>
> <code>
> package de.yhd.buma.refreshtests;
>
> import java.io.Serializable;
> import java.util.ArrayList;
> import java.util.List;
>
> import org.apache.wicket.markup.html.panel.Panel;
> import org.apache.wicket.model.IModel;
> import org.apache.wicket.model.Model;
>
> public abstract class BasePanel extends Panel {
>
> private List<IChangeListener> listeners = new
> ArrayList<IChangeListener>();
>
> /**
> *
> * Constructor of BasePanel
> * @param pId
> */
> public BasePanel(String pId) {
> super(pId);
> }
>
> /**
> *
> * Constructor of BasePanel
> * @param pId
> * @param pModel
> */
> public BasePanel(String pId, IModel pModel) {
> super(pId, pModel);
> }
>
> /**
> * adds a changeListener to a panel
> * @param pListener the listener of the panel
> */
> public void addChangeListener(IChangeListener pListener) {
> listeners.add(pListener);
> }
>
> /**
> * removes a changeListener from a panel
> * @param pListener the listener of the panel
> */
> public void removeChangeListener(IChangeListener pListener) {
> listeners.remove(pListener);
> }
>
> /**
> * initialize the panel.
> * @param pModel the model part of triad
> */
> public abstract void initialize(Object pModel);
>
> /**
> * Refresh the data model.
> * The model assigned to panel can be set thru this method.
> * It´s the partner to the model assigned in initialize.
> * The components displayed in panel will not initialized again.
> * This has been implemented because [EMAIL PROTECTED]
> #setModelObject(Object)}
> * is final.
> * @param pModel the model part of triad
> */
> public void refreshModelObject(Serializable pModel) {
> modelChanging();
> setModel(new Model(pModel));
> modelChanged();
> }
>
> /**
> * Informs listeners of model content change event
> */
> protected void fireContentChanged() {
> fireContentChanged(null);
> }
>
> /**
> * Informs listeners of model content change event
> * @param pParameter parameter that have changed
> */
> protected void fireContentChanged(Object pParameter) {
> for (IChangeListener element : listeners) {
> element.contentChanged(pParameter);
> }
> }
> }
>
> ##########################################
>
> package de.yhd.buma.refreshtests;
>
> import java.io.Serializable;
>
>
> public interface IChangeListener extends Serializable {
>
>
> /**
> * Method informs a listener if the content changed
> * @param pParam
> */
> void contentChanged(Object pParam);
>
> }
>
> ##############################
>
> package de.yhd.buma.refreshtests;
>
> import java.io.Serializable;
>
> public class RefreshLinkModel implements Serializable {
>
> private static final long serialVersionUID = 1L;
> private Boolean _highlite = false;
>
> public void toggleHighlite() {
> _highlite = !_highlite;
> }
>
> public Boolean getHighlite() {
> return _highlite;
> }
>
> public void setHighlite(Boolean pHighlite) {
> _highlite = pHighlite;
> }
>
> }
>
> ################################
>
> package de.yhd.buma.refreshtests;
>
> import java.io.Serializable;
>
> import org.apache.wicket.AttributeModifier;
> import org.apache.wicket.ajax.AjaxRequestTarget;
> import org.apache.wicket.ajax.markup.html.AjaxLink;
> import org.apache.wicket.model.Model;
>
>
> public class RefreshLinkPanel extends BasePanel {
>
> private static final long serialVersionUID = -4422790485992136492L;
>
> /**
> * Constructor of RefreshLinkPanel
> */
> public RefreshLinkPanel(String pId) {
> super(pId);
> }
>
> /**
> *
> * @see refreshtests.BasePanel#initialize(java.lang.Object)
> */
> @Override
> public void initialize(Object pModel) {
> RefreshLinkModel model = (RefreshLinkModel) pModel;
> refreshModelObject(model);
>
> add(new AttributeModifier("style", true, new
> MyStyleModifierModel(model)));
>
> AjaxLink link = new AjaxLink("link") {
> private static final long serialVersionUID = 2337879573169864643L;
>
> public void onClick(AjaxRequestTarget target) {
> RefreshLinkModel m = (RefreshLinkModel)
> getParent().getModelObject();
> m.toggleHighlite();
> target.addComponent(this);
> fireContentChanged();
> }
> };
> add(link);
> }
>
> class MyStyleModifierModel extends Model {
> private static final long serialVersionUID = 1L;
>
> /**
> * Constructor of RefreshLinkPanel.MyStyleModifierModel
> */
> public MyStyleModifierModel(Serializable m) {
> super(m);
> }
>
> /**
> * @see org.apache.wicket.model.Model#getObject()
> */
> public Object getObject() {
> RefreshLinkModel m = (RefreshLinkModel) super.getObject();
> if (m.getHighlite()) {
> return "background:yellow;";
> }
> return "background:green;";
> }
> }
> }
>
> ############################################
>
> package de.yhd.buma.refreshtests;
>
> public class RefreshPanel extends BasePanel {
>
> private static final long serialVersionUID = 1L;
>
> /**
> * Constructor of RefreshPanel
> */
> public RefreshPanel(String id) {
> super(id);
> }
>
> /**
> * @see refreshtests.BasePanel#initialize(java.lang.Object)
> */
> @Override
> public void initialize(Object pModel) {
> RefreshLinkPanel one = new RefreshLinkPanel("one");
> RefreshLinkPanel two = new RefreshLinkPanel("two");
> RefreshLinkPanel three = new RefreshLinkPanel("three");
>
> IChangeListener l = new MyChangeListener();
>
> one.addChangeListener(l);
> two.addChangeListener(l);
> three.addChangeListener(l);
>
> one.initialize(new RefreshLinkModel());
> two.initialize(createHighlited());
> three.initialize(new RefreshLinkModel());
>
> add(one);
> add(two);
> add(three);
> }
>
> private RefreshLinkModel createHighlited() {
> RefreshLinkModel modelOne = new RefreshLinkModel();
> modelOne.toggleHighlite();
> return modelOne;
> }
>
> class MyChangeListener implements IChangeListener {
> private static final long serialVersionUID = 1L;
>
> /**
> *
> * @see refreshtests.IChangeListener#contentChanged(java.lang.Object)
> */
> public void contentChanged(Object pParam) {
> RefreshLinkPanel p1 = (RefreshLinkPanel) get("one");
> p1.refreshModelObject(createHighlited());
> RefreshLinkPanel p2 = (RefreshLinkPanel) get("two");
> p2.refreshModelObject(createHighlited());
> RefreshLinkPanel p3 = (RefreshLinkPanel) get("three");
> p3.refreshModelObject(createHighlited());
> }
> }
> }
>
> </code>
> --
> Psssst! Schon vom neuen GMX MultiMessenger gehört?
> Der kanns mit allen: http://www.gmx.net/de/go/multimessenger
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>