2

私が抱えている問題は、リスト オブジェクト (productsEntitled) を持つ複数選択データ グリッド列を作成しようとしていることです。

ユーザーがレコードの [編集] をクリックしたときに、buildSelect カスタム関数を提供して [編集] ダイアログ ボックスに入力することで、製品が適切に表示されるようにしました。

グリッドに複数選択のある列がある場合<sjg:gridColumn name="productsEntitledListModel、保存機能が機能せず、保存されません。ブラウザ コンソールにも Java コンソールにもエラーは表示されません。

問題が何であるかを見つけることができないので、どんな助けも感謝します.ショーケースjar全体を逆コンパイルしましたが、この問題に役立つものは何もありません.

私のモデルは次のようになります。

@Entity
@Table ( name = "USERS")
public class User {

    private Long id;
    private String name;
    private String username;
    private String password;
    private String sourceIp;
    private Device device;
    private List<Product> productsEntitled;

これはjspページの私のグリッドです:

<s:url id="remoteurl" action="loadUsersJson"/>
    <s:url id="editurl" action="editGridUserEntry"/>
    <s:url id="selectproductsurl" action="loadProductsJson"/>


    <sjg:grid gridModel="users"  
              id="gridUsers"
              dataType="json" 
              width="1150"
              href="%{remoteurl}"
              draggable="true"
              pager="true" 
              resizable="true"
              navigatorAddOptions="{height:525, width:425, readAfterSubmit:true, draggable:true, resizable:true}"
              navigatorEditOptions="{height:525, width:425, reloadAfterSubmit:true, draggable:true, resizable:true}"
              navigatorDeleteOptions="{height:200, width:200, reloadAfterSubmit:true, draggable:true, resizable:true}"
              editurl="%{editurl}"
              navigator="true"
              navigatorEdit="true"
              navigatorAdd="true"
              navigatorView="true"
              navigatorDelete="true"
              rowList="10,15,20"
              rowNum="15"
              multiselect="false"
              onSelectRowTopics="rowselect">

        <sjg:gridColumn name="id" editable="true" index="id" hidden="true" key="true" title="ID"/>
        <sjg:gridColumn name="name" index="name" editable="true" edittype="text" title="NAME"/>
        <sjg:gridColumn name="sourceIp" index="sourceIp" editable="true" edittype="text" title="SOURCE IP"/>
        <sjg:gridColumn name="username" index="username" editable="true" edittype="text" title="USERNAME"/>
        <sjg:gridColumn name="password" index="password" editable="true" edittype="password" title="PASSWORD"/>
        <sjg:gridColumn name="role" index="role" editable="true" edittype="select" editoptions="{value:'Admin:Admin;User:User;'}" title="ROLE"/>

        <sjg:gridColumn name="deviceId" jsonmap="device.id" key="true" hidden="true" editable="text" title="DEVICE ID"/> 
        <sjg:gridColumn name="deviceIp" jsonmap="device.ip" editable="true" edittype="text" title="DEVICE IP"/>

        <sjg:gridColumn name="productsEntitledListModel"  
                        width="300"
                        editable="true" 
                        edittype="select"
                        editoptions="{dataUrl: '%{selectproductsurl}', multiple:true, buildSelect:customBuildSelect}"
                        title="PRODUCTS"/>

    </sjg:grid>

これらは私のアクションクラスです:

グリッドを表示する:

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.interceptor.ServletRequestAware;

import com.opensymphony.xwork2.ActionSupport;


public class AdminAction extends ActionSupport implements ServletRequestAware {

    private static final long serialVersionUID = -1090720652366248768L;
    private static final Log logger = LogFactory.getLog(AdminAction.class);

    private HttpServletRequest request;
    private AuthenticationTicket ticket;
    private AdminService adminService;
    private List<User> users;
    private List<Product> products;
    //private List<String>productsAllList;
    private String userId;

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public List<Product> getProducts() {
        return products;
    }

    public void setProducts(List<Product> products) {
        this.products = products;
    }

    public AuthenticationTicket getTicket() {
        return ticket;
    }

    public List<User> getUsers() {
        return users;
    }

    public void setUsers(List<User> users) {
        this.users = users;
    }

    public void setTicket(AuthenticationTicket ticket) {
        this.ticket = ticket;
    }

    @Override
    public void setServletRequest(HttpServletRequest request) {

        this.request = request;

    }

    public String redirectUsersTab() {
        return "users";
    }

    public String redirectProductsTab() {
        return "products";
    }

    private void initAdminService () {

        logger.debug("initAdminService()...");

        if (adminService == null) {
            adminService = (AdminService)ServiceFinder.getContext(request).getBean("adminService");
        }

    }

    public String loadUsersJson() {

        initAdminService();

        this.users = adminService.getUsersAll();

        return "success";
    }

    public String loadProductsJson() {

        initAdminService();

        this.products = adminService.getProductsAll();

        return "success";
    }

    //TODO: clean up
    public String getAllProductsList() {

        logger.debug("testParam, userId: " + this.userId);

        initAdminService();


        List<Product> temp = adminService.getProductsAll();

        if (userId != null) {

            User userTemp = new User();
            userTemp.setId(new Long(userId));

            List<Product> prodEntitled = adminService.getProductsByUser(userTemp);

            logger.debug("Products entitled: " + prodEntitled);
        }

        //TODO: merge prod and prod entitled to Model to populate the grid

        products = temp;
        /*
        if (temp != null && temp.size() > 0) {

            this.productsAllList = new ArrayList<String>();

            for (Product p : temp) {
                this.productsAllList.add(p.getName());
            }
        }
        */

        //logger.debug("this.productsAllList: " + this.productsAllList);


        return "success";
    }

}

グリッドを編集するクラス:

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.interceptor.ServletRequestAware;

import com.opensymphony.xwork2.ActionSupport;


public class EditUsersGridAction extends ActionSupport implements ServletRequestAware {

    private static final Log logger = LogFactory.getLog(EditUsersGridAction.class);
    private static final long serialVersionUID = -5485382508029951644L;

    private HttpServletRequest request;

    private AdminService adminService;
    private String oper = "";
    private Long id;
    private String name;
    private String sourceIp;
    private String password;
    private String username;
    private Long deviceId;
    private String deviceIp;
    private String devicePortDescription;
    private String devicePortLayer;
    private String deviceType;
    private List<Product>productsEntitled;
    private List<GridColumnListModel> productsEntitledListModel;
    private List<Product>productsAvailable;


    public List<GridColumnListModel> getProductsEntitledListModel() {

        try {

            if (productsEntitled != null && productsEntitled.size() > 0) {

                productsEntitledListModel = new ArrayList<EditUsersGridAction.GridColumnListModel>();

                for (Product p : productsEntitled) {

                    GridColumnListModel tmp = new GridColumnListModel();

                    tmp.setName(p.getName());
                    tmp.setValue(p);

                    productsEntitledListModel.add(tmp);
                }

                return this.productsEntitledListModel;
            }else {
                return null;
            }

        } catch (Exception ex) {
            logger.error("Exception in getProductsEntitledString", ex);
            return null;
        }
    }

    public void setProductsEntitledListModel(List<GridColumnListModel> productsEntitledListModel) {
        this.productsEntitledListModel = productsEntitledListModel;
    }

    public Long getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(Long deviceId) {
        this.deviceId = deviceId;
    }

    public String getDeviceIp() {
        return deviceIp;
    }

    public void setDeviceIp(String deviceIp) {
        this.deviceIp = deviceIp;
    }

    public String getDevicePortDescription() {
        return devicePortDescription;
    }

    public void setDevicePortDescription(String devicePortDescription) {
        this.devicePortDescription = devicePortDescription;
    }

    public String getDevicePortLayer() {
        return devicePortLayer;
    }

    public void setDevicePortLayer(String devicePortLayer) {
        this.devicePortLayer = devicePortLayer;
    }

    public String getDeviceType() {
        return deviceType;
    }

    public void setDeviceType(String deviceType) {
        this.deviceType = deviceType;
    }

    public String getOper() {
        return oper;
    }

    public void setOper(String oper) {
        this.oper = oper;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSourceIp() {
        return sourceIp;
    }

    public void setSourceIp(String sourceIp) {
        this.sourceIp = sourceIp;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public List<Product> getProductsEntitled() {
        return productsEntitled;
    }

    public void setProductsEntitled(List<Product> productsEntitled) {
        this.productsEntitled = productsEntitled;
    }

    public List<Product> getProductsAvailable() {
        return productsAvailable;
    }

    public void setProductsAvailable(List<Product> productsAvailable) {
        this.productsAvailable = productsAvailable;
    }

    public HttpServletRequest getRequest() {
        return request;
    }

    public void setRequest(HttpServletRequest request) {
        this.request = request;
    }

    @Override
    public void setServletRequest(HttpServletRequest request) {
        this.request = request;

    }

    private void initAdminService () {

        logger.debug("initAdminService()...");

        if (adminService == null) {
            adminService = (AdminService)ServiceFinder.getContext(request).getBean("adminService");
        }

    }

    public String execute() throws Exception {

        logger.debug("#### IN EditGridUsersAction ###");

        initAdminService();

        productsAvailable = adminService.getProductsAll();

        User user = new User();

        user.setName(name);
        user.setPassword(password);
        user.setUsername(username);
        user.setSourceIp(sourceIp);

        Device device = new Device();

        device.setId(deviceId);
        device.setIp(deviceIp);
        device.setPortDescription(devicePortDescription);
        device.setType(deviceType);

        user.setDevice(device);

        if (id != null) {
            user.setId(id);
        }

        if (oper.equalsIgnoreCase("add")) {

            logger.debug("products selected");
            //user.setProductsEntitled(adminService.getProductsAll());
            adminService.addUser(user);

        } else if ( oper.equalsIgnoreCase("edit")) {

            //TODO: convert model to products and add to user
            logger.debug("now in edit");

            List<Product> tempProd = new ArrayList<Product>();

            for (GridColumnListModel gridColModel : productsEntitledListModel) { 
                tempProd.add(gridColModel.getValue());
            }

            user.setProductsEntitled(tempProd);
            adminService.updateUser(user);

            //return "input";

        }else if (oper.equalsIgnoreCase("del")) {
            logger.debug("in delete");
            adminService.deleteUser(user);
        }

        return "success";
    }

    public class GridColumnListModel {

        private String name;
        private Product value;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Product getValue() {
            return value;
        }

        public void setValue(Product value) {
            this.value = value;
        }


    }

}
4

0 に答える 0