Export to GitHub

google-web-toolkit - issue #6144

Cannot have multiple CellTables with different custom resources


Posted on Mar 14, 2011 by Helpful Panda

Found in GWT Release: GWT 2.2.0

Encountered on OS / Browser: Windows XP Pro SP3/ All browsers.

Detailed description (please be as specific as possible): If I use in my application two CellTables with each CellTable using different custom resources, these resources (at least the generated CSS) get mixed. For example if I want a table with red cell borders and one with blue cell borders it is not possible. Both cell table will have cell borders of the same color.

Shortest code snippet which demonstrates issue:

public class Test1 implements EntryPoint {

private static class Contact { private final String name;

public Contact(String name) {
  this.name = name;
}

}

private static List<Contact> CONTACTS = Arrays.asList(new Contact("John"), new Contact("Mary"), new Contact("Zander"));

public interface CellTableResources extends CellTable.Resources { @Source("CellTable.css") Style cellTableStyle(); }

public interface CellTableResources2 extends CellTable.Resources { @Source("CellTable2.css") Style cellTableStyle(); }

public void onModuleLoad() {

CellTableResources resources = GWT.create(CellTableResources.class);
CellTableResources2 resources2 = GWT.create(CellTableResources2.class);

CellTable&lt;Contact&gt; table = new CellTable&lt;Contact&gt;(Integer.MAX_VALUE, resources);
CellTable&lt;Contact&gt; table2 = new CellTable&lt;Contact&gt;(Integer.MAX_VALUE, resources2);

ListDataProvider&lt;Contact&gt; dataProvider = new ListDataProvider&lt;Contact&gt;();

dataProvider.addDataDisplay(table);
dataProvider.addDataDisplay(table2);

  TextColumn&lt;Contact&gt; nameColumn = new TextColumn&lt;Contact&gt;() {
    @Override
    public String getValue(Contact object) {
      return object.name;
    }
  };
  table.addColumn(nameColumn, &quot;Name&quot;);
  table2.addColumn(nameColumn, &quot;Name&quot;);


List&lt;Contact&gt; list = dataProvider.getList();
for (Contact contact : CONTACTS) {
  list.add(contact);
}

RootPanel.get(&quot;main&quot;).add(table);
RootPanel.get(&quot;main&quot;).add(table2);

} }

CellTable.css is a copy of the default CellTable.css where I've just modified .cellTableCell by this to have a blue border: .cellTableCell { border: 1px solid blue !important; }

CellTable2.css is a copy of the default CellTable.css where I've just modified .cellTableCell by this to have a red border: .cellTableCell { border: 1px solid red!important; }

Workaround if you have one: None found.

Attachments

Comment #1

Posted on Mar 14, 2011 by Helpful Panda

Note : If I look in Firebug at the generated CSS applied to a cells I can see that I have the same class defined twice.

.GALD-WOHC { border: 1px solid blue !important; }

.GALD-WOHC { border: 1px solid red !important; }

Comment #2

Posted on Mar 14, 2011 by Helpful Panda

Maybe with an attached screenshot it's clearer.

Attachments

Comment #3

Posted on Mar 14, 2011 by Swift Rhino

The CSS className is computed (Adler32 checksum) based on the interface name (before the dash) and method name (after the dash). That's why you have the same class name twice, and this is how GWT can implement @ImportedWithPrefix/@Import and @Shared features on CssResource-s.

You have to extend the Style interface in each extended Resources interface so the computed class names are different.

I discovered this by reading the code though (in CssResourceGenerator); documentation should definitely be improved!

Comment #4

Posted on Mar 26, 2011 by Grumpy Horse

I'm having this issue - I have a bunch of celltables, and in one instance i definitely need a variant on the css, that results in some sort of collision (eg whatever is the latest version, affects the other cell tables.

could you elaborate on "extend the Style interface" or point me to the docs where I probably should already have looked?

Comment #5

Posted on Mar 27, 2011 by Helpful Panda

It seems you just have to do something like this :

interface TableResources extends CellTable.Resources { @Source({"myCellTable.css"}) TableStyle cellTableStyle();

}

interface TableStyle extends CellTable.Style {}

Comment #6

Posted on Jan 19, 2012 by Swift Rhino

(No comment was entered for this change.)

Comment #7

Posted on Feb 9, 2012 by Grumpy Elephant

Comment deleted

Comment #8

Posted on Feb 27, 2012 by Quick Camel

I am not even able to us the same table resource in two tables. Though one is inheriting the custom CSS defined by me, second Cell Table takes the default CSS. public interface TableRes extends CellTable.Resources {

@Source({CellTable.Style.DEFAULT_CSS,"mycustomtable.css"}) CellTableStyle cellTableStyle();

public interface CellTableStyle extends CellTable.Style {};

}

And this is how I consumed the resource defined above

CellTable myTable1 = new CellTable(Integer.MAX_VALUE, ViewUtil.getPracTableCssRes());

CellTable myTable2 = new CellTable(Integer.MAX_VALUE, ViewUtil.getPracTableCssRes());

though myTable1 takes the style defined in custom css, myTable2 takes default css

Comment #9

Posted on Apr 13, 2012 by Quick Horse

What classname has your tables? Try to remove default css, but custom css must contain all default css-classname.

public interface TableRes extends CellTable.Resources {

@Source({"mycustomtable.css"}) CellTableStyle cellTableStyle();

public interface CellTableStyle extends CellTable.Style {};

}

Comment #10

Posted on Apr 30, 2012 by Swift Rhino

@kohli.Vikram1982: if you still have a problem, let's discuss it in the Google Group (but first try to "debug" it using your browser's developer tools examining the CSS being applied and where it comes from)

Comment #11

Posted on Jan 10, 2013 by Grumpy Rhino

Hi Thomas, I tried your solution but it seems that it does not work for me. I have two screens containing a celltable that are declared like this: first screen:

public interface ECCellTableRes extends CellTable.Resources
{
@Source("ECCellTableWidget.css")
ECCellTableStyle cellTableStyle();

public interface ECCellTableStyle extends CellTable.Style
{
}
}

second screen: public interface TooltipTableRes extends CellTable.Resources { /** * Get the style */ @Source("TooltipTable.css") TooltipStyle cellTableStyle();

public interface TooltipStyle extends CellTable.Style
{
}
}

if i go in the first screen first, css is correct, but if i go on the second screen and i come back on the first one, i have the css of the second screen applied. Any idea?

Comment #12

Posted on Sep 24, 2013 by Swift Rhino

Issue 8358 has been merged into this issue.

Comment #13

Posted on Nov 4, 2013 by Happy Horse

Hi there,

I've managed to get it working. As t.broyer wrote I've changed the interface name.

Before:

public interface NxoCellTableResources extends CellTable.Resources {
    @Source({ CellTable.Style.DEFAULT_CSS, "NxoCellTable.css" })
    public CellTable.Style cellTableStyle();
}

public interface NxoCellTableThinResources extends CellTable.Resources {
    @Source({ CellTable.Style.DEFAULT_CSS, "NxoCellTable.css", "NxoCellTableThin.css" })
    public CellTable.Style cellTableStyle();
}

After:

public interface NxoCellTableResources extends CellTable.Resources {
    public interface NormalStyle extends CellTable.Style {}

    @Source({ CellTable.Style.DEFAULT_CSS, "NxoCellTable.css" })
    public NormalStyle cellTableStyle();
}

public interface NxoCellTableThinResources extends CellTable.Resources {
    public interface ThinStyle extends CellTable.Style {}

    @Source({ CellTable.Style.DEFAULT_CSS, "NxoCellTable.css", "NxoCellTableThin.css" })
    public ThinStyle cellTableStyle();
}

So, I've added two new inner interfaces. And now it's ok.

In your case I would say it should be like this:

public interface CellTableResources2 extends CellTable.Resources { public interface Style2 extends Style {}

@Source("CellTable2.css")
Style2 cellTableStyle();

}

The first one can stay unchanged.

Comment #14

Posted on Oct 23, 2014 by Swift Camel

Many thanks to t.broyer and consros for a solution. I was having this same issue with DataGrid styles.

Status: AsDesigned

Labels:
Category-Documentation