use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.
the class VelocityWriter method doReplace.
/**
* Replaces the search string by rendering the corresponding component.
*
* @param search the search String that was matched.
* @param backing the underlying writer to write the replacement to.
*/
@Override
protected void doReplace(final String search, final Writer backing) {
WComponent component = componentsByKey.get(search);
UIContextHolder.pushContext(uic);
try {
component.paint(new WebXmlRenderContext((PrintWriter) backing));
} finally {
UIContextHolder.popContext();
}
}
use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.
the class WTabGroupRenderer_Test method testDoPaint.
@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
String groupName = "WTabGroupRenderer_Test.testDoPaint.groupName";
WTabGroup tabGroup = new WTabGroup(groupName);
WComponent wrapped = wrapTabGroup(tabGroup);
assertXpathNotExists("//ui:tab", wrapped);
tabGroup.addTab(new WText("dummy"), "dummy", TabMode.CLIENT);
assertXpathExists("//ui:tab", wrapped);
assertSchemaMatch(wrapped);
}
use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.
the class WComponentGroupRenderer_Test method testDoPaint.
@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
// Setup Group
WComponent actionTarget1 = new WTextField();
WComponent actionTarget2 = new WTextField();
WComponent actionTarget3 = new WTextField();
WComponentGroup<WComponent> group = new WComponentGroup<>();
group.addToGroup(actionTarget1);
group.addToGroup(actionTarget2);
group.addToGroup(actionTarget3);
WContainer root = new WContainer();
root.add(actionTarget1);
root.add(actionTarget2);
root.add(actionTarget3);
root.add(group);
setActiveContext(createUIContext());
// Validate Schema
assertSchemaMatch(root);
// Check group
assertXpathEvaluatesTo("1", "count(//ui:componentGroup)", root);
assertXpathEvaluatesTo("3", "count(//ui:componentGroup/ui:component)", root);
assertXpathEvaluatesTo(group.getId(), "//ui:componentGroup/@id", root);
assertXpathEvaluatesTo(actionTarget1.getId(), "//ui:componentGroup/ui:component[position()=1]/@id", root);
assertXpathEvaluatesTo(actionTarget2.getId(), "//ui:componentGroup/ui:component[position()=2]/@id", root);
assertXpathEvaluatesTo(actionTarget3.getId(), "//ui:componentGroup/ui:component[position()=3]/@id", root);
}
use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.
the class AjaxInterceptor method serviceRequest.
/**
* {@inheritDoc}
*/
@Override
public void serviceRequest(final Request request) {
String triggerId = request.getParameter(WServlet.AJAX_TRIGGER_PARAM_NAME);
AjaxOperation ajaxOperation = AjaxHelper.getCurrentOperation();
if (ajaxOperation == null) {
throw new IllegalStateException("No AJAX operation available for trigger " + triggerId + ".");
}
ComponentWithContext triggerWithContext = AjaxHelper.getCurrentTriggerAndContext();
if (triggerWithContext == null) {
throw new IllegalStateException("No component/context available for AJAX trigger " + triggerId + ".");
}
UIContext uic = UIContextHolder.getCurrent();
// Reset the focus for this new request.
uic.setFocussed(null, null);
// We've hit the action phase, so we do want focus on this app.
uic.setFocusRequired(true);
// Process trigger only
if (isProcessTriggerOnly(triggerWithContext, ajaxOperation)) {
// Get user context
UIContext tuic = triggerWithContext.getContext();
UIContextHolder.pushContext(tuic);
try {
WComponent trigger = triggerWithContext.getComponent();
trigger.serviceRequest(request);
// Manually invoke laters as the InvokeLaters in the service request is not run due to the trigger
// having a "parent"
tuic.doInvokeLaters();
} finally {
UIContextHolder.popContext();
}
} else if ("GET".equals(request.getMethod())) {
// GET only supports the above scenarios
throw new IllegalStateException("GET is not supported for the AJAX trigger " + triggerId + ".");
} else {
// service the request
super.serviceRequest(request);
}
}
use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.
the class PlainLauncher method getUI.
/**
* This method has been overridden to load a WComponent from parameters.
*
* @param httpServletRequest the servlet request being handled.
* @return the top-level WComponent for this servlet.
*/
@Override
public synchronized WComponent getUI(final Object httpServletRequest) {
String configuredUIClassName = getComponentToLaunchClassName();
if (sharedUI == null || !Util.equals(configuredUIClassName, uiClassName)) {
uiClassName = configuredUIClassName;
WComponent ui = createUI();
if (ui instanceof WApplication) {
sharedUI = (WApplication) ui;
} else {
LOG.warn("Top-level component should be a WApplication." + " Creating WApplication wrapper...");
sharedUI = new WApplication();
ui.setLocked(false);
sharedUI.add(ui);
sharedUI.setLocked(true);
}
if (ConfigurationProperties.getLdeServerShowMemoryProfile()) {
ProfileContainer profiler = new ProfileContainer();
sharedUI.setLocked(false);
sharedUI.add(profiler);
sharedUI.setLocked(true);
}
}
return sharedUI;
}
Aggregations