1 38 package com.gargoylesoftware.htmlunit.html; 39 40 import java.io.IOException ; 41 import java.util.Map ; 42 43 import com.gargoylesoftware.htmlunit.Page; 44 45 56 public class HtmlCheckBoxInput extends HtmlInput { 57 58 private final boolean initialCheckedState_; 60 61 69 public HtmlCheckBoxInput( final HtmlPage page, final Map attributes) { 70 super( page, attributes ); 71 72 initialCheckedState_ = isAttributeDefined("checked"); 74 75 if (getAttributeValue("value") == ATTRIBUTE_NOT_DEFINED) { 77 setAttributeValue("value", "on"); 78 } 79 } 80 81 82 85 public void reset() { 86 setChecked(initialCheckedState_); 87 } 88 89 94 public void setChecked( final boolean isChecked ) { 95 if( isChecked ) { 96 setAttributeValue( "checked", "checked" ); 97 } 98 else { 99 removeAttribute( "checked" ); 100 } 101 } 102 103 108 public String asText() { 109 if (isChecked()) { 110 return "checked"; 111 } 112 else { 113 return "unchecked"; 114 } 115 } 116 117 123 protected Page doClickAction(final Page defaultPage) throws IOException { 124 if (isChecked()) { 125 setChecked(false); 126 } 127 else { 128 setChecked(true); 129 } 130 131 return super.doClickAction(defaultPage); 132 } 133 134 139 protected boolean isStateUpdateFirst() { 140 return true; 141 } 142 } 143 144 | Popular Tags |