/** * @param margin the margin to include on the panel. * @return the panel with a margin. */ private WPanel createPanel(final Margin margin) { WText text = new WText(DUMMY_TEXT); text.setEncodeText(false); WPanel panel = new WPanel(WPanel.Type.BOX); panel.add(text); panel.setMargin(margin); return panel; } }
@Test public void testSanitizeOnOutput() { WText text = new WText("<form>content</form>"); text.setSanitizeOnOutput(true); text.setEncodeText(false); Assert.assertEquals("Expect output to be sanitized", "content", text.getText()); } }
/** * Override of preparePaintComponent to set the dynamic (user specific) text. * * @param request the request being responded to. */ @Override public void preparePaintComponent(final Request request) { String dateStr = "The current date is " + new Date(); dynamicText.setText(dateStr); }
/** * Creates a SimpleListRenderer. */ public SimpleListRenderer() { WText name = new WText(); WText type = new WText(); WText thing = new WText(); name.setBeanProperty("name"); type.setBeanProperty("type"); thing.setBeanProperty("thing"); WFieldLayout fields = new WFieldLayout(); fields.addField("Name", name); fields.addField("Type", type); fields.addField("Thing", thing); add(fields); } }
/** * @param label the column label */ public AbstractTableColumn(final String label) { this(null, label, new WText(), null); }
/** * applySettings creates the WCollapsible, and loads it into the container. */ private void applySettings() { // reset the container. container.reset(); // create the new collapsible. WText component1 = new WText("Here is some text that is collapsible via ajax."); WCollapsible collapsible1 = new WCollapsible(component1, "Collapsible", (CollapsibleMode) rbCollapsibleSelect.getSelected()); collapsible1.setCollapsed(cbCollapsed.isSelected()); collapsible1.setVisible(cbVisible.isSelected()); if (collapsible1.getMode() == CollapsibleMode.DYNAMIC) { component1.setText(component1.getText() + "\u00a0Generated on " + new Date()); } if (drpHeadingLevels.getSelected() != null) { collapsible1.setHeadingLevel((HeadingLevel) drpHeadingLevels.getSelected()); } // add the new collapsible to the container. container.add(collapsible1); }
@Test public void testGetText() { WText wtf = new WText(); String defaultText = "Dflt"; String myText = "MyText"; wtf.setText(defaultText); Assert.assertEquals("Incorrect default text", defaultText, wtf.getText()); // Set test for a users session wtf.setLocked(true); setActiveContext(createUIContext()); wtf.setText(myText); Assert.assertEquals("Should have session text", myText, wtf.getText()); resetContext(); Assert.assertEquals("Should have default text", defaultText, wtf.getText()); }
@Test public void testNoSanitizeOnOutput() { String input = "<form>content</form>"; WText text = new WText(input); text.setEncodeText(false); Assert.assertEquals("Expect output to not be sanitized", input, text.getText()); }
@Test public void testEncodeText() throws IOException, SAXException, XpathException { String value = "T1<b>T2</b>T3"; String encoded = WebUtilities.encode(value); WText text = new WText(); text.setText(value); // Encoded (default) String xml = toXHtml(text); Assert.assertTrue("XML should have encoded text", xml.contains(encoded)); // Not encoded text.setEncodeText(false); xml = toXHtml(text); Assert.assertTrue("XML should have not encoded text", xml.contains(value)); }
beanBoundText.setBeanProperty("beanAttribute"); beanProviderBoundText.setBeanProperty("innerBean.innerAttribute"); add(button2); beanProviderBoundText.setBeanProvider(new ExampleBeanProvider()); add(new WText("•")); add(new WHeading(HeadingLevel.H2, "Unencoded text containing a HTML character entity")); WText unescapedWithEntity = new WText("•"); unescapedWithEntity.setEncodeText(false); add(unescapedWithEntity);
@Test public void testIsDefaultState() { String defaultText = "Dflt"; String myText = "MyText"; WText wtf = new WText(defaultText); wtf.setLocked(true); setActiveContext(createUIContext()); Assert.assertTrue("Should be in default state by default", wtf.isDefaultState()); wtf.setText(myText); Assert.assertFalse("Should not be in default state after setting different text", wtf. isDefaultState()); wtf.setText(defaultText); Assert.assertTrue("Should be in default state after setting text to default text", wtf. isDefaultState()); }
@Test public void testConstructor1() { WText content = new WText(); WFigure figure = new WFigure(content, "label"); WText txt = (WText) figure.getDecoratedLabel().getBody(); Assert.assertEquals("Constructor - Incorrect label", "label", txt.getText()); Assert.assertSame("Constructor - Incorrect content", content, figure.getContent()); }
/** * test remove - child from shared list. */ @Test public void testRemoveCommon() { AbstractWComponent comp = new MockContainer(); WText text1 = new WText("XYZ"); WText text2 = new WText("ABC"); comp.add(text1); comp.add(text2); comp.remove(text1); // from shared list Assert.assertNull("shared should not contain text1", text1.getParent()); Assert.assertSame("shared should contain text2", text2, comp.getChildAt(0)); }
/** * {@inheritDoc} */ @Override public String getText() { return super.getText() + " generated at: " + new Date(); } }
/** * Construct example. */ public WSessionExample() { WMessages messages = new WMessages(true); messages .info("If \"ui:session\" is supported by the theme, wait 180 seconds to see a warning message and then a session expired message."); add(messages); WText txtSession = new WText() { @Override public String getText() { return "<ui:session timeout=\"180\" />"; } }; txtSession.setEncodeText(false); add(txtSession); } }
/** * Creates a WDropdownSubmitOnChangeExample. */ public WDropdownSubmitOnChangeExample() { actMessage.setEncodeText(false); add(new ExplanatoryText("Any form control component which is not a WButton will show a visible warning in its label if its " + "submitOnChange property is set true.")); WFieldLayout flay = new WFieldLayout(); add(flay); flay.setLabelWidth(25); flay.setMargin(new Margin(null, null, Size.LARGE, null)); flay.addField("State", stateSelector).getLabel().setHint("Selecting a state will update the available regions."); flay.addField("Region", regionSelector); // Used to test control of visibility as part of submit on change. add(actMessage); actMessage.setVisible(false); stateSelector.setOptions(new String[]{null, STATE_ACT, STATE_NSW, STATE_VIC}); //This is the flag which causes accessibility problems. It may be removed completely in future versions of WComponents. //you should use AJAX instead stateSelector.setSubmitOnChange(true); stateSelector.setActionOnChange(new Action() { @Override public void execute(final ActionEvent event) { updateRegion(); regionSelector.resetData(); } }); regionSelector.setSubmitOnChange(true); }
/** * Paints the given WText. * * @param component the WText to paint. * @param renderContext the RenderContext to paint to. */ @Override public void doRender(final WComponent component, final WebXmlRenderContext renderContext) { WText text = (WText) component; XmlStringBuilder xml = renderContext.getWriter(); String textString = text.getText(); if (textString != null) { if (text.isEncodeText()) { xml.print(WebUtilities.encode(textString)); } else { // If we are outputting unencoded content it must be XML valid. xml.print(HtmlToXMLUtil.unescapeToXML(textString)); } } } }