Reputation: 1164
I am very new to struts and the application is using struts , and every time I submit the form the old values are submitted until and unless I change the values by selecting different options from drop down or I go to other tab and come back again to the same tab then in this case the values are resetting..
In my scenario what I want to achieve is to reset some of the values after they executed once.on the basis of those values I have to search some data and show it on the form, if I don't remove this value then it .
This is my execute method :
public class ListTerminalDevicesAction extends BaseQueryAction {
private RetailerService retailerService;
private DataBinder<OmposTerminalQuery> dataBinder;
private TerminalDeviceService terminalDeviceService;
private ImportCSVService importCSVService;
@Inject
public void setImportCSVService(ImportCSVService importCSVService) {
this.importCSVService = importCSVService;
}
@Inject
public void setRetailerService(final RetailerService retailerService) {
this.retailerService = retailerService;
}
@Inject
public void setTerminalDeviceService(final TerminalDeviceService terminalDeviceService) {
this.terminalDeviceService = terminalDeviceService;
}
@Inject
private DataBinder<OmposTerminalQuery> getDataBinder() {
if (dataBinder == null) {
final BeanBinder<OmposTerminalQuery> binder = BeanBinder.instance(OmposTerminalQuery.class);
binder.registerBinder("pageParameters", DataBinderHelper.pageBinder());
binder.registerBinder("retailer", PropertyBinder.instance(OmposRetailer.class, "retailer"));
binder.registerBinder("branch", PropertyBinder.instance(OmposBranch.class, "branch"));
binder.registerBinder("store", PropertyBinder.instance(OmposStore.class, "store"));
binder.registerBinder("terminalId", PropertyBinder.instance(String.class, "terminalId"));
binder.registerBinder("terminalSearchByTid",
PropertyBinder.instance(String.class, "terminalSearchByTid"));
dataBinder = binder;
}
return dataBinder;
}
@Override
protected void executeQuery(ActionContext context, QueryParameters queryParameters) {
final OmposTerminalQuery query = (OmposTerminalQuery) queryParameters;
query.setResultType(ResultType.PAGE);
// List<OmposRetailer> retailerList = retailerService.searchRetailers();
// context.getRequest().setAttribute("retailers", retailerList);
// if (query.getRetailer() != null) {
// OmposBranchQuery branchQuery = new OmposBranchQuery();
// branchQuery.setOmposRetailer(query.getRetailer());
// List<OmposBranch> branchList = retailerService.searchBranchByRetailer(branchQuery);
// context.getRequest().setAttribute("branches", branchList);
// if (query.getBranch() != null) {
// OmposStoreQuery storeQuery = new OmposStoreQuery();
// storeQuery.setOmposBranch(query.getBranch());
// List<OmposStore> storeList = retailerService.searchStore(storeQuery);
List<OmposStore> storeList = retailerService.searchStores();
context.getRequest().setAttribute("stores", storeList);
if (query.getStore() != null) {
ListTerminalDevicesForm form = context.getForm();
final FormFile uploadTerminal = form.getUploadTerminal();
if (uploadTerminal != null && uploadTerminal.getFileSize() != 0) {
try {
ImportCSVDTO uploadDtoForTerminal = new ImportCSVDTO();
// uploadDtoForTerminal.setRetailer(query.getRetailer());
// uploadDtoForTerminal.setBranch(query.getBranch());
uploadDtoForTerminal.setStore(query.getStore());
int records = importCSVService.importCSV(TMSEntity.TERMINAL, uploadDtoForTerminal,
uploadTerminal.getInputStream());
if (records > 0) {
context.getRequest().setAttribute("uploadMsgTerminal", records);
}
} catch (final UnknownColumnException | IOException e) {
// context.sendError("general.error.csv.unknownColumn",
// e.getColumn());
} finally {
uploadTerminal.destroy();
}
}
OmposTerminalQuery terminalQuery = new OmposTerminalQuery();
List<OmposTerminal> terminalList = null;
if (query.getStore() != null && query.getTerminalSearchByTid() != null) {
terminalQuery.setTerminalSearchByTid(query.getTerminalSearchByTid());
terminalQuery.setStore(query.getStore());
terminalList = terminalDeviceService.searchTerminalByTidAndStoreId(terminalQuery);
} else {
terminalQuery.setStore(query.getStore());
terminalList = terminalDeviceService.searchByStore(terminalQuery);
}
context.getRequest().setAttribute("terminals", terminalList);
if (query.getTerminalId() != null) {
OmposTerminal omposTerminal = new OmposTerminal();
omposTerminal.setTerminalId(query.getTerminalId());
OmposDeviceQuery deviceQuery = new OmposDeviceQuery();
deviceQuery.setOmposTerminal(omposTerminal);
final FormFile uploadDevice = form.getUploadDevice();
if (uploadDevice != null && uploadDevice.getFileSize() != 0) {
try {
ImportCSVDTO uploadDtoForDevice = new ImportCSVDTO();
uploadDtoForDevice.setRetailer(query.getRetailer());
uploadDtoForDevice.setBranch(query.getBranch());
uploadDtoForDevice.setStore(query.getStore());
uploadDtoForDevice.setTerminal(new OmposTerminal(null, query.getTerminalId(), null));
int records = importCSVService.importCSV(TMSEntity.DEVICE, uploadDtoForDevice,
uploadDevice.getInputStream());
if (records > 0) {
context.getRequest().setAttribute("uploadMsgDevice", records);
}
} catch (final UnknownColumnException | IOException e) {
// context.sendError("general.error.csv.unknownColumn",
// e.getColumn());
} finally {
uploadDevice.destroy();
}
}
context.getRequest().setAttribute("terminalId", query.getTerminalId());
List<OmposDevice> deviceList = terminalDeviceService.searchByTerminal(deviceQuery);
context.getRequest().setAttribute("devices", deviceList);
}
}
// }
// }
}
@Override
protected QueryParameters prepareForm(ActionContext context) {
final ListTerminalDevicesForm form = context.getForm();
final OmposTerminalQuery query = getDataBinder().readFromString(form.getQuery());
return query;
}
@Override
protected boolean willExecuteQuery(final ActionContext context,
final QueryParameters queryParameters) throws Exception {
return true;
}
}
I have to reset "terminalSearchByTid" field after the execution.
Upvotes: 3
Views: 942