/** * {@inheritDoc} */ @Override public void add(final WComponent component) { super.add(component); if (component instanceof Input) { setForComponent(component); } }
@Test public void testForComponentAccessors() { WText forComponent1 = new WText(); WText forComponent2 = new WText(); WLabel lbl = new WLabel("test", forComponent1); Assert.assertSame("forComponent accessor incorrect", forComponent1, lbl.getForComponent()); lbl.setForComponent(forComponent2); Assert.assertSame("forComponent accessors incorrect", forComponent2, lbl.getForComponent()); }
label.setForComponent(labelField);
@Test public void testDoPaintAllOptions() throws IOException, SAXException, XpathException { WTextArea text = new WTextArea(); text.setText("text1"); WLabel label = new WLabel(); label.setForComponent(text); label.setHint("hint1"); label.setAccessKey('A'); label.setText("label1"); WContainer root = new WContainer(); root.add(label); root.add(text); // Validate Schema assertSchemaMatch(root); // Check Attributes assertXpathEvaluatesTo(label.getId(), "//ui:label/@id", label); assertXpathEvaluatesTo(text.getId(), "//ui:label/@for", label); assertXpathEvaluatesTo("hint1", "//ui:label/@hint", label); assertXpathEvaluatesTo("A", "//ui:label/@accessKey", label); assertXpathEvaluatesTo("input", "//ui:label/@what", label); // Check Label assertXpathEvaluatesTo("label1", "//ui:label", label); // Add Children to Label WTextArea text2 = new WTextArea(); text2.setText("text2"); label.add(text2); assertSchemaMatch(root); assertXpathEvaluatesTo("text2", "//ui:label/ui:textarea", label); }