use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class WDropdownTriggerActionExample_Test method testExample.
@Test
public void testExample() {
// Launch the web browser to the LDE
SeleniumWComponentsWebDriver driver = getDriver();
WDropdownTriggerActionExample ui = (WDropdownTriggerActionExample) getUi();
// Select "ACT" from State dropdown
driver.findElement(byWComponent(ui.getStateDropdown(), "ACT")).click();
Assert.assertTrue("Incorrect region selection on client", driver.findElement(byWComponent(ui.getRegionDropdown(), "")).isSelected());
// Context is required for in-JVM calls to work.
// This is generally not a good test, as it relies on the JVM not on the servlet.
UIContext uic = getUserContextForSession();
UIContextHolder.pushContext(uic);
// Should have round-tripped, check server and client-side states
Assert.assertEquals("Incorrect state selection on server", "ACT", ui.getStateDropdown().getSelected());
Assert.assertTrue("Incorrect state selection on client", driver.findElement(byWComponent(ui.getStateDropdown(), "ACT")).isSelected());
// Select "Woden" from Region dropdown
driver.findElement(byWComponent(ui.getRegionDropdown(), "Woden")).click();
// Should have round-tripped, check server and client-side states
Assert.assertEquals("Incorrect region selection on server", "Woden", ui.getRegionDropdown().getSelected());
Assert.assertTrue("Incorrect region selection on client", driver.findElement(byWComponent(ui.getRegionDropdown(), "Woden")).isSelected());
// Select "Torrens" from Suburb dropdown (no round trip)
driver.findElement(byWComponent(ui.getSuburbDropdown(), "Torrens")).click();
Assert.assertTrue("Incorrect suburb selection on client", driver.findElement(byWComponent(ui.getSuburbDropdown(), "Torrens")).isSelected());
// Select "VIC" from the State dropdown
driver.findElement(byWComponent(ui.getStateDropdown(), "VIC")).click();
Assert.assertTrue("Incorrect region selection on client", driver.findElement(byWComponent(ui.getRegionDropdown(), "")).isSelected());
// Select "Melbourne" from Region dropdown
driver.findElement(byWComponent(ui.getRegionDropdown(), "Melbourne")).click();
// Select "Torrens" from Suburb dropdown (no round trip)
driver.findElement(byWComponent(ui.getSuburbDropdown(), "Blackburn")).click();
Assert.assertTrue("Incorrect suburb selection on client", driver.findElement(byWComponent(ui.getSuburbDropdown(), "Blackburn")).isSelected());
UIContextHolder.popContext();
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class WListRenderer method paintRows.
/**
* Paints the rows.
*
* @param list the WList to paint the rows for.
* @param renderContext the RenderContext to paint to.
*/
protected void paintRows(final WList list, final WebXmlRenderContext renderContext) {
List<?> beanList = list.getBeanList();
WComponent row = list.getRepeatedComponent();
XmlStringBuilder xml = renderContext.getWriter();
for (int i = 0; i < beanList.size(); i++) {
Object rowData = beanList.get(i);
// Each row has its own context. This is why we can reuse the same
// WComponent instance for each row.
UIContext rowContext = list.getRowContext(rowData, i);
UIContextHolder.pushContext(rowContext);
try {
xml.appendTag("ui:cell");
row.paint(renderContext);
xml.appendEndTag("ui:cell");
} finally {
UIContextHolder.popContext();
}
}
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class WTableRenderer method doPaintRows.
/**
* Override paintRow so that we only paint the first-level nodes for tree-tables.
*
* @param table the table to paint the rows for.
* @param renderContext the RenderContext to paint to.
*/
private void doPaintRows(final WTable table, final WebXmlRenderContext renderContext) {
TableRepeater repeater = table.getRepeater();
WComponent row = repeater.getRepeatedComponent();
List<RowIdWrapper> wrappers = repeater.getBeanList();
Set<?> otherSelectedRows = new HashSet<>(table.getSelectedRows());
int index = -1;
for (RowIdWrapper wrapper : wrappers) {
index++;
Object rowKey = wrapper.getRowKey();
if (table.getSelectedRows().contains(rowKey)) {
otherSelectedRows.remove(rowKey);
}
// Child rows handled by the layout, so dont paint the row
if (wrapper.getParent() != null) {
continue;
}
// Each row has its own context. This is why we can reuse the same
// WComponent instance for each row.
UIContext rowContext = repeater.getRowContext(wrapper, index);
UIContextHolder.pushContext(rowContext);
try {
row.paint(renderContext);
} finally {
UIContextHolder.popContext();
}
}
this.selectedOnOther = otherSelectedRows.size();
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class WTableRowRendererRenderer method renderChildren.
/**
* @param renderer the WTableRowRenderer to paint.
* @param renderContext the RenderContext to paint to.
* @param children the children ids
*/
private void renderChildren(final WTableRowRenderer renderer, final WebXmlRenderContext renderContext, final List<RowIdWrapper> children) {
XmlStringBuilder xml = renderContext.getWriter();
WTable table = renderer.getTable();
WRepeater repeater = table.getRepeater();
TableModel dataModel = table.getTableModel();
// If there is a renderer specified by any child, we only paint content that has a specified renderer
boolean rendererPresent = false;
for (RowIdWrapper child : children) {
if (dataModel.getRendererClass(child.getRowIndex()) != null) {
rendererPresent = true;
break;
}
}
// Paint immediate children only.
if (rendererPresent) {
xml.appendTagOpen("ui:content");
// Always span all columns
xml.appendAttribute("spanAllCols", "true");
xml.appendClose();
for (RowIdWrapper child : children) {
UIContext nodeContext = repeater.getRowContext(child, child.getPosition());
WComponent expandedRenderer = renderer.getExpandedTreeNodeRenderer(dataModel.getRendererClass(child.getRowIndex()));
if (expandedRenderer != null) {
UIContextHolder.pushContext(nodeContext);
try {
expandedRenderer.paint(renderContext);
} finally {
UIContextHolder.popContext();
}
}
}
xml.appendEndTag("ui:content");
} else {
for (RowIdWrapper child : children) {
UIContext nodeContext = repeater.getRowContext(child, child.getPosition());
UIContextHolder.pushContext(nodeContext);
try {
render(renderer, renderContext);
} finally {
UIContextHolder.popContext();
}
}
}
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class DebugStructureInterceptor_Test method doRequest.
/**
* Does a request/response cycle for a WApplication.
*
* @return the xml output.
*/
private String doRequest() {
WApplication app = new WApplication();
app.setLocked(true);
UIContext uic = createUIContext();
uic.setUI(app);
setActiveContext(uic);
// Create interceptor
PageShellInterceptor pageInterceptor = new PageShellInterceptor();
DebugStructureInterceptor debugInterceptor = new DebugStructureInterceptor();
pageInterceptor.setBackingComponent(debugInterceptor);
pageInterceptor.attachUI(app);
// Action phase
MockRequest request = new MockRequest();
pageInterceptor.serviceRequest(request);
pageInterceptor.preparePaint(request);
// Render phase
MockResponse response = new MockResponse();
pageInterceptor.attachResponse(response);
pageInterceptor.paint(new WebXmlRenderContext(response.getWriter()));
return response.getWriterOutput();
}
Aggregations