Skip to content

Commit f6b7fb5

Browse files
committed
GGW-369: Resolve project saving ajax issue
1 parent 18e77d4 commit f6b7fb5

2 files changed

Lines changed: 42 additions & 35 deletions

File tree

amp/WEB-INF/src/org/dgfoundation/amp/onepager/components/features/sections/AmpStructuresFormSectionFeature.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</td>
66
<td colspan="5">
77
<form wicket:id="structuresImportForm">
8-
<!-- <input type="file" wicket:id="fileUpload">-->
8+
<span class="upfile" wicket:id="fileUpload" />
99
<button type="submit" id="importStructures" wicket:id="importStructures">Import Structures</button>
1010
</form>
1111
</td>

amp/WEB-INF/src/org/dgfoundation/amp/onepager/components/features/sections/AmpStructuresFormSectionFeature.java

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.apache.wicket.request.resource.IResource;
3636
import org.apache.wicket.request.resource.ResourceReference;
3737
import org.apache.wicket.util.lang.Bytes;
38+
import org.apache.wicket.util.upload.FileItem;
3839
import org.dgfoundation.amp.onepager.OnePagerUtil;
3940
import org.dgfoundation.amp.onepager.components.ListEditorRemoveButton;
4041
import org.dgfoundation.amp.onepager.components.ListItem;
@@ -46,6 +47,7 @@
4647
import org.dgfoundation.amp.onepager.components.fields.AmpTextAreaFieldPanel;
4748
import org.dgfoundation.amp.onepager.components.fields.AmpTextFieldPanel;
4849
import org.dgfoundation.amp.onepager.components.fields.LatAndLongValidator;
50+
import org.dgfoundation.amp.onepager.components.upload.FileUploadPanel;
4951
import org.dgfoundation.amp.onepager.helper.structure.ColorData;
5052
import org.dgfoundation.amp.onepager.helper.structure.CoordinateData;
5153
import org.dgfoundation.amp.onepager.helper.structure.MapData;
@@ -334,49 +336,54 @@ public void onClick(AjaxRequestTarget target) {
334336

335337
// final FileUploadField fileUploadField = new FileUploadField("fileUpload");
336338
// fileUploadField.setOutputMarkupId(true);
339+
final Model<FileItem> fileItemModel = new Model<FileItem>();
340+
341+
FileUploadPanel fileUpload = new FileUploadPanel("fileUpload",String.valueOf(am.getObject().getAmpActivityId()), fileItemModel);
342+
343+
337344

338345
final Form<?> form = new Form<Void>("structuresImportForm") {
339346
private static final long serialVersionUID = 1L;
340347

341348
@Override
342349
protected void onSubmit() {
343-
// FileUpload upload = new FileUploadField("fileUpload").getFileUpload();
344-
// if (upload == null) {
345-
// logger.info("No file uploaded");
346-
// } else {
347-
// logger.info("File-Name: " + upload.getClientFileName() + " File-Size: " +
348-
// Bytes.bytes(upload.getSize()));
349-
// try {
350-
// XSSFWorkbook workbook = new XSSFWorkbook(upload.getInputStream());
351-
// XSSFSheet sheet = workbook.getSheetAt(0);
352-
// Iterator<Row> rowIterator = sheet.iterator();
353-
// rowIterator.next();
354-
//
355-
// while (rowIterator.hasNext()) {
356-
// XSSFRow row = (XSSFRow) rowIterator.next();
357-
// String title = getStringValueFromCell(row.getCell(0));
358-
// String description = getStringValueFromCell(row.getCell(1));
359-
// String latitude = getStringValueFromCell(row.getCell(2));
360-
// String longitude = getStringValueFromCell(row.getCell(3));
361-
//
362-
// AmpStructure stru = new AmpStructure();
363-
// stru.setTitle(title);
364-
// stru.setDescription(description);
365-
// stru.setLatitude(latitude);
366-
// stru.setLongitude(longitude);
367-
// list.addItem(stru);
368-
// list.goToLastPage();
369-
// }
370-
// } catch (IOException e) {
371-
// throw new RuntimeException(e);
372-
// }
373-
// }
350+
FileUpload upload = new FileUpload(fileItemModel.getObject());
351+
if (upload == null) {
352+
logger.info("No file uploaded");
353+
} else {
354+
logger.info("File-Name: " + upload.getClientFileName() + " File-Size: " +
355+
Bytes.bytes(upload.getSize()));
356+
try {
357+
XSSFWorkbook workbook = new XSSFWorkbook(upload.getInputStream());
358+
XSSFSheet sheet = workbook.getSheetAt(0);
359+
Iterator<Row> rowIterator = sheet.iterator();
360+
rowIterator.next();
361+
362+
while (rowIterator.hasNext()) {
363+
XSSFRow row = (XSSFRow) rowIterator.next();
364+
String title = getStringValueFromCell(row.getCell(0));
365+
String description = getStringValueFromCell(row.getCell(1));
366+
String latitude = getStringValueFromCell(row.getCell(2));
367+
String longitude = getStringValueFromCell(row.getCell(3));
368+
369+
AmpStructure stru = new AmpStructure();
370+
stru.setTitle(title);
371+
stru.setDescription(description);
372+
stru.setLatitude(latitude);
373+
stru.setLongitude(longitude);
374+
list.addItem(stru);
375+
list.goToLastPage();
376+
}
377+
} catch (IOException e) {
378+
throw new RuntimeException(e);
379+
}
380+
}
374381
}
375382
};
376383

377-
// form.setMultiPart(true);
378-
// form.setMaxSize(Bytes.megabytes(10));
379-
// form.add(fileUploadField);
384+
form.setMultiPart(true);
385+
form.setMaxSize(Bytes.megabytes(10));
386+
form.add(fileUpload);
380387

381388
Button importStructures = new Button("importStructures");
382389
importStructures.setOutputMarkupId(true);

0 commit comments

Comments
 (0)