Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package actions;
- import admin.dao.service.SharableService;
- import admin.dao.service.ZoneService;
- import com.opensymphony.xwork2.ActionContext;
- import com.opensymphony.xwork2.ActionSupport;
- import com.opensymphony.xwork2.ModelDriven;
- import com.opensymphony.xwork2.Preparable;
- import com.opensymphony.xwork2.ValidationAware;
- import com.opensymphony.xwork2.validator.annotations.FieldExpressionValidator;
- import com.opensymphony.xwork2.validator.annotations.RequiredFieldValidator;
- import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
- import com.opensymphony.xwork2.validator.annotations.StringLengthFieldValidator;
- import com.opensymphony.xwork2.validator.annotations.Validations;
- import com.opensymphony.xwork2.validator.annotations.ValidatorType;
- import java.io.Serializable;
- import java.math.BigDecimal;
- import java.util.ArrayList;
- import java.util.List;
- import model.Transporter;
- import model.ZoneTable;
- import org.apache.struts2.convention.annotation.Action;
- import org.apache.struts2.convention.annotation.InterceptorRef;
- import org.apache.struts2.convention.annotation.Namespace;
- import org.apache.struts2.convention.annotation.ParentPackage;
- import org.apache.struts2.convention.annotation.Result;
- import org.apache.struts2.convention.annotation.ResultPath;
- import org.springframework.beans.factory.annotation.Autowired;
- import pagination.Paging;
- @Namespace("/admin_side")
- @ResultPath("/WEB-INF/content")
- @ParentPackage(value="default")
- public final class ZoneAction extends ActionSupport implements Serializable, ValidationAware, Preparable, ModelDriven<ZoneTable>
- {
- @Autowired
- private final transient ZoneService zoneService=null;
- @Autowired
- private final transient SharableService sharableService=null;
- private static final long serialVersionUID = 1L;
- private int pageSize=5;
- private Long id;
- private Boolean deleteOneRow;
- private Boolean deleteMultipleRows;
- private ZoneTable entity=new ZoneTable();
- private List<ZoneTable>zones=new ArrayList<ZoneTable>();
- private String message;
- private List<Long>chk;
- private Long deleteId;
- private Long transporterId;
- private List<Transporter> transporters;
- private Transporter transporter;
- private Long begin;
- private Long end;
- private Long currentPage=1L;
- private Long rowCount;
- private Long totalPages;
- private Integer status;
- public int getPageSize() {
- return pageSize;
- }
- public void setPageSize(int pageSize) {
- this.pageSize = pageSize;
- }
- public Long getId() {
- return id;
- }
- public void setId(Long id) {
- this.id = id;
- }
- public Boolean getDeleteOneRow() {
- return deleteOneRow;
- }
- public void setDeleteOneRow(Boolean deleteOneRow) {
- this.deleteOneRow = deleteOneRow;
- }
- public Boolean getDeleteMultipleRows() {
- return deleteMultipleRows;
- }
- @RequiredFieldValidator(type= ValidatorType.FIELD, key="delete.multiple.confirm")
- public void setDeleteMultipleRows(Boolean deleteMultipleRows) {
- this.deleteMultipleRows = deleteMultipleRows;
- }
- public String getMessage() {
- return message;
- }
- public void setMessage(String message) {
- this.message = message;
- }
- public List<Long> getChk() {
- return chk;
- }
- public void setChk(List<Long> chk) {
- this.chk = chk;
- }
- public Long getDeleteId() {
- return deleteId;
- }
- public void setDeleteId(Long deleteId) {
- this.deleteId = deleteId;
- }
- public Transporter getTransporter() {
- return transporter;
- }
- public void setTransporter(Transporter transporter) {
- this.transporter = transporter;
- }
- public Long getBegin() {
- return begin;
- }
- public void setBegin(Long begin) {
- this.begin = begin;
- }
- public Long getEnd() {
- return end;
- }
- public List<Transporter> getTransporters() {
- transporters=sharableService.getTransporterList();
- return transporters;
- }
- /*public void setTransporters(List<Transporter> transporters) {
- this.transporters = transporters;
- }*/
- public void setEnd(Long end) {
- this.end = end;
- }
- public Long getCurrentPage() {
- return currentPage;
- }
- public void setCurrentPage(Long currentPage) {
- this.currentPage = currentPage;
- }
- public Long getRowCount() {
- return rowCount;
- }
- public void setRowCount(Long rowCount) {
- this.rowCount = rowCount;
- }
- public Long getTotalPages() {
- return totalPages;
- }
- public void setTotalPages(Long totalPages) {
- this.totalPages = totalPages;
- }
- public Integer getStatus() {
- return status;
- }
- public void setStatus(Integer status) {
- this.status = status;
- }
- public Long getTransporterId() {
- return transporterId;
- }
- public void setTransporterId(Long transporterId) {
- this.transporterId = transporterId;
- }
- private void paginate()
- {
- rowCount=zoneService.rowCount();
- Paging paging=new Paging(rowCount, pageSize, currentPage);
- totalPages=Paging.getTotalPages(rowCount, pageSize);
- if(currentPage>totalPages||currentPage<=0)
- {
- currentPage=1L;begin=1L;
- end=totalPages<10?paging.getEnd():10;
- }
- else
- {
- begin=paging.getBegin();
- end=paging.getEnd();
- }
- }
- @Action(value = "Zone",
- results = {
- @Result(name=ActionSupport.SUCCESS, location="Zone.jsp"),
- @Result(name = ActionSupport.INPUT, location = "Zone.jsp")},
- interceptorRefs={@InterceptorRef(value="modelParamsPrepareParamsStack", params={"params.acceptParamNames", "id, currentPage, rowCount, totalPages, message, status", "validation.validateAnnotatedMethodOnly", "true", "validation.excludeMethods", "load"})})
- public String load() throws Exception
- {
- return ActionSupport.SUCCESS;
- }
- @Action(value = "ZonePage",
- results = {@Result(name=ActionSupport.SUCCESS, location="Zone.jsp", params={"namespace", "/admin_side", "actionName", "Zone", "currentPage", "${currentPage}"}),
- @Result(name = ActionSupport.INPUT, location = "Zone.jsp")},
- interceptorRefs={@InterceptorRef(value="modelParamsPrepareParamsStack", params={"params.acceptParamNames", "currentPage", "validation.validateAnnotatedMethodOnly", "true"})})
- public String page()
- {
- return ActionSupport.SUCCESS;
- }
- @Validations(
- requiredFields={@RequiredFieldValidator(fieldName="selectedItem", type= ValidatorType.FIELD, key = "transporter.required")},
- requiredStrings={
- @RequiredStringValidator(fieldName="zoneName", type= ValidatorType.FIELD, key = "zone.name.required")},
- stringLengthFields={
- @StringLengthFieldValidator(fieldName="zoneName", type= ValidatorType.FIELD, minLength="2", maxLength="45", key="transporter.name.length", messageParams={"2", "45"})})
- @Action(value = "AddZone",
- results = {@Result(name=ActionSupport.SUCCESS, type="redirectAction", location="Zone.jsp", params={"namespace", "/admin_side", "actionName", "Zone", "currentPage", "${currentPage}", "message", "${message}", "id", "${id}", "status", "${status}"}),
- @Result(name = ActionSupport.INPUT, location = "Zone.jsp")},
- interceptorRefs={@InterceptorRef(value="modelParamsPrepareParamsStack", params={"params.acceptParamNames", "id, zoneId, zoneName, (\\[1\\]\\.)*transporterId, currentPage, rowCount, totalPages, status", "validation.validateAnnotatedMethodOnly", "true"})})
- public String insert()
- {
- System.out.println(transporter.getTransporterId()+" : "+transporter.getTransporterName()+" : "+transporter.getTransporterWebsite());
- if(entity.getTransporterId()==null)
- {
- setId(null);
- setStatus(1);
- setCurrentPage(1L);
- /*if(zoneService.insert(entity.getZoneName(), entity.getTransporterWebsite()))
- {
- setStatus(1);
- setMessage(getText("insert.success"));
- }
- else
- {
- setStatus(-1);
- setMessage(getText("insert.failed"));
- }*/
- }
- else
- {
- if(zoneService.update(entity))
- {
- setStatus(1);
- setMessage(getText("update.success", new String[]{String.valueOf(entity.getTransporterId())}));
- }
- else
- {
- setStatus(-1);
- setMessage(getText("update.failed", new String[]{String.valueOf(entity.getTransporterId())}));
- }
- }
- return ActionSupport.SUCCESS;
- }
- @Validations(
- requiredFields={
- @RequiredFieldValidator(fieldName="zoneId", type= ValidatorType.FIELD, key = "edit.warning"),
- @RequiredFieldValidator(fieldName="selectedItem", type= ValidatorType.FIELD, key = "dropbox.required"),
- @RequiredFieldValidator(fieldName="id", type= ValidatorType.FIELD, key = "delete.id.missing")})
- @Action(value = "EditZone",
- results = {
- @Result(name=ActionSupport.SUCCESS, location="Zone.jsp"),
- @Result(name = ActionSupport.INPUT, location = "Zone.jsp")},
- interceptorRefs={
- @InterceptorRef(value="modelParamsPrepareParamsStack", params={"params.acceptParamNames", "id, selectedItem, zoneId, zoneName, currentPage", "validation.validateAnnotatedMethodOnly", "true"})})
- public String edit()
- {
- return ActionSupport.SUCCESS;
- }
- @Validations(
- requiredFields={
- @RequiredFieldValidator(fieldName="deleteOneRow", type= ValidatorType.FIELD, shortCircuit=true, key="delete.row.reject"),
- @RequiredFieldValidator(fieldName="deleteId", type= ValidatorType.FIELD, shortCircuit=true, key="delete.id.missing")},
- fieldExpressions={@FieldExpressionValidator(fieldName="deleteOneRow", expression="deleteOneRow==true", shortCircuit=true, key="delete.row.reject")})
- @Action(value = "DeleteTransporter",
- results = {
- @Result(name=ActionSupport.SUCCESS, type="redirectAction", location="Transporter.action", params={"currentPage", "${currentPage}", "message", "${message}", "status", "${status}"}),
- @Result(name = ActionSupport.INPUT, location = "Zone.jsp")},
- interceptorRefs={
- @InterceptorRef(value="modelParamsPrepareParamsStack", params={"params.acceptParamNames", "deleteId, deleteOneRow, currentPage, status", "validation.validateAnnotatedMethodOnly", "true"})})
- public String deleteSingleRow()
- {
- if(zoneService.delete(deleteId))
- {
- rowCount--;
- currentPage=Paging.delete(rowCount, pageSize, currentPage);
- setMessage(getText("delete.success", new String[]{String.valueOf(deleteId)}));
- setStatus(1);
- }
- else
- {
- setStatus(-1);
- setMessage(getText("delete.failed", new String[]{String.valueOf(deleteId)}));
- }
- return ActionSupport.SUCCESS;
- }
- @Validations(
- requiredFields={@RequiredFieldValidator(type= ValidatorType.FIELD, fieldName="chk", key="delete.multiple.alert"),
- @RequiredFieldValidator(type= ValidatorType.FIELD, fieldName="deleteMultipleRows", key="delete.row.reject")},
- fieldExpressions={
- @FieldExpressionValidator(fieldName="deleteMultipleRows", expression="deleteMultipleRows==true", shortCircuit=true, key="delete.row.confirm")})
- @Action(value = "DeleteZones",
- results = {
- @Result(name=ActionSupport.SUCCESS, type="redirectAction", location="Zone.jsp", params={"namespace", "/admin_side", "actionName", "Transporter", "currentPage", "${currentPage}", "message", "${message}", "status", "${status}"}),
- @Result(name = ActionSupport.INPUT, location = "Zone.jsp")},
- interceptorRefs={
- @InterceptorRef(value="modelParamsPrepareParamsStack", params={"params.acceptParamNames", "chk, currentPage, rowCount, totalPages", "validation.validateAnnotatedMethodOnly", "true"})})
- public String deleteMultipleRows()
- {
- if(zoneService.delete(chk))
- {
- int size=chk.size();
- rowCount-=size;
- currentPage=Paging.delete(rowCount, pageSize, currentPage);
- setMessage(getText("delete.multiple.success", new String[]{String.valueOf(size)}));
- setStatus(1);
- }
- else
- {
- setMessage(getText("delete.multiple.failed"));
- setStatus(-1);
- }
- return ActionSupport.SUCCESS;
- }
- @Override
- public ZoneTable getModel()
- {
- return entity;
- }
- public List<ZoneTable> getZones()
- {
- return zones;
- }
- @Override
- public void validate()
- {
- if(hasErrors())
- {
- if(entity.getTransporterId()==null&&id!=null&&zoneService.checkId(id))
- {
- long currentRow=zoneService.getCurrentRow(id);
- long page=currentRow%pageSize;
- page=page==0?currentRow-pageSize:currentRow-currentRow%pageSize;
- zones= zoneService.getList((int)page, pageSize, null, null);
- currentPage=new BigDecimal(currentRow).divide(new BigDecimal(pageSize), 0, BigDecimal.ROUND_CEILING).longValue();
- }
- else
- {
- zones= zoneService.getList((int)(currentPage-1)*pageSize, pageSize, null, null);
- }
- paginate();
- //transporters=sharableService.getTransporterList();
- }
- }
- @Override
- public void prepare() throws Exception
- {
- String actionName = ActionContext.getContext().getName();
- if(actionName.equals("Zone")||actionName.equals("EditZone")||actionName.equals("ZonePage"))
- {
- if(entity.getTransporterId()==null&&id!=null&&zoneService.checkId(id))
- {
- long currentRow=zoneService.getCurrentRow(id);
- long page=currentRow%pageSize;
- page=page==0?currentRow-pageSize:currentRow-currentRow%pageSize;
- zones= zoneService.getList((int)page, pageSize, null, null);
- currentPage=new BigDecimal(currentRow).divide(new BigDecimal(pageSize), 0, BigDecimal.ROUND_CEILING).longValue();
- }
- else
- {
- zones= zoneService.getList((int)(currentPage-1)*pageSize, pageSize, null, null);
- }
- paginate();
- //transporters=sharableService.getTransporterList();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement