Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jquery Grid getting row id not working when deleting #152

Open
tonymanello opened this issue Nov 30, 2017 · 0 comments
Open

Jquery Grid getting row id not working when deleting #152

tonymanello opened this issue Nov 30, 2017 · 0 comments

Comments

@tonymanello
Copy link

tonymanello commented Nov 30, 2017

Hi,

I have a rare issue with an editable grid, when selecting a row and clicking on edit button, I get the object id, however if I click on delete button I get a null id.

Struts2 version: 2.5.10.1
Struts2-jquery plugin version: 4.0.2

Edit JSP:

<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags"%>
<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Zones</title>
        <sj:head jqueryui="true" jquerytheme="darkness" />
        <script type="text/javascript">
            $.subscribe('rowselect', function (event, data) {
                $("#gridinfo").html('<p>Selected Zone: ' + event.originalEvent.id + '</p>');
            });
            $.subscribe('oneditsuccess', function (event, data) {
                var message = event.originalEvent.response.statusText;
                $("#gridinfo").html('<p>Status: ' + message + '</p>');
            });
        </script>
    </head>
    <body>
        <s:url var="remoteurl" action="gridZones"/>
        <s:url var="editurl" action="editZone"/>
        <sjg:grid
            id="gridedittable"
            caption="Zones"
            dataType="json"
            href="%{remoteurl}"
            pager="true"
            navigator="true"
            navigatorAddOptions="{height:280,reloadAfterSubmit:true}"
            navigatorEdit="true"
            navigatorEditOptions="{height:280,reloadAfterSubmit:true}"
            navigatorView="false"
            navigatorDelete="true"
            navigatorDeleteOptions="{height:280,reloadAfterSubmit:true}"
            navigatorInlineEditButtons="false"
            gridModel="gridModel"
            rowList="5,10,20,50,100"
            rowNum="10"
            rownumbers="true"
            editurl="%{editurl}"
            editinline="false"
            onSelectRowTopics="rowselect"
            onEditInlineSuccessTopics="oneditsuccess"
            viewrecords="true"
            width="958"
            shrinkToFit="false"
            gridview="true"
            >
            <sjg:gridColumn name="idZone" 
                            key="true"
                            index="idZone" 
                            editable="true"
                            hidden="true"
                            title="ID" 
                            width="40" 
                            formatter="integer"/>
            <sjg:gridColumn name="zoneName"
                            index="zoneName" 
                            title="Zone" 
                            width="300" 
                            editable="true"
                            edittype="text"/>
            <sjg:gridColumn name="zoneDeleted" 
                            index="zoneDeleted" 
                            title="Deleted" 
                            width="45"
                            hidden="true"/>
        </sjg:grid>
        <div id="gridinfo" class="ui-widget-content ui-corner-all"><p>Edit mode for row: </p></div>
    </body>
</html>

CRUD action:

public class crudZone extends ActionSupport implements SessionAware, UserAware {

    private static final long serialVersionUID = -2866084280614329570L;
    private static final Log log = LogFactory.getLog(crudZone.class);
    private ServiceImplemented userService;
    private User loggedUser;
    private Map session;

    private String oper = "edit";
    private Integer idZone;
    private String zoneName;
    private boolean zoneDeleted;

    public crudZone(ServiceImplemented userService) {
        this.userService = userService;
    }

    @Override
    public String execute() {
        Zone zone;
        try {
            if (oper.equalsIgnoreCase("add")) {
                log.debug("Add zone: " + zoneName);
                zone = new Zone();
                zone.setZoneName(zoneName);
                zone.setZoneDeleted(false);
                this.userService.newZone(zone);
            } else if (oper.equalsIgnoreCase("edit")) {
                log.debug("Edit zone: " + getZoneName() + "idZone:" + idZone);
                zone = (Zone) this.userService.getZoneByID(getIdZone());
                if (zone != null) {
                    zone.setZoneName(getZoneName());
                    this.userService.editZone(zone);
                }
            } else if (oper.equalsIgnoreCase("del")) {
                log.debug("Delete zone: " + getZoneName() + "idZone:" + idZone);
                zone = (Zone) this.userService.getZoneByID(getIdZone());
                if (zone != null) {
                    this.userService.deleteZone(zone);
                }
            }
        } catch (Exception exception) {
            addActionError("ERROR: something went wrong " + exception.getLocalizedMessage());
            return "error";
        }
        return "NONE";
    }

With edit buttton it works fine, but whit delete button it doesn't work at all because I get idZone with a null value.

Any hint?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant