PDA

View Full Version : Wrong display DateField



catalin.ciobanu
7 Nov 2011, 8:41 AM
Hi guys, I try to display some Fields<> into an LayoutContainer() with FormLayout() like here:



formData = new FormData("90%");
right = new LayoutContainer();
right.setStyleAttribute("paddingLeft", "10px");
layout = new FormLayout();
layout.setLabelAlign(LabelAlign.LEFT);
right.setLayout(layout);




if ("DATA".equals(type)) {
DateField _date = new DateField();
_date.setId("data");
_date.setItemId("customField" + i);
DateTimePropertyEditor dateFormat = new DateTimePropertyEditor(
"MM-dd-yyyy");
_date.setPropertyEditor(dateFormat);
if ("true".equals(req)) {
_date.setAllowBlank(false);
}
if (value != null && !("".equals(value))) {
_date.setValue(dateFormat
.convertStringValue(value));
}
_date.setFieldLabel(st);
right.add(_date, formData);
}


Is there any known bug concerning this ? Has anyone experienced this problem before ?

catalin.ciobanu
7 Nov 2011, 8:44 AM
here are the screenshots (sory for 2xPosting)
1.
29090
2.

29091
3.
29092
4.
29093

sven
7 Nov 2011, 1:12 PM
You should add some description on what youre screenshots are actually showing. You should also try to reproduce this in a small, standalone testcase implementing EntyrPoint.

catalin.ciobanu
8 Nov 2011, 12:23 AM
public class SomeClass implements EntryPoint {

public static Button submit;
public static Button anulla;
public static FormPanel panel;
private static LayoutContainer right;
private static FormData formData;

public void addForm(ContentPanel cp) {
cp.setHeaderVisible(false);
formData = new FormData("90%");
FormPanel panel = new FormPanel();
panel.setFrame(true);
panel.setHeaderVisible(false);
panel.setLabelAlign(LabelAlign.LEFT);
panel.setButtonAlign(HorizontalAlignment.CENTER);

LayoutContainer main = new LayoutContainer();
main.setLayout(new ColumnLayout());

LayoutContainer left = new LayoutContainer();
left.setStyleAttribute("paddingRight", "10px");
FormLayout layout = new FormLayout();
layout.setLabelAlign(LabelAlign.LEFT);
left.setLayout(layout);

TextField<String> nome = new TextField<String>();
nome.setFieldLabel("Nome");
nome.setAllowBlank(false);
left.add(nome, formData);

TextField<String> note = new TextField<String>();
note.setFieldLabel("Note");
left.add(note, formData);

TextField<String> oggetto = new TextField<String>();
oggetto.setFieldLabel("Oggetto");
left.add(oggetto, formData);

TextField<String> ricerca1 = new TextField<String>();
ricerca1.setFieldLabel("Ricerca1");
left.add(ricerca1, formData);

TextField<String> ricerca2 = new TextField<String>();
ricerca2.setFieldLabel("Ricerca2");
left.add(ricerca2, formData);

right = new LayoutContainer();
right.setStyleAttribute("paddingLeft", "10px");
layout = new FormLayout();
layout.setLabelAlign(LabelAlign.LEFT);
right.setLayout(layout);

DateTimePropertyEditor dateFormat = new DateTimePropertyEditor(
"MM-dd-yyyy");
List<Field> list = new ArrayList<Field>();
DateField data1 = new DateField();
data1.setFieldLabel("data1");
data1.setPropertyEditor(dateFormat);
list.add(data1);
DateField data2 = new DateField();
data2.setFieldLabel("data2");
data2.setPropertyEditor(dateFormat);
list.add(data2);
DateField data3 = new DateField();
data3.setFieldLabel("data3");
data3.setPropertyEditor(dateFormat);
list.add(data3);
DateField data4 = new DateField();
data4.setFieldLabel("data4");
data4.setPropertyEditor(dateFormat);
list.add(data4);
DateField data5 = new DateField();
data5.setFieldLabel("data5");
data5.setPropertyEditor(dateFormat);
list.add(data5);
int i = 0;
for (Field f : list) {
f.setId("custom" + i); //if I remove this it works WHY?
f.setItemId("data");
((DateField) f).setAllowBlank(false);
right.add(f, formData);
}
main.add(left, new ColumnData(.5));
main.add(right, new ColumnData(.5));
panel.add(main, new FormData("90%"));
submit = new Button("Modifica");
// submit.addSelectionListener(MyButtons.documentHandler.editDocument());
anulla = new Button("Anulla");
// anulla.addSelectionListener(MyButtons.documentHandler.editDocument());

panel.addButton(submit);
panel.addButton(anulla);
panel.setButtonAlign(HorizontalAlignment.CENTER);
FormButtonBinding binding = new FormButtonBinding(panel);
binding.addButton(submit);
cp.add(panel);
}
@Override
public void onModuleLoad() {
ContentPanel cp = new ContentPanel();
cp.setWidth(600);
cp.setHeaderVisible(false);
addForm(cp);
RootPanel.get().add(cp);
}
}

sven
8 Nov 2011, 1:02 AM
IDs have to be unique. In Your code i never see you increasing "i"

catalin.ciobanu
8 Nov 2011, 1:05 AM
Yeah I forgot about unique id's and I kind of relied on id when identifying the field for later usage. It's clear now where I was wrong, Thanks sven.