텍스트 필드와 레이블로 구성된 사용자 정의 위젯을 만드는 과정에서 단순히 텍스트 필드를 확장하고 이후에 이벤트 처리뿐만 아니라 텍스트 필드의 기능을 상속받을 수도 있습니다.텍스트 필드를 확장하는 사용자 정의 위젯
내가 이해할 수있는 것은 일반적으로 Composite를 확장 한 다음 생성자에서 initWidget()을 구현한다는 것입니다.
initWidget(binder.createAndBindUi(this));
텍스트 필드를 확장하여 비슷한 작업을 수행 할 수 있습니까?
레이블을 사용하여 표시기 텍스트 필드를 이미 만들었으므로이 사용자 정의 위젯에서 이벤트 처리를 적용하면 어딘가에서 사용하려고하면 예상치 못한 결과가 발생합니다.
import com.google.gwt.core.client.GWT;
public class IndicatorTextField extends Composite implements HasText, HasKeyUpHandlers{
public interface Binder extends UiBinder<Widget, IndicatorTextField> {
}
private static final Binder binder = GWT.create(Binder.class);
public interface Style extends CssResource{
String textStyling();
String requiredInputLabel();
String colorNotValidated();
}
@UiField Style style;
@UiField Label label;
@UiField TextBox textBox;
public IndicatorTextField()
{
initWidget(binder.createAndBindUi(this));
}
public void setBackgroundValidateTextbox(boolean validated)
{
if(validated)
{
textBox.getElement().addClassName(style.colorNotValidated());
}
else
{
textBox.getElement().removeClassName(style.colorNotValidated());
}
}
@Override
public String getText() {
return label.getText();
}
@Override
public void setText(String text) {
label.setText(text);
}
@UiHandler("textBox")
public void onKeyUp(KeyUpEvent event)
{
DomEvent.fireNativeEvent(event.getNativeEvent(), this);
}
@Override
public HandlerRegistration addKeyUpHandler(KeyUpHandler handler) {
//return textBox.addKeyUpHandler(handler);
return addDomHandler(handler, KeyUpEvent.getType());
}
}