【问题标题】:jTable jquery with struts2带有struts2的jTable jquery
【发布时间】:2015-04-07 00:57:44
【问题描述】:

我正在使用 Struts2 开发一个 jquery Jtable,因此,当我想添加新记录或更新现有记录并在显示的弹出窗口中输入新值时,这些值不会被 struts 操作恢复,并且新记录将全部添加空值。 这是我的 java 方法:

private String nom,identifiant;
private String prenom;
private String email;

// getter/setter...
public String create() throws IOException {
    record = new Student();

    record.setNom(this.getNom());
    record.setPrenom(this.getPrenom());
    record.setEmail(this.getEmail());
    record.setIdentifiant(getIdentifiant());
    try {
        // Create new record

        dao.ajout(record);
        result = "OK";

    } catch (Exception e) {
        result = "ERROR";
        message = e.getMessage();
        System.err.println(e.getMessage());
    }
    return Action.SUCCESS;  
}

这里是jquery代码:

$(document).ready(function () {

    $('#StudentTableContainer').jtable({
        title: 'Liste des agents pharmaciens',
        paging : true, //Enable paging
       pageSize : 3, //Set page size (default: 10)  
        actions: {
            listAction : 'afficheStudent',
            createAction : 'createAction',
            updateAction : 'updateAction',
            deleteAction : 'deleteAction'
        },
        fields: {
            id: {
                title:'id',
                key: true,
                list: true,

            },
            identifiant: {
                title: 'Identifiant',
                width: '20%',
                edit:true
            },
            nom: {
                title: 'Nom',
                width: '20%',
                edit:true
            },
            prenom: {
                title: 'Prenom',
                width: '30%',
                edit:true,
                create:true
            },
            email: {
                title: 'Email',
                width: '20%',
                edit: true,
                create:true
            }              
        }
    });
    $('#StudentTableContainer').jtable('load');
});

【问题讨论】:

  • 检查发送到服务器的内容。
  • 我做到了,但似乎无法将值从表单恢复到操作类以便保存在数据库中
  • 在浏览器中打开开发工具,选择网络选项卡,查看发送到服务器的内容。

标签: jquery struts2 row add jquery-jtable


【解决方案1】:

一个错误是字段 nom 没有 create : true 选项。

$(document).ready(function () {

    $('#StudentTableContainer').jtable({
        title: 'Liste des agents pharmaciens',
        paging : true, //Enable paging
       pageSize : 3, //Set page size (default: 10)  
        actions: {
            listAction : 'afficheStudent',
            createAction : 'createAction',
            updateAction : 'updateAction',
            deleteAction : 'deleteAction'
        },
        fields: {
            id: {
                title:'id',
                key: true,
                list: true,

            },
            identifiant: {
                title: 'Identifiant',
                width: '20%',
                edit:true
            },
            nom: {
                title: 'Nom',
                width: '20%',
                edit:true,
                create: true //this is one error
            },
            prenom: {
                title: 'Prenom',
                width: '30%',
                edit:true,
                create:true
            },
            email: {
                title: 'Email',
                width: '20%',
                edit: true,
                create:true
            }              
        }
    });
    $('#StudentTableContainer').jtable('load');
});

【讨论】:

  • 如果这不能完全解决你的问题,我可以再看一遍
猜你喜欢
  • 1970-01-01
  • 2013-10-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-17
  • 1970-01-01
  • 2012-12-18
  • 2010-12-24
相关资源
最近更新 更多