我有一个带有三个步骤面板的示例vaadin应用程序。我在步骤1的字段中输入了一些数据,然后我点击下一步按钮进入步骤2。但是当我想通过点击上一个按钮改变上一步骤1中的某些内容时,所有数据都将丢失。可以在此问题上提供任何帮助。我希望数据存储在用户输入的任何内容中,直到所有步骤结束。
我有一个用于显示数据的util类。
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;
}
我的Vaadin申请类:
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();
}
}
我正在读取xml文件中的字段,我将根据用户的上一个和下一个按钮事件显示
向导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 :(得分:0)
我尝试使用tf.setValue()
方法设置用户值,现在工作正常。
答案 1 :(得分:-2)
最好使用向导添加vaadin,这对于这种要求是很好的补充