PDA

View Full Version : help in ComponentManager.get().get("element-id").....



suresh.sivanantham
1 Sep 2009, 9:57 AM
below is my code......


public class Sample_gxt implements EntryPoint {
@Override
public void onModuleLoad() {

ContentPanel c1 = new ContentPanel();
c1.setHeight(200);
c1.setHeading("con 1");
c1.add(new ModelPortal(2));

ContentPanel c2 = new ContentPanel();
c2.setHeight(200);
c2.setHeading("con 2");
c2.add(new ToolBarModel());

RootPanel.get().add(c1);
RootPanel.get().add(c2);
}

class ToolBarModel extends ToolBar {

ModelPortal m = (ModelPortal) ComponentManager.get().get(
"model-design-portal");

Button btnOpenModel = new Button("Add portlet con 1",
new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
System.out.println("Event OK");
m.add(new Portlet(), 1);
}
});
Button btnPublish = new Button("Publish");

public ToolBarModel() {
setStyleAttribute("margin", "2");
setMinButtonWidth(25);
setSpacing(10);
add(btnOpenModel);
add(new SeparatorToolItem());
add(btnPublish);
}
}

class ModelPortal extends Portal {

public ModelPortal(int numColumns) {
super(numColumns);
setId("model-design-portal");
setBorders(true);
setColumnWidth(0, .5);
setColumnWidth(1, .5);
setSpacing(25);
setLayoutOnChange(true);
add(new Portlet(), 0);
}

}

}when user clicks "Add portlet to con 1" button i am accessing the ModelPortal using ComponentManager.get().get("portlet_id")... and trying to add a new portlet...
But ComponentManager.get().get("portlet_id") returns null....

is there any other way to access ModelPortal widget using id...

i need to add a portlet whenever user clicks "Add portlet to con 1" button.....
tell me if anything is wrong with my code.... 8-|:-/:-/:-/

Arno.Nyhm
2 Sep 2009, 3:01 AM
try to place the line with the component manager into the button listener.
my guess that the element is not rendered when the constructor of ToolBarModel is called

Arno.Nyhm
2 Sep 2009, 3:03 AM
NOTE: i did not try this on my computer.



// (re)moved
// ModelPortal m = (ModelPortal) ComponentManager.get().get(
"model-design-portal");

Button btnOpenModel = new Button("Add portlet con 1",
new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
System.out.println("Event OK");
// moved to here
ModelPortal m = (ModelPortal) ComponentManager.get().get(
"model-design-portal");

m.add(new Portlet(), 1);
}
});

suresh.sivanantham
2 Sep 2009, 4:19 AM
=D>=D>

thanx Arno... it worked......

so only after the component is rendered, we can access the component through component manager..... this was given in docs.... but i didnt noticed.........

sbarakat
6 Nov 2009, 1:11 AM
Hi All,
I am trying to find a content panel component using the ComponentManager but the problem is if the content panel is collapsed the system cant find it. I need to expand it again in order to be found.

Is there any solution or a workaround regarding this issue?