-
25 Dec 2008 7:26 PM #1
How to clone a Field?
How to clone a Field?
Hi,
I have a method with parameter abstract Field , i need to clone a new one and return it.
just like:
public Field cloneField(Field input)
{
return GWT.create(input.getClass());
}
It works fine in hostmode,but compile error in ant building with message:
"Only class literals may be used as arguments to GWT.create()".
Is that means abstract class or interface can't use in create method?
Thanks.
-
29 Dec 2008 2:40 PM #2
No, it requires... Field.class - but in saying that, as its abstract there is not really a way to use it.. you should be creating sub classes of Field.
Why do you want to clone the field? Perhaps there is another simpler solution.GXT JavaDocs: http://extjs.com/deploy/gxtdocs/
GXT FAQ & Wiki: http://extjs.com/learn/Learn_About_the_Ext_GWT_Library
Buy the Book on GXT: http://www.apress.com/book/view/9781430219408
Follow me on Twitter: http://twitter.com/gslender
-
29 Dec 2008 6:13 PM #3
Actually, i want to build a MultiField's subclass which can add a Field repeatly just like add attachments in email, and the field doesn't need to know what exactly it is and can be added repeatly.

Thanks.
-
29 Dec 2008 8:42 PM #4
...still can't say I fully understand what you are doing - if you provide a small example/test case then I'd be happy to help you figure out another way to do what you need.
GXT JavaDocs: http://extjs.com/deploy/gxtdocs/
GXT FAQ & Wiki: http://extjs.com/learn/Learn_About_the_Ext_GWT_Library
Buy the Book on GXT: http://www.apress.com/book/view/9781430219408
Follow me on Twitter: http://twitter.com/gslender
-
29 Dec 2008 9:47 PM #5
Code:public class MyRepeatFieldGroup extends MultiField<Field> { private LayoutContainer lc = new LayoutContainer(new FormLayout()); public BTRepeatEditorFieldGroup(final Field field) { setOrientation(Orientation.VERTICAL); lc.setLayoutOnChange(true); lc.add(new MyRepeatField(cloneField(field))); final LayoutContainer lc_btn = new LayoutContainer(); final Button btn = new Button("Add"); btn.setIconStyle("bt-icon-add"); btn.addSelectionListener(new SelectionListener<ButtonEvent>(){ public void componentSelected(ButtonEvent ce) { lc.add(new BTRepeatEditorField(cloneField(field))); }}); lc_btn.add(btn); add(new AdapterField(lc)); add(new AdapterField(lc_btn)); } }In the class MyRepeatFieldGroup's cloneField method i want to clone another one,and display repeatly.Code:public class MyRepeatField extends MultiField<Field> { private Field field; public MyRepeatField(Field field) { this.field = field; setHideLabel(true); field.setHideLabel(true); setOrientation(Orientation.HORIZONTAL); add(field); LabelField label = new LabelField(" "); label.setHideLabel(true); add(label); final Button btn = new Button("Delete"); btn.setIconStyle("bt-icon-cancel"); btn.addSelectionListener(new SelectionListener<ButtonEvent>(){ public void componentSelected(ButtonEvent ce) { MyRepeatField.this.removeFromParent(); }}); add(new AdapterField(btn)); } public Object getRepeatValue() { return field.getValue(); } public void setRepeateValue(Object obj) { field.setValue(obj); } }
-
30 Dec 2008 12:30 AM #6
zhoujianghao,
Can you provide a section of code that uses the above snippet - start with onModuleLoad and go from there... I'm happy to help, but you need to provide complete code examples that clearly show the problem you are having.
Also, can you provide some background on what you are trying to do - what is the goal behind trying to create new fields where you don't know what kind of field it is ??GXT JavaDocs: http://extjs.com/deploy/gxtdocs/
GXT FAQ & Wiki: http://extjs.com/learn/Learn_About_the_Ext_GWT_Library
Buy the Book on GXT: http://www.apress.com/book/view/9781430219408
Follow me on Twitter: http://twitter.com/gslender
-
11 Jul 2012 2:12 AM #7
Cloning a field in editors
Cloning a field in editors
In Editor Grid, when the columns rendered for the first time, everything works fine. But when the new columns gets added when another entity value changes on the UI, I needed to rebuild the whole column model which will re-create the column editors as well.
But when I'm creating the column's underlying field only once... when it has got rendered for the first time, having the rendered flag as TRUE, the same will not get rendered for the subsequent store refreshes.
So no editors are being seen on the UI from the second refresh of the grid onwards. So, the solution I found myself is to create a new clone of existing field so that the same will be considered for re-rendering when the editor gets rendered.
It would be great if I can do the generic clone of a field with all the listeners attached to it.Thanks,
nanich


Reply With Quote