Skip to content

Commit

Permalink
changed setModel to delegate to ListboxModelDynamicMethods
Browse files Browse the repository at this point in the history
  • Loading branch information
chanwit committed May 30, 2009
1 parent df00bed commit c0a2161
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 11 deletions.
9 changes: 2 additions & 7 deletions ZkGrailsPlugin.groovy
Expand Up @@ -154,13 +154,8 @@ support to Grails applications.
}
}

org.zkoss.zul.Listbox.metaClass.setModel = { java.util.List list ->
if(delegate.getModel()!=null) {
delegate.getModel().clear()
delegate.getModel().addAll(list)
} else {
delegate.setModel(new BindingListModelList(list, false))
}
org.zkoss.zul.Listbox.metaClass.setModel = { java.util.List list ->
ListboxModelDynamicMethods.setModel(delegate, list)
}

org.zkoss.zul.Listbox.metaClass.getModel = { ->
Expand Down
Binary file modified grails-zk-0.7.2.zip
Binary file not shown.
49 changes: 45 additions & 4 deletions src/java/org/zkoss/zkgrails/ListboxModelDynamicMethods.java
@@ -1,9 +1,50 @@
/* ListboxModelDynamicMethods.java
Copyright (C) 2009 Chanwit Kaewkasi
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

package org.zkoss.zkgrails;

import org.zkoss.zkgrails.*;
import org.zkoss.zkplus.databind.BindingListModelList;
import org.zkoss.zul.Listbox;

public class ListboxModelDynamicMethods {

ListboxModelDynamicMethods (arguments) {
// expression

public static void setModel(Listbox delegate, Object list) {
if(list instanceof java.util.List) {
Object model = delegate.getModel();
if(model != null) {
if(model instanceof BindingListModelList) {
BindingListModelList blml = (BindingListModelList)model;
blml.clear();
blml.addAll((java.util.List)list);
return;
}
} else {
delegate.setModel(new BindingListModelList((java.util.List)list, false));
return;
}
}

if (list instanceof org.zkoss.zul.GroupsModel) {
delegate.setModel((org.zkoss.zul.GroupsModel)list);
} else {
delegate.setModel((org.zkoss.zul.ListModel)list);
}
}

}

0 comments on commit c0a2161

Please sign in to comment.