Use Extensions to override Client-Widget

Hello Vaadin Community,

i just now start getting into Extensions and writing client-side code. That’s why i have this question:

Imagine i want to override a method in a Client-side Widgetset (in my case i’m testing it with the getDisplayString-method of the VFilterSelect class). I want to keep it simple and for that am trying to write an extension. I made the abstractextension and the associated Connector-class but now i have a problem:

In the Connector i am able to retrieve the Widget and put it into a variable but i don’t know how or whether i can override it.

I know that there is no setWidget method in the componentconnector otherwise i would’ve just made a class extending the VFilterSelect class and overriding the method.

Is this even possible using an Extension or do you have to create your own component extending the server-side, client-side and connector of the Vaadin Combobox to override the method?

Best Regards,
M R

You can use the GWT compiler to replace the widget class with your own by adding something like the following to the widgetset xml:[code]


[/code]This also works for connectors.

Thank you for your reply Johannes.

Ah that’s cool. I totally forgot about the replace-with tag.
If i would use that it would replace the classes for every component, right?
So if i would like to have a way to have a seperate version i would have to make my own custom component (what i’m currently even testing out and it doesn’t seem that difficult)?
So Extension should/can mainly be used to expand a component but not to make major changes inside of the client-side Widget or am i mistaken?

You could also replace the connector class and override createWidget() to return something else than the default if some condition is fulfilled. However, it’s not completely clear to me at which point createWidget() is first called - for instance, if the initial state is already available.

Extensions would be much more useful if connectors offered a few more customization points; that’s something we’ll have to think about a bit in the future.

Yes i also realized that overriding the VFilterSelect method i was aiming at may not be the smartest idea for a beginner like me. Like i said i was trying to make it by creating my own component extending the Combobox/VFilterSelect classes but when i then wanted to override the method i found out that it was buried inside of a subclass inside the VFilterSelect class which gets initialized by another subclass which gets initialized by another subclass which… i think you get the idea.
So i dropped that “mini-” project for now and start extending the FileDownloader to display files rather then downloading them while also avoiding the pop-up blocker and not using deprecated methods. At this point this is working decently well. Extending the FileDownloader wasn’t a problem at all just the actual displaying of the file isn’t as easy as i expected.

Making the ExtensionConnectors more open to customizations would really be a great idea which would make it so much easier to change something in existing components without spending a lot of time.

I really hope that you, the Vaadin devs, find the time to implement this customization-possibilities.

Hi all.
I’m going on the same way. my wedgetSet dos not compiles.
Widget set contains:

and i get compile error:

Caused by: java.lang.NoClassDefFoundError: my.test.web.ui.calendar.MyVCalendar
at com.google.gwt.dev.jjs.impl.UnifyAst.searchForTypeBySource(UnifyAst.java:981)
at com.google.gwt.dev.jjs.impl.UnifyAst.access$1500(UnifyAst.java:120)
at com.google.gwt.dev.jjs.impl.UnifyAst$UnifyVisitor.handleGwtCreate(UnifyAst.java:364)
at com.google.gwt.dev.jjs.impl.UnifyAst$UnifyVisitor.handleMagicMethodCall(UnifyAst.java:433)
at com.google.gwt.dev.jjs.impl.UnifyAst$UnifyVisitor.endVisit(UnifyAst.java:237)
at com.google.gwt.dev.jjs.ast.JMethodCall.traverse(JMethodCall.java:243)
at com.google.gwt.dev.jjs.ast.JModVisitor.traverse(JModVisitor.java:361)
at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:273)
… 34 more
[ERROR]
at ConnectorBundleLoaderImpl.java(3491): GWT.create(VCalendar.class)
com.google.gwt.dev.jjs.ast.JMethodCall
[ERROR]
at ConnectorBundleLoaderImpl.java(3491): return GWT.create(VCalendar.class)
com.google.gwt.dev.jjs.ast.JReturnStatement
[ERROR]
at ConnectorBundleLoaderImpl.java(3490): {
return GWT.create(VCalendar.class);
}
com.google.gwt.dev.jjs.ast.JBlock
[ERROR]
at ConnectorBundleLoaderImpl.java(3490): {
return GWT.create(VCalendar.class);
}
com.google.gwt.dev.jjs.ast.JMethodBody
[ERROR]
at ConnectorBundleLoaderImpl.java(3490): public Object invoke(Object target, Object params);

     com.google.gwt.dev.jjs.ast.JMethod

Widgetset compilation failed

where i must paste MyVCalendar for compiler see it, or may be i have not add additional properties?

best regards.

I think the part in the widgetset is fine but i think you made something wrong in the MyVCalendar class.
The plain class you could start from, which should act like the original one would look like this:[code]
import com.vaadin.client.ui.calendar.CalendarConnector;
public class MyVCalendar extends CalendarConnector{

public MyVCalendar(){
super();
}

}
[/code](Code is untested)
In this class you should be able to override the methods you want. Btw: Why are you trying to override the connector? You know that the Connector is mainly used for the communication between the server-side and the client-side class. I don’t have a eclipse with Vaadin 7.1.0 set up right now but i’m guessing the real client class would be called something like VCalendar.

Hello everyone.
Thank you, Marius for response.
But i still have not achieve result.

I trying override client side vaadin 7.1 calendar .
I make sow:


public class MyVCalendar extends VCalendar {

	@Override
	public void setDayNames(String[] names) {
		String[] newNames = new String[names.length]
;
		for(int i = 0 ; i< names.length; i++){
			newNames[i]
 = names[i]
+"My";
		}
		
		super.setDayNames(newNames);
    }
}

this is my WidgetSet.gwt.xml


	<replace-with class="my.test.web.ui.calendar.MyVCalendar">
		<when-type-is class="com.vaadin.client.ui.calendar.VCalendar" />
	</replace-with>

when i compile WidgetSet my changes was not seen.

Then I added MyCalendarConectore:


public class MyCalendarConector extends CalendarConnector {

	@Override
	public MyVCalendar getWidget() {
		return (MyVCalendar)super.getWidget();
	}

}

and to WidgetSet:


	<replace-with class="my.test.web.ui.calendar.MyCalendarConector">
		<when-type-is class="com.vaadin.client.ui.calendar.CalendarConnector" />
	</replace-with>

And after this my WidgetSet does not compiles:


Caused by: java.lang.NoClassDefFoundError: my.test.web.ui.calendar.MyCalendarConector
	at com.google.gwt.dev.jjs.impl.UnifyAst.searchForTypeBySource(UnifyAst.java:981)
	at com.google.gwt.dev.jjs.impl.UnifyAst.access$1500(UnifyAst.java:120)
	at com.google.gwt.dev.jjs.impl.UnifyAst$UnifyVisitor.handleGwtCreate(UnifyAst.java:364)
	at com.google.gwt.dev.jjs.impl.UnifyAst$UnifyVisitor.handleMagicMethodCall(UnifyAst.java:433)
	at com.google.gwt.dev.jjs.impl.UnifyAst$UnifyVisitor.endVisit(UnifyAst.java:237)
	at com.google.gwt.dev.jjs.ast.JMethodCall.traverse(JMethodCall.java:243)
	at com.google.gwt.dev.jjs.ast.JModVisitor.traverse(JModVisitor.java:361)
	at com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:273)
	... 34 more
      [ERROR]
 at ConnectorBundleLoaderImpl.java(3904): GWT.create(CalendarConnector.class)
         com.google.gwt.dev.jjs.ast.JMethodCall
      [ERROR]
 at ConnectorBundleLoaderImpl.java(3904): return GWT.create(CalendarConnector.class)
         com.google.gwt.dev.jjs.ast.JReturnStatement
      [ERROR]
 at ConnectorBundleLoaderImpl.java(3903): {
  return GWT.create(CalendarConnector.class);
}
         com.google.gwt.dev.jjs.ast.JBlock
      [ERROR]
 at ConnectorBundleLoaderImpl.java(3903): {
  return GWT.create(CalendarConnector.class);
}
         com.google.gwt.dev.jjs.ast.JMethodBody
      [ERROR]
 at ConnectorBundleLoaderImpl.java(3903): public Object invoke(Object target, Object[] params);

         com.google.gwt.dev.jjs.ast.JMethod
Widgetset compilation failed

I cannot understand what is wrong. what i must override all classes in vaadin 7.1 library where is used CalendarConnectore ? I know there are not too many, 30 somewhere.