Search in sources :

Example 11 with SubUIContext

use of com.github.bordertech.wcomponents.WRepeater.SubUIContext in project wcomponents by BorderTech.

the class WDataTable_Test method testTableIdsWithIdnames.

@Test
public void testTableIdsWithIdnames() {
    WNamingContext context = new WNamingContext("TEST");
    WDataTable table = new WDataTable();
    table.setDataModel(new SimpleTableDataModel(new String[][] { { "1" }, { "3" }, { "2" } }));
    WComponent repeated = new WBeanComponent();
    table.addColumn(new WTableColumn("dummy", repeated));
    context.add(table);
    table.setIdName("T");
    repeated.setIdName("X");
    context.setLocked(true);
    setActiveContext(new UIContextImpl());
    // Table ID
    Assert.assertEquals("Incorrect id for table with idname", "TEST" + WComponent.ID_CONTEXT_SEPERATOR + "T", table.getId());
    String tableId = table.getId();
    // Table repeater id
    Assert.assertEquals("Incorrect id for table repeater", tableId + "-row", table.getRepeater().getId());
    // Table repeater root id
    Assert.assertEquals("Incorrect id for table repeater root", tableId + "-row-r", table.getRepeater().getRepeatRoot().getId());
    String rowPrefix = table.getRepeater().getRepeatRoot().getId();
    // Row IDs
    for (UIContext uic : table.getRepeater().getRowContexts()) {
        // Id has uic row render id in it
        int row = ((SubUIContext) uic).getContextId();
        String repeatedId = rowPrefix + row + WComponent.ID_CONTEXT_SEPERATOR + "X";
        try {
            UIContextHolder.pushContext(uic);
            Assert.assertEquals("Incorrect id for repeated component with idname", repeatedId, repeated.getId());
        } finally {
            UIContextHolder.popContext();
        }
    }
}
Also used : SubUIContext(com.github.bordertech.wcomponents.WRepeater.SubUIContext) SubUIContext(com.github.bordertech.wcomponents.WRepeater.SubUIContext) Test(org.junit.Test)

Example 12 with SubUIContext

use of com.github.bordertech.wcomponents.WRepeater.SubUIContext in project wcomponents by BorderTech.

the class WRepeater_Test method testRepeaterInternalIds.

@Test
public void testRepeaterInternalIds() {
    WNamingContext context = new WNamingContext("TEST");
    WComponent repeated = new WBeanComponent();
    WRepeater repeater = new WRepeater(repeated);
    context.add(repeater);
    context.setLocked(true);
    setActiveContext(new UIContextImpl());
    repeater.setBeanList(Arrays.asList("A", "B", "C"));
    // Repeater ID
    Assert.assertEquals("Incorrect internal id for repeater", WComponent.DEFAULT_INTERNAL_ID + "0", repeater.getInternalId());
    String repeaterId = repeater.getInternalId();
    // Repeat root ID
    Assert.assertEquals("Incorrect internal id for repeater root", repeaterId + "r", repeater.getRepeatRoot().getInternalId());
    // Row IDs
    for (UIContext uic : repeater.getRowContexts()) {
        // Id has uic row render id in it
        int row = ((SubUIContext) uic).getContextId();
        String repeatedId = repeaterId + "r" + row + "a";
        try {
            UIContextHolder.pushContext(uic);
            Assert.assertEquals("Incorrect internal id for repeated component", repeatedId, repeated.getInternalId());
        } finally {
            UIContextHolder.popContext();
        }
    }
}
Also used : SubUIContext(com.github.bordertech.wcomponents.WRepeater.SubUIContext) SubUIContext(com.github.bordertech.wcomponents.WRepeater.SubUIContext) Test(org.junit.Test)

Example 13 with SubUIContext

use of com.github.bordertech.wcomponents.WRepeater.SubUIContext in project wcomponents by BorderTech.

the class WRepeater_Test method testDataChangeDuringRequest.

@Test
public void testDataChangeDuringRequest() {
    WRepeater repeater = new WRepeater();
    // We need a component which always retrieves its bean
    repeater.setRepeatedComponent(new WText() {

        @Override
        public void handleRequest(final Request request) {
            super.handleRequest(request);
            getBean();
        }

        @Override
        public void preparePaintComponent(final Request request) {
            super.preparePaintComponent(request);
            getBean();
        }
    });
    repeater.setLocked(true);
    UIContext uic = createUIContext();
    List<String> data = new ArrayList<>(Arrays.asList(ROW_DATA));
    setActiveContext(uic);
    repeater.setBeanList(data);
    MockRequest request = new MockRequest();
    repeater.handleRequest(request);
    String newValue = ROW_DATA[0] + ".new";
    data.add(newValue);
    repeater.preparePaint(request);
    SubUIContext lastRowContext = (SubUIContext) repeater.getRowContexts().get(data.size() - 1);
    Assert.assertEquals("Incorrect data for row context", newValue, repeater.getRowBeanForSubcontext(lastRowContext));
    DataBound component = (DataBound) repeater.getRepeatedComponent();
    setActiveContext(lastRowContext);
    Assert.assertEquals("Incorrect renderer value", newValue, component.getData());
}
Also used : SubUIContext(com.github.bordertech.wcomponents.WRepeater.SubUIContext) SubUIContext(com.github.bordertech.wcomponents.WRepeater.SubUIContext) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) ArrayList(java.util.ArrayList) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Example 14 with SubUIContext

use of com.github.bordertech.wcomponents.WRepeater.SubUIContext in project wcomponents by BorderTech.

the class WRepeater_Test method testRepeaterIdsWithIdnames.

@Test
public void testRepeaterIdsWithIdnames() {
    WNamingContext context = new WNamingContext("TEST");
    WComponent repeated = new WBeanComponent();
    WRepeater repeater = new WRepeater(repeated);
    context.add(repeater);
    repeater.setIdName("R");
    repeated.setIdName("X");
    context.setLocked(true);
    setActiveContext(new UIContextImpl());
    repeater.setBeanList(Arrays.asList("A", "B", "C"));
    // Repeater ID
    Assert.assertEquals("Incorrect id for repeater with idname", "TEST" + WComponent.ID_CONTEXT_SEPERATOR + "R", repeater.getId());
    String repeaterId = repeater.getId();
    // Repeat root ID
    Assert.assertEquals("Incorrect id for repeater root", repeaterId + "-r", repeater.getRepeatRoot().getId());
    // Row IDs
    for (UIContext uic : repeater.getRowContexts()) {
        // Id has uic row render id in it
        int row = ((SubUIContext) uic).getContextId();
        String repeatedId = repeaterId + WComponent.ID_CONTEXT_SEPERATOR + "r" + row + WComponent.ID_CONTEXT_SEPERATOR + "X";
        try {
            UIContextHolder.pushContext(uic);
            Assert.assertEquals("Incorrect id for repeated component with idname", repeatedId, repeated.getId());
        } finally {
            UIContextHolder.popContext();
        }
    }
}
Also used : SubUIContext(com.github.bordertech.wcomponents.WRepeater.SubUIContext) SubUIContext(com.github.bordertech.wcomponents.WRepeater.SubUIContext) Test(org.junit.Test)

Example 15 with SubUIContext

use of com.github.bordertech.wcomponents.WRepeater.SubUIContext in project wcomponents by BorderTech.

the class WRepeater_Test method testDataChange.

@Test
public void testDataChange() {
    final String text1 = "WRepeater_Test.testDataChange.text1";
    final String text2 = "WRepeater_Test.testDataChange.text2";
    WTextField textField = new WTextField();
    textField.setText(text1);
    WRepeater repeater = new WRepeater(textField);
    repeater.setLocked(true);
    UIContext uic = createUIContext();
    setActiveContext(uic);
    repeater.setBeanList(Arrays.asList(ROW_DATA));
    SubUIContext lastRowContext = (SubUIContext) repeater.getRowContexts().get(ROW_DATA.length - 1);
    setActiveContext(lastRowContext);
    textField.setText(text2);
    String lastRowId = textField.getId();
    Assert.assertEquals("Last row should have user text", text2, textField.getText());
    // Rows which are present in the new bean list should retain their data when setBeanList is called
    setActiveContext(uic);
    repeater.setBeanList(Arrays.asList(ROW_DATA[ROW_DATA.length - 1], ROW_DATA[0]));
    setActiveContext(repeater.getRowContexts().get(0));
    Assert.assertEquals("Row 1 should have previous user text", text2, textField.getText());
    Assert.assertTrue("Row 1 id should not have changed", lastRowId.equals(textField.getId()));
    setActiveContext(repeater.getRowContexts().get(1));
    Assert.assertEquals("Row 2 should have bean text", ROW_DATA[0], textField.getText());
    // Rows which are not present in the new bean list should lose their data when setBeanList is called
    repeater.setBeanList(Arrays.asList("x"));
    repeater.setBeanList(Arrays.asList(ROW_DATA));
    setActiveContext(repeater.getRowContexts().get(0));
    Assert.assertEquals("Row 0 should have bean text", ROW_DATA[0], textField.getText());
    setActiveContext(repeater.getRowContexts().get(1));
    Assert.assertEquals("Row 1 should have bean text", null, textField.getText());
    setActiveContext(repeater.getRowContexts().get(2));
    Assert.assertEquals("Row 2 should have bean text", ROW_DATA[2], textField.getText());
}
Also used : SubUIContext(com.github.bordertech.wcomponents.WRepeater.SubUIContext) SubUIContext(com.github.bordertech.wcomponents.WRepeater.SubUIContext) Test(org.junit.Test)

Aggregations

SubUIContext (com.github.bordertech.wcomponents.WRepeater.SubUIContext)19 Test (org.junit.Test)14 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)4 UIContext (com.github.bordertech.wcomponents.UIContext)2 RowIdWrapper (com.github.bordertech.wcomponents.WTable.RowIdWrapper)2 TableDataModel (com.github.bordertech.wcomponents.TableDataModel)1 TableTreeNode (com.github.bordertech.wcomponents.TableTreeNode)1 TreeTableDataModel (com.github.bordertech.wcomponents.TreeTableDataModel)1 WComponent (com.github.bordertech.wcomponents.WComponent)1 WDataTable (com.github.bordertech.wcomponents.WDataTable)1 WDataTableRowRenderer (com.github.bordertech.wcomponents.WDataTableRowRenderer)1 WRepeater (com.github.bordertech.wcomponents.WRepeater)1 WTable (com.github.bordertech.wcomponents.WTable)1 WTableColumn (com.github.bordertech.wcomponents.WTableColumn)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1 TreeNode (com.github.bordertech.wcomponents.util.TreeNode)1 ArrayList (java.util.ArrayList)1