Question

I have a grid and I need to add just before and just after it 2 links. They are the same, they just need to be visible both above and below the grid. I put them in a ToolStrip and add the ToolStrip as a member of a VLayout twice. The thing is that the ToolStrip is added twice, but the couple of links is seen only below (or is added to only the second ToolStrip). What did I do wrong? Here is the code:

 import com.google.gwt.core.client.GWT;
 import com.smartgwt.client.types.Alignment;
 import com.smartgwt.client.types.VerticalAlignment;
 import com.smartgwt.client.widgets.form.DynamicForm;
 import com.smartgwt.client.widgets.form.fields.LinkItem;
 import com.smartgwt.client.widgets.form.fields.StaticTextItem;
 import com.smartgwt.client.widgets.grid.ListGrid;
 import com.smartgwt.client.widgets.layout.VLayout;
 import com.smartgwt.client.widgets.toolbar.ToolStrip;
 import com.smartgwt.client.widgets.toolbar.ToolStripButton;

 final VLayout container = new VLayout(10);
    container.setAlign(VerticalAlignment.CENTER);

    final DynamicForm someForm1 = new DynamicForm();
    // some form with text

    final DynamicForm someForm2 = new DynamicForm();
    // some other form with text

    final VLayout grid = new VLayout(0);
    grid.setWidth100();

    final DynamicForm linksForm = new DynamicForm();
    linksForm.setWidth100();
    linksForm.setHeight(20);
    linksForm.setNumCols(2);

    final LinkItem linkOne = new LinkItem();
    linkOne.setShowTitle(false);
    linkOne.setValue("Click1");
    linkOne.setTextAlign(Alignment.RIGHT);

    final LinkItem linkTwo = new LinkItem();
    linkTwo.setShowTitle(false);
    linkTwo.setValue("Click2");
    linkTwo.setTextAlign(Alignment.RIGHT);

    linksForm.setFields(linkOne, linkTwo);

    final ToolStrip linksToolStrip = new ToolStrip();
    linksToolStrip.setWidth100();
    linksToolStrip.setAlign(VerticalAlignment.CENTER);
    linksToolStrip.addMember(linksForm);

    final ListGrid results = new ListGrid();
    // height, width, dataSource for ListGrid results, etc.

    grid.addMember(linksToolStrip, 0);
    grid.addMember(results, 1);
    grid.addMember(linksToolStrip, 2);

    container.setMembers(someForm1, grid, someForm2);

Thank you very much in advance.

Was it helpful?

Solution

You can't add a widget twice, when you add a member as you do the grid get a reference to your link and its position in the member's list so the first time its position is 0 and is changed to 2 the second time. You need two instances of your link. You can have a look also here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top