I have an issue with the CompositeCell in a CellTable. My
CompositeCell consists of 3 ActionCells and a SelectionCell.
However the difference to a normal behaviour of a CompositeCell is
that I don't show all Cells at the same time but based on some state
in a domain object. Here is what I try to achieve:
Initial State
Second Stage After pressing on Save/Cancel
| NEW | -> (press on NEW ActionCell) -> | SELECTION SAVE CANCEL |
-> | NEW |
So after pressing on the NEW ActionCell it should be hidden and the
SelectionCell and the SAVE/CANCEL ActionCells should be shown. After I
press on SAVE or CANCEL again only the NEW ActionCell should be shown.
For the ActionCells i just override the render method of the Cell to
either not render the cell or to render it based on the state in my
domain object.
This looks like this:
public static class NewActioncell extends ActionCell<MyObject> {
public NewActioncell(String
text,com.google.gwt.cell.client.ActionCell.Delegate<MyObject>
delegate) {
super(text, delegate);
}
@Override
public void render(MyObject value, Object key, SafeHtmlBuilder sb)
{
if (value.getIsNew()) // get the state
super.render(value, key, sb);
}
}
The code for the Save and Cencel Action Cells is basically the same
apart from the fact that in the render method i will render the cells
if value.getIsNew() == false
The delegate action just sets the IsNew flag on the MyObject and calls
refresh on the DataProvider.
So far everything works as expected. As soon as I press on the NEW
Button, the NEW Button is hidden and only the CANCEL and SAVE buttons
are shown.
Now I also want to display a Select Box when SAVE and CANCEL are
shown. The Problem with the SelectionCell is that it is bound to
String as the Generic Type, so I can't access MyObject in its render
method.
My workaround is now to override the <X> void render method of the
CompositeCell and hide the SelectionCell there. This looks something
like that:
public static class CustomCompositeCell extends
CompositeCell<MyObject> {
public CustomCompositeCell(List<HasCell<MyObject, ?>> hasCells) {
super(hasCells);
}
@Override
protected <X> void render(MyObject value, Object
key,SafeHtmlBuilder sb, HasCell<MyObject, X> hasCell) {
if (!(hasCell.getCell() instanceof SelectionCell) ||
(value.getIsNew())) // check Cell and State
{
super.render(value, key, sb, hasCell);
}
}
}
So now the SelectionCell is displayed as soon as I press on the NEW
Button. However I get an exception in hosted and in production mode as
soon as I press on cancel or save.
The error is:
Chrome: com.google.gwt.core.client.JavaScriptException: (TypeError):
Cannot read property 'nextSibling' of null
Firefox: elem is null [Break on this error] var sib =
elem.nextSibling;
I managed to trace the problem back to the resetFocus method of the
CompositeCell class:
@Override
public boolean resetFocus(Element parent, C value, Object key) {
Element curChild =
getContainerElement(parent).getFirstChildElement();
for (HasCell<C, ?> hasCell : hasCells) {
// The first child that takes focus wins. Only one child should
ever be in
// edit mode, so this is safe.
if (resetFocusImpl(curChild, value, key, hasCell)) {
return true;
}
curChild = curChild.getNextSiblingElement();
}
return false;
}
It seems that the loop goes through all 4 Cells but one call of
getNextSiblingElement() returns null. The interesting part is that the
exception only happens when I add the selectionCell to CompositeCell.
It seems that not rendering an ActionCell by overriding its render
method doesn't cause a problem. However overriding the render method
of the CompositeCell to not render the SelectionCell causes this
Exception in the resetFocus method.
Is this a potential bug or is my approach of hiding Cells in a
CompositeCell flawed. Maybe there is a better approach.
Thanks in advance
Uemit
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.