The code bellow:
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import wicket.markup.html.*;
import wicket.markup.html.basic.Label;
import wicket.markup.html.form.Form;
import wicket.markup.html.link.Link;
import wicket.markup.html.list.ListItem;
import wicket.markup.html.list.ListView;
import wicket.markup.html.panel.FeedbackPanel;
import wicket.markup.html.form.*;
import wicket.model.*;
public class TestPage extends WebPage implements Serializable
{
private static final long serialVersionUID = 1L;
private List testList=new ArrayList();
private ListView testListView;
public TestPage()
{
final FeedbackPanel testFeedback = new
FeedbackPanel("testFeedback");
add(testFeedback);
WebMarkupContainer dataContainer = new
WebMarkupContainer("data");
dataContainer.setOutputMarkupId(true);
this.add(dataContainer);
testListView = new ListView("testList", testList){
private static final long serialVersionUID = 1L;
protected void populateItem(ListItem listItem){
final TestTO
to=(TestTO)listItem.getModelObject();
listItem.add(new Label("file",
to.getFileInput()));
System.out.println("to.getFileInput(0:"+to.getFileInput());
listItem.add(new
Label("notes",to.getFileNotes()));
listItem.add(new Link("delete"){
public void onClick()
{
testList.remove(to);
}
});
}
};
dataContainer.add(testListView);
Form uploadForm = new Form("uploadform",new
CompoundPropertyModel(new
TestTO())){
private static final long serialVersionUID = 1L;
protected void onSubmit(){
TestTO to=(TestTO)getModelObject();
System.out.println("******
Input:"+to.getFileInput());
System.out.println("Now size
a:"+testList.size());
if(testList.size()>0)
{
System.out.println("First
value:"+((TestTO)testList.get(0)).getFileInput());
}
testList.add(to);
System.out.println("Now Size
b:"+testList.size());
}
};
uploadForm.add(new TextArea("fileNotes"));
uploadForm.add(new TextField("fileInput"));
add(uploadForm);
}
private class TestTO implements Serializable{
private static final long serialVersionUID = 1L;
private String fileID;
private String fileNotes;
private String fileInput;
public TestTO(){}
public String getFileID() {
return fileID;
}
public void setFileID(String fileID) {
this.fileID = fileID;
}
public String getFileNotes() {
return fileNotes;
}
public void setFileNotes(String fileNotes) {
this.fileNotes = fileNotes;
}
public String getFileInput() {
return fileInput;
}
public void setFileInput(String fileInput) {
this.fileInput = fileInput;
}
}
}
and the html code:
<?xml version="1.0" encoding="UTF-8"?>
File
Note
File
Notes
Del
(file)
(notes)
img/delete.gif
*******************
when execute the code, the console show:
****** Input:1
Now size a:0
Now Size b:1
to.getFileInput(0:1
****** Input:2
Now size a:1
First value:2
Now Size b:2
to.getFileInput(0:2
to.getFileInput(0:2
I first input 1 and then input 2 ,but the two value all become 2,why? Could
anyone help me to solve this question?
http://www.nabble.com/file/p12569419/test2.jpg
--
View this message in context:
http://www.nabble.com/Help-%21-CompoundPropertyMode-and-ArrayList-Question-tf4405830.html#a12569419
Sent from the Wicket - Dev mailing list archive at Nabble.com.