Ejemplo n.º 1
0
  @Override
  protected void onFirstShowPage() {
    super.onFirstShowPage();

    final PVerticalPanel layout = new PVerticalPanel();

    final FormView formView = new DefaultFormView();
    final FormConfiguration formConfiguration = new FormConfiguration();
    formConfiguration.setName("Form");
    final FormActivity formActivity = new FormActivity(formConfiguration, formView);

    final FormField field1 = new FormField("field1");
    formActivity.addFormField(field1);
    field1.addValidator(new NotEmptyFieldValidator());
    field1.addValidator(new DoubleFieldValidator());

    final FormFieldRenderer field2Renderer = new TextBoxFormFieldRenderer("field2");
    final FormField field2 = new FormField(field2Renderer);
    formActivity.addFormField(field2);

    final ListBoxFormFieldRenderer field3Renderer = new ListBoxFormFieldRenderer("field3");
    field3Renderer.addItem("Choice 1", 1);
    field3Renderer.addItem("Choice 2", 2);
    field3Renderer.addItem("Choice 3", 3);
    field3Renderer.addItem("Choice 4", 4);
    final FormField field3 = new FormField(field3Renderer);
    formActivity.addFormField(field3);

    final FormFieldRenderer field4Renderer = new DateBoxFormFieldRenderer("field4");
    final FormField field4 = new FormField(field4Renderer);
    formActivity.addFormField(field4);

    final FormFieldRenderer field5Renderer = new TextAreaFormFieldRenderer("field5");
    final FormField field5 = new FormField(field5Renderer);
    formActivity.addFormField(field5);

    final PSimplePanel formLayout = new PSimplePanel();
    layout.add(formLayout);
    formActivity.start(formLayout);

    final PButton validateButton = new PButton("Validate");
    validateButton.addClickHandler(
        new PClickHandler() {

          @Override
          public void onClick(final PClickEvent clickEvent) {
            final boolean isValid = formActivity.isValid();
            PNotificationManager.showTrayNotification(
                "The form is valid? " + (isValid ? "YES" : "NO"));
          }
        });
    layout.add(validateButton);

    examplePanel.setWidget(layout);
  }
  @Override
  protected void onFirstShowPage() {
    super.onFirstShowPage();

    final PTextBox name = new PTextBox();
    name.setPlaceholder("Cookie name");
    final PTextBox value = new PTextBox();
    name.setPlaceholder("Cookie value");
    final PButton add = new PButton("Add");
    add.addClickHandler(
        new PClickHandler() {

          @Override
          public void onClick(final PClickEvent event) {
            UIContext.get().getCookies().setCookie(name.getValue(), value.getValue());
          }
        });

    final PTextBox name2 = new PTextBox();
    name2.setPlaceholder("Cookie name");
    final PButton remove = new PButton("Remove");
    remove.addClickHandler(
        new PClickHandler() {

          @Override
          public void onClick(final PClickEvent event) {
            UIContext.get().getCookies().removeCookie(name2.getValue());
          }
        });

    final PHorizontalPanel addPanel = new PHorizontalPanel();
    addPanel.add(name);
    addPanel.add(value);
    addPanel.add(add);

    final PHorizontalPanel removePanel = new PHorizontalPanel();
    removePanel.add(name2);
    removePanel.add(remove);

    final PVerticalPanel panel = new PVerticalPanel();
    panel.setSpacing(10);

    panel.add(new PLabel("Add a cookie:"));
    panel.add(addPanel);
    panel.add(new PLabel("Remove a cookie:"));
    panel.add(removePanel);

    examplePanel.setWidget(panel);
  }