/** * Sets the text for this HtmlOption. * @param text the text */ public void setText(final String text) { if (text == null || text.isEmpty()) { removeAllChildren(); } else { final DomNode child = getFirstChild(); if (child == null) { appendChild(new DomText(getPage(), text)); } else { child.setNodeValue(text); } } }
/** * Sets the text for this HtmlOption. * @param text the text */ public void setText(final String text) { if (text == null || text.isEmpty()) { removeAllChildren(); } else { final DomNode child = getFirstChild(); if (child == null) { appendChild(new DomText(getPage(), text)); } else { child.setNodeValue(text); } } }
/** * JavaScript constructor. This must be declared in every JavaScript file because * the rhino engine won't walk up the hierarchy looking for constructors. * @param newText the text * @param newValue the value * @param defaultSelected Whether the option is initially selected * @param selected the current selection state of the option */ public void jsConstructor(final String newText, final String newValue, final boolean defaultSelected, final boolean selected) { final HtmlPage page = (HtmlPage) getWindow().getWebWindow().getEnclosedPage(); AttributesImpl attributes = null; if (defaultSelected) { attributes = new AttributesImpl(); attributes.addAttribute(null, "selected", "selected", null, "selected"); } final HtmlOption htmlOption = (HtmlOption) HTMLParser.getFactory(HtmlOption.TAG_NAME).createElement( page, HtmlOption.TAG_NAME, attributes); htmlOption.setSelected(selected); setDomNode(htmlOption); if (newText != null && !newText.equals("undefined")) { htmlOption.appendChild(new DomText(page, newText)); } if (newValue != null && !newValue.equals("undefined")) { htmlOption.setValueAttribute(newValue); } }
/** * JavaScript constructor. This must be declared in every JavaScript file because * the rhino engine won't walk up the hierarchy looking for constructors. * @param newText the text * @param newValue the value * @param defaultSelected Whether the option is initially selected * @param selected the current selection state of the option */ public void jsConstructor(final String newText, final String newValue, final boolean defaultSelected, final boolean selected) { final HtmlPage page = (HtmlPage) getWindow().getWebWindow().getEnclosedPage(); AttributesImpl attributes = null; if (defaultSelected) { attributes = new AttributesImpl(); attributes.addAttribute(null, "selected", "selected", null, "selected"); } final HtmlOption htmlOption = (HtmlOption) HTMLParser.getFactory(HtmlOption.TAG_NAME).createElement( page, HtmlOption.TAG_NAME, attributes); htmlOption.setSelected(selected); setDomNode(htmlOption); if (newText != null && !newText.equals("undefined")) { htmlOption.appendChild(new DomText(page, newText)); } if (newValue != null && !newValue.equals("undefined")) { htmlOption.setValueAttribute(newValue); } }
/** * JavaScript constructor. This must be declared in every JavaScript file because * the rhino engine won't walk up the hierarchy looking for constructors. * @param newText the text * @param newValue the value * @param defaultSelected Whether the option is initially selected * @param selected the current selection state of the option */ public void jsConstructor(final String newText, final String newValue, final boolean defaultSelected, final boolean selected) { final HtmlPage page = (HtmlPage) getWindow().getWebWindow().getEnclosedPage(); AttributesImpl attributes = null; if (defaultSelected) { attributes = new AttributesImpl(); attributes.addAttribute(null, "selected", "selected", null, "selected"); } final HtmlOption htmlOption = (HtmlOption) HTMLParser.getFactory(HtmlOption.TAG_NAME).createElement( page, HtmlOption.TAG_NAME, attributes); htmlOption.setSelected(selected); setDomNode(htmlOption); if (newText != null && !newText.equals("undefined")) { htmlOption.appendChild(new DomText(page, newText)); } if (newValue != null && !newValue.equals("undefined")) { htmlOption.setValueAttribute(newValue); } }
/** * JavaScript constructor. * @param newText the text * @param newValue the value * @param defaultSelected Whether the option is initially selected * @param selected the current selection state of the option */ @JsxConstructor({CHROME, FF, EDGE}) public void jsConstructor(final String newText, final String newValue, final boolean defaultSelected, final boolean selected) { final HtmlPage page = (HtmlPage) getWindow().getWebWindow().getEnclosedPage(); AttributesImpl attributes = null; if (defaultSelected) { attributes = new AttributesImpl(); attributes.addAttribute(null, "selected", "selected", null, "selected"); } final HtmlOption htmlOption = (HtmlOption) HTMLParser.getFactory(HtmlOption.TAG_NAME).createElement( page, HtmlOption.TAG_NAME, attributes); htmlOption.setSelected(selected); setDomNode(htmlOption); if (!"undefined".equals(newText)) { htmlOption.appendChild(new DomText(page, newText)); htmlOption.setLabelAttribute(newText); } if (!"undefined".equals(newValue)) { htmlOption.setValueAttribute(newValue); } }
/** * JavaScript constructor. * @param newText the text * @param newValue the value * @param defaultSelected Whether the option is initially selected * @param selected the current selection state of the option */ @JsxConstructor({CHROME, FF, EDGE}) public void jsConstructor(final String newText, final String newValue, final boolean defaultSelected, final boolean selected) { final HtmlPage page = (HtmlPage) getWindow().getWebWindow().getEnclosedPage(); AttributesImpl attributes = null; if (defaultSelected) { attributes = new AttributesImpl(); attributes.addAttribute(null, "selected", "selected", null, "selected"); } final HtmlOption htmlOption = (HtmlOption) HTMLParser.getFactory(HtmlOption.TAG_NAME).createElement( page, HtmlOption.TAG_NAME, attributes); htmlOption.setSelected(selected); setDomNode(htmlOption); if (!"undefined".equals(newText)) { htmlOption.appendChild(new DomText(page, newText)); htmlOption.setLabelAttribute(newText); } if (!"undefined".equals(newValue)) { htmlOption.setValueAttribute(newValue); } }
/** * Sets the text for this HtmlOption. * @param text the text */ public void setText(final String text) { if (getPage().getWebClient().getBrowserVersion().isIE() && (text == null || text.length() == 0)) { removeAllChildren(); } else { final DomNode child = getFirstChild(); if (child == null) { appendChild(new DomText(getPage(), text)); } else { child.setNodeValue(text); } } }
/** * Sets the text for this HtmlOption. * @param text the text */ public void setText(final String text) { if (getPage().getWebClient().getBrowserVersion().isIE() && (text == null || text.length() == 0)) { removeAllChildren(); } else { final DomNode child = getFirstChild(); if (child == null) { appendChild(new DomText(getPage(), text)); } else { child.setNodeValue(text); } } }
/** * Sets the text for this HtmlOption. * @param text the text */ public void setText(final String text) { if (getPage().getWebClient().getBrowserVersion().isIE() && (text == null || text.length() == 0)) { removeAllChildren(); } else { final DomNode child = getFirstChild(); if (child == null) { appendChild(new DomText(getPage(), text)); } else { child.setNodeValue(text); } } }
/** * Changes the number of options: removes options if the new length * is less than the current one else add new empty options to reach the * new length. * @param newLength the new length property value */ public void jsxSet_length(final int newLength) { final int currentLength = htmlSelect_.getOptionSize(); if (currentLength > newLength) { htmlSelect_.setOptionSize(newLength); } else { for (int i = currentLength; i < newLength; i++) { final HtmlOption option = (HtmlOption) HTMLParser.getFactory(HtmlOption.TAG_NAME).createElement( htmlSelect_.getPage(), HtmlOption.TAG_NAME, null); htmlSelect_.appendOption(option); if (!getBrowserVersion().isIE()) { option.appendChild(new DomText(option.getPage(), "")); } } } }
/** * Changes the number of options: removes options if the new length * is less than the current one else add new empty options to reach the * new length. * @param newLength the new length property value */ public void jsxSet_length(final int newLength) { final int currentLength = htmlSelect_.getOptionSize(); if (currentLength > newLength) { htmlSelect_.setOptionSize(newLength); } else { for (int i = currentLength; i < newLength; i++) { final HtmlOption option = (HtmlOption) HTMLParser.getFactory(HtmlOption.TAG_NAME).createElement( htmlSelect_.getPage(), HtmlOption.TAG_NAME, null); htmlSelect_.appendOption(option); if (!getBrowserVersion().isIE()) { option.appendChild(new DomText(option.getPage(), "")); } } } }
/** * Changes the number of options: removes options if the new length * is less than the current one else add new empty options to reach the * new length. * @param newLength the new length property value */ public void jsxSet_length(final int newLength) { final int currentLength = htmlSelect_.getOptionSize(); if (currentLength > newLength) { htmlSelect_.setOptionSize(newLength); } else { for (int i = currentLength; i < newLength; i++) { final HtmlOption option = (HtmlOption) HTMLParser.getFactory(HtmlOption.TAG_NAME).createElement( htmlSelect_.getPage(), HtmlOption.TAG_NAME, null); htmlSelect_.appendOption(option); if (!getBrowserVersion().isIE()) { option.appendChild(new DomText(option.getPage(), "")); } } } }
/** * Changes the number of options: removes options if the new length * is less than the current one else add new empty options to reach the * new length. * @param newLength the new length property value */ @JsxSetter public void setLength(final int newLength) { if (newLength < 0) { if (getBrowserVersion().hasFeature(JS_SELECT_OPTIONS_IGNORE_NEGATIVE_LENGTH)) { return; } throw Context.reportRuntimeError("Length is negative"); } final int currentLength = htmlSelect_.getOptionSize(); if (currentLength > newLength) { htmlSelect_.setOptionSize(newLength); } else { for (int i = currentLength; i < newLength; i++) { final HtmlOption option = (HtmlOption) HTMLParser.getFactory(HtmlOption.TAG_NAME).createElement( htmlSelect_.getPage(), HtmlOption.TAG_NAME, null); htmlSelect_.appendOption(option); if (!getBrowserVersion().hasFeature(JS_SELECT_OPTIONS_DONT_ADD_EMPTY_TEXT_CHILD_WHEN_EXPANDING)) { option.appendChild(new DomText(option.getPage(), "")); } } } }
/** * Changes the number of options: removes options if the new length * is less than the current one else add new empty options to reach the * new length. * @param newLength the new length property value */ @JsxSetter public void setLength(final int newLength) { if (newLength < 0) { if (getBrowserVersion().hasFeature(JS_SELECT_OPTIONS_IGNORE_NEGATIVE_LENGTH)) { return; } throw Context.reportRuntimeError("Length is negative"); } final int currentLength = htmlSelect_.getOptionSize(); if (currentLength > newLength) { htmlSelect_.setOptionSize(newLength); } else { for (int i = currentLength; i < newLength; i++) { final HtmlOption option = (HtmlOption) HTMLParser.getFactory(HtmlOption.TAG_NAME).createElement( htmlSelect_.getPage(), HtmlOption.TAG_NAME, null); htmlSelect_.appendOption(option); if (!getBrowserVersion().hasFeature(JS_SELECT_OPTIONS_DONT_ADD_EMPTY_TEXT_CHILD_WHEN_EXPANDING)) { option.appendChild(new DomText(option.getPage(), "")); } } } }