2011-01-21 2 views
0

J'ai un exemple d'application vaadin avec trois panneaux d'étape. J'entre des données dans les champs de l'étape 1 et je passe à l'étape 2 en cliquant sur le bouton suivant. Mais quand je veux changer quelque chose à l'étape précédente1 en cliquant sur le bouton précédent, toutes les données seront perdues. N'importe quelle aide sur cette question. Je veux que les données soient stockées n'importe quel utilisateur entre jusqu'à la fin de toutes les étapes.Vaadin Data Persist Problème dans les champs

J'ai une classe util pour afficher les données.

 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; 
} 

Mon Vaadin classe Application:

 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(); 
} 

    } 

Je lis des champs à partir du fichier xml et j'afficher en fonction de l'événement bouton précédent et suivant de l'utilisateur

Assistant de configuration xml:

<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> 
+0

nous montrent un code – fmucar

+0

fatih: S'il vous plaît trouver plus d'informations –

+0

vous ne sauvegardez pas les valeurs que vous avez obtenu de l'utilisateur? – fmucar

Répondre

0

Je suis tenté de définir les valeurs utilisateur en utilisant tf.setValue() méthode et cela fonctionne bien maintenant.

-2

Mieux vous utilisez des assistants pour Vaadin ajouter sur, son grand ajouter pour ce genre d'exigences