Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Cast Element to Widget

Remy Travis
6 years ago Jul 15, 2015 9:57am

Hi guys I'm really stuck on that problem.... Please look at the basic class below and the comments

public class PlanningWidget extends Composite {

   private @UiField FooterPlanningLine footerPlanningLine;
   private @UiField FooterLeft footerLeft;

  public void paintBackground() {


public abstract class Composite extends Widget implements IsRenderable { ... }

public class FooterPlanningLine extends Composite {

   public void paintBackground() {
       //I want to call this method regardless from FooterLeft or PlanningWidget...


public class FooterLeft extends Composite {

   private Canvas canvas;


     canvas.addClickHandler(new ClickHandler() {          
            public void onClick(ClickEvent event) {
                // HERE I'D LIKE TO CALL THE  FooterPlanningLine/PlanningWidget paintBackground() METHOD

These class are client-sided. I have tried to do :
    NodeList<Element> nodeList = Document.get().getElementsByTagName("footerPanel");  
    // the line above gets the element of type FooterPlanningLine from the DOM

    Element footerLp = nodeList.getItem(0); //The Element that I have to convert to Widget
    Widget myWidget = new Widget(); 

       // I WAS SUPPOSED TO DO THE THING BELOW BUT setElement is DEPRECATED ! Can't use it anymore
      ((FooterPlanningLine) w).paintBackground();

 /*  How can I call the FooterPlanningLine paintBackground() method OR PlanningWidget paintBackground() method from the FooterLeft click listener ???  I'm really stuck .. Thank you for help. */



Anna Koskinen
6 years ago Jul 16, 2015 10:12am


That Anchor.wrap(footerLP) that you call there should already return to you an Anchor widget, was that a failed experiment that you just haven't removed yet? I'm not exactly sure which one of your classes has that footerPanel element, but perhaps you could add a similar wrapper method to that class as well? Or your PlanningWidget instance could just give itself as a reference to that footerLeft instance.

Remy Travis
6 years ago Jul 20, 2015 4:36am