Skip to content

Commit

Permalink
GGW-369: Resolve project saving ajax issue
Browse files Browse the repository at this point in the history
  • Loading branch information
brianbrix committed Nov 6, 2024
1 parent 18e77d4 commit f6b7fb5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</td>
<td colspan="5">
<form wicket:id="structuresImportForm">
<!-- <input type="file" wicket:id="fileUpload">-->
<span class="upfile" wicket:id="fileUpload" />
<button type="submit" id="importStructures" wicket:id="importStructures">Import Structures</button>
</form>
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.wicket.request.resource.IResource;
import org.apache.wicket.request.resource.ResourceReference;
import org.apache.wicket.util.lang.Bytes;
import org.apache.wicket.util.upload.FileItem;
import org.dgfoundation.amp.onepager.OnePagerUtil;
import org.dgfoundation.amp.onepager.components.ListEditorRemoveButton;
import org.dgfoundation.amp.onepager.components.ListItem;
Expand All @@ -46,6 +47,7 @@
import org.dgfoundation.amp.onepager.components.fields.AmpTextAreaFieldPanel;
import org.dgfoundation.amp.onepager.components.fields.AmpTextFieldPanel;
import org.dgfoundation.amp.onepager.components.fields.LatAndLongValidator;
import org.dgfoundation.amp.onepager.components.upload.FileUploadPanel;
import org.dgfoundation.amp.onepager.helper.structure.ColorData;
import org.dgfoundation.amp.onepager.helper.structure.CoordinateData;
import org.dgfoundation.amp.onepager.helper.structure.MapData;
Expand Down Expand Up @@ -334,49 +336,54 @@ public void onClick(AjaxRequestTarget target) {

// final FileUploadField fileUploadField = new FileUploadField("fileUpload");
// fileUploadField.setOutputMarkupId(true);
final Model<FileItem> fileItemModel = new Model<FileItem>();

FileUploadPanel fileUpload = new FileUploadPanel("fileUpload",String.valueOf(am.getObject().getAmpActivityId()), fileItemModel);



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

@Override
protected void onSubmit() {
// FileUpload upload = new FileUploadField("fileUpload").getFileUpload();
// if (upload == null) {
// logger.info("No file uploaded");
// } else {
// logger.info("File-Name: " + upload.getClientFileName() + " File-Size: " +
// Bytes.bytes(upload.getSize()));
// try {
// XSSFWorkbook workbook = new XSSFWorkbook(upload.getInputStream());
// XSSFSheet sheet = workbook.getSheetAt(0);
// Iterator<Row> rowIterator = sheet.iterator();
// rowIterator.next();
//
// while (rowIterator.hasNext()) {
// XSSFRow row = (XSSFRow) rowIterator.next();
// String title = getStringValueFromCell(row.getCell(0));
// String description = getStringValueFromCell(row.getCell(1));
// String latitude = getStringValueFromCell(row.getCell(2));
// String longitude = getStringValueFromCell(row.getCell(3));
//
// AmpStructure stru = new AmpStructure();
// stru.setTitle(title);
// stru.setDescription(description);
// stru.setLatitude(latitude);
// stru.setLongitude(longitude);
// list.addItem(stru);
// list.goToLastPage();
// }
// } catch (IOException e) {
// throw new RuntimeException(e);
// }
// }
FileUpload upload = new FileUpload(fileItemModel.getObject());
if (upload == null) {
logger.info("No file uploaded");
} else {
logger.info("File-Name: " + upload.getClientFileName() + " File-Size: " +
Bytes.bytes(upload.getSize()));
try {
XSSFWorkbook workbook = new XSSFWorkbook(upload.getInputStream());
XSSFSheet sheet = workbook.getSheetAt(0);
Iterator<Row> rowIterator = sheet.iterator();
rowIterator.next();

while (rowIterator.hasNext()) {
XSSFRow row = (XSSFRow) rowIterator.next();
String title = getStringValueFromCell(row.getCell(0));
String description = getStringValueFromCell(row.getCell(1));
String latitude = getStringValueFromCell(row.getCell(2));
String longitude = getStringValueFromCell(row.getCell(3));

AmpStructure stru = new AmpStructure();
stru.setTitle(title);
stru.setDescription(description);
stru.setLatitude(latitude);
stru.setLongitude(longitude);
list.addItem(stru);
list.goToLastPage();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
};

// form.setMultiPart(true);
// form.setMaxSize(Bytes.megabytes(10));
// form.add(fileUploadField);
form.setMultiPart(true);
form.setMaxSize(Bytes.megabytes(10));
form.add(fileUpload);

Button importStructures = new Button("importStructures");
importStructures.setOutputMarkupId(true);
Expand Down

0 comments on commit f6b7fb5

Please sign in to comment.