开发者

Vaadin Data Persist Problem in the Fields

I have a sample vaadin application with three step panels.I am entering some data in the fields of step1 and I am proceeding to step2 by clicking on next button. But when I want to change some thing in the previous step1 by clicking on previous button all the data will be lost.Can any one help on this issue.I want the data to be stored whatever user enters until end of all steps.

I have a util class for displaying the data.

     public static AbsoluteLayout showUI(String uiname, WizardPanel panel,
           HashMap data) {
      UiType ui = WizardController.getUiComponent(uiname);
      List fields = ui.getField();
      AbsoluteLayout layout = (AbsoluteLayout) panel.p.getContent();

      // Iterating to the list of fields in the panel
      for (int i = 0; i < fields.size(); i++) {
       FieldType field = (FieldType) fields.get(i);
       List attributes = field.getAttr();
       TextField tf = new TextField();
       ComboBox cb = new ComboBox();
       TextField editor = new TextField();
       final Label Label_3 = new Label();
       CheckBox chk = null;
       Link link = null;
       Embedded img = null;
       boolean isChk = false;
       boolean isTxt = false;
       boolean isDrp = false;
       boolean isLink = false;
       boolean isImg = false;

       String object = "";
       for (int j = 0; j < attributes.size(); j++) {
        AttributeType attr = (AttributeType) attributes.get(j);

        if (attr.getName().equals("label")) {
         Label_3.setImmediate(false);
         Label_3.setHeight("100.0%");
         Label_3.setWidth("100.0%");
         Label_3.setCaption(attr.getValue());
        } else if (attr.getName().equals("type")) {
         if (attr.getValue().equals("text")) {
          tf.setWidth(200, Sizeable.UNITS_PIXELS);
          tf.setData(field.getName());
          isTxt = true;
         } else if (attr.getValue().equals("dropdown")) {
          cb.setWidth(200, Sizeable.UNITS_PIXELS);
          isDrp = true;
         } else if (attr.getValue().equals("checkbox")) {
          chk = new CheckBox();
          isChk = true;
         } else if (attr.getValue().equals("link")) {
          link = new Link();
          isLink = true;
         } else if (attr.getValue().equals("image")) {
          img = new Embedded();
          isImg = true;
         } else if (attr.getValue().equals("textarea")) {
          editor.setRows(10);
          editor.setColumns(30)

;
      editor.setImmediate(true);
      layout.addComponent(editor, "top:" + top + "px;left:"
        + left + "px;");
     }
    } else if (attr.getName().equals("label_top")) {
     labelTop = Integer.parseInt(attr.getValue());
    } else if (attr.getName().equals("label_left")) {
     labelLeft = Integer.parseInt(attr.getValue());
     layout.addComponent(Label_3, "top:" + labelTop + "px;left:"
       + labelLeft + "px;");
    } else if (attr.getName().equals("field_top")) {
     top = Integer.parseInt(attr.getValue());
    } else if (attr.getName().equals("field_left")) {
     left = Integer.parseInt(attr.getValue());
     left = left + 100;
     if (isTxt) {
      layout.addComponent(tf, "top:" + top + "px;left:"
        + left + "px;");
     }
    } else if (attr.getName().equals("required")) {
     if (attr.getValue() != null || attr.getValue() != "")
      tf.setRequired(new Boolean(attr.getValue()));
    } else if (attr.getName().equals("caption")) {
     if (attr.getValue() != null) {
      if (isChk) {
       chk.setCaption(attr.getValue());
       chk.setImmediate(true);
       layout.addComponent(chk, "top:" + top + "px;left:"
         + left + "px;");
      }
      if (isLink)
       link.setCaption(attr.getValue());

     }
    } else if (attr.getName().equals("target")) {

     if (attr.getValue() != null) {
      if (isLink) {
       link.setResource(new ExternalResource(attr
         .getValue()));
       layout.addComponent(link, "top:" + top + "px;left:"
         + left + "px;");
      }
     }
    } else if (attr.getName().equals("path")) {
     if (attr.getValue() != null) {
      if (isImg) {
       img.setSource(new ThemeResource(attr.getValue()));
      }
     }

    } else if (attr.getName().equals("name")) {

     if (attr.getValue() != null) {
      if (isImg) {
       img.setCaption(attr.getValue());
       layout.addComponent(img, "top:" + top + "px;left:"
         + left + "px;");
      }
     }
    } else if (attr.getName().equals("secret")) {
     if (tf.getValue() != null) {
      if (attr.getValue().equals("true"))
       tf.setSecret(true);
      else
       tf.setEnabled(false);
     }
    } else if (attr.getName().equals("readonly")) {
     if (tf.getData() != null) {
      if (attr.getValue().equals("true"))
       tf.setEnabled(false);
      else
       tf.setEnabled(true);
     } 
    } else if (attr.getName().equals("values")) {
     if (tf.getData() != null) {
      tf.setValue("");
     } else if (attr.getValue() != null) {
      String values = attr.getValue();
      String[] array = values.split(";");
      for (int k = 0; k < array.length; k++) {
       cb.addItem(array[k]);
      }
     }

     layout.addComponent(cb, "top:" + top + "px;left:" + left
       + "px;");
    } else if (attr.getName().equals("object")) {
     object = attr.getValue();

    } else if (attr.getName().equals("object_field")) {
     if (data != null) {
      String val = null;
      String[] objhierarchy = attr.getValue().split("\\.");
      if (objhierarchy.length == 0
        || objhierarchy.length == 1) {
       val = (String) data.get(attr.getValue());
      } else {
       HashMap temp1 = data;
       HashMap temp2 = null;
       for (int k = 0; k < objhierarchy.length - 1; k++) {
        temp2 = (HashMap) temp1.get(objhierarchy[k]);
        temp1 = temp2;
       }

       if (temp2
         .get(objhierarchy[objhierarchy.length - 1]) instanceof List) {
        ArrayList list = (ArrayList) temp2
          .get(objhierarchy[objhierarchy.length - 1]);
        val = (String) list.get(0);
       } else if (temp2
         .get(objhierarchy[objhierarchy.length - 1]) instanceof String) {
        val = (String) temp2
          .get(objhierarchy[objhierarchy.length - 1]);
       } else {
        val = "";
       }
      }
      if (tf.getData() != null) {
       tf.setValue(val);
      }

      /*
       * String fieldVal = ""; HashMap m = null; HashMap temp =
       * data; if (temp.get(object+"_"+attr.getValue()) !=
       * null) { fieldVal =
       * (String)temp.get(object+"_"+attr.getValue());
       * if(tf.getData() != null) { tf.setValue(fieldVal); } }
       * else { if(temp.get(object) instanceof HashMap){ m =
       * (HashMap)temp.get(object); fieldVal =
       * (String)m.get(object+"_"+attr.getValue());
       * if(tf.getData() != null) { tf.setValue(fieldVal); } } }
       */

     }
    }

    // left = left + 100;
   }// for loop for attributes within 开发者_运维技巧a field

   top = top + 30;
   left = 10;
   labelTop = labelTop + 30;
   labelLeft = 10;

  }// for loop for fields

  // sheet.addTab(layout, "Tab", null);
  return layout;
 }

My Vaadin Application Class:

        public class VaadinMainApplication extends Application {

public init(){

        WizardController.init();

       setMainWindow(new Window("::Administration & Customer Care V 3.1::"));
       setTheme("reindeer");
       System.out.println("Theme using is" + getTheme());

       layout = new VerticalLayout();
       layout.setSizeFull();
           layout.addComponent(new WizardPanel("Create User Wizard"));
           getMainWindow().setContent(layout);
           getMainWindow().setSizeFull();
}

    }

I am reading fields from the xml file and I will display based on the previous and next button event of the user

Wizard xml configuration:

<Wizards>
    <wizard wizardId="createUserWizard" nameKey="Create User Wizard"  >

        <page pageId="1" nameKey="wizard_page_1"
            introKey="User Details." order="1">
            <ui>createUser</ui>
            <pagePopulator
                class="com.wizard.createUserPopulator"
                method="userPopulator" />
            <pageValidator
                class="com.wizard.createUserValidator"
                method="validateUser" />
        </page>

        <page pageId="2" nameKey="wizard_page_2"
            introKey="Personal details" order="2">
            <ui>personalDetails</ui>
            <pagePopulator
                class="com.wizard.createUserPopulator"
                method="userPopulator" />
            <pageValidator
                class="com.wizard.createUserValidator"
                method="validatePersonalDetails" />
        </page>

        <page pageId="3" nameKey="wizard_page_3" introKey="Response"
            order="3">
            <ui>final</ui>
            <pagePopulator
                class="com.wizard.createUserPopulator"
                method="createUser" />
        </page>

    </wizard>


I am tried to set the user values using tf.setValue() method and it works fine now.


Better you use wizards for vaadin add on, its great add on for this kind of requirements

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜