XPage Dojo Grid 可编辑单元格在调用 REST 服务 save() 方法时不保存值 [英] XPages Dojo Grid editable cell does not save value when REST Service save() method is called

查看:46
本文介绍了XPage Dojo Grid 可编辑单元格在调用 REST 服务 save() 方法时不保存值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用具有可编辑列的 Dojo 网格的 REST 服务.我可以双击单元格并更改值,但是,当我尝试保存更改时——在按钮中使用 REST 服务 save() 方法——更改不会保存.

I have a REST Service working with a Dojo Grid that has editable columns. I can double-click in the cell and change the value, however, when I attempt to save the changes -- using the REST Service save() method in a button -- the changes do not save.

我可以保存这个值的唯一方法是首先调用 REST 服务上的 revert() 方法——单击按钮中的 REST 服务 revert() 方法——然后对我需要的任何可编辑单元格进行更改并点击保存按钮.

The only way I can get this value to save is to call the revert() method on the REST service first -- clicking the REST Service revert() method in a button -- then make changes to whatever editable cell I need to and click the Save button.

代码如下:

<xe:restService id="rsVictims" pathInfo="gridDataVictims">
        <xe:this.service>
            <xe:viewItemFileService defaultColumns="true"
                viewName="InvoiceMPRVictims" contentType="application/json">
                <xe:this.keys><![CDATA[#{javascript:viewScope.get("mprKeysValue");}]]></xe:this.keys>
                <xe:this.databaseName><![CDATA[#{javascript:applicationScope.get("appConfig").keywords.appDataStore.join("!!")}]]></xe:this.databaseName>
            </xe:viewItemFileService>
        </xe:this.service>
    </xe:restService>

<xp:button value="Save Changes" id="button1">
                <xp:eventHandler event="onclick" submit="false">
                    <xp:this.script><![CDATA[// Save the changes...
rsVictims.save();]]></xp:this.script>
                </xp:eventHandler>
            </xp:button>
            <xp:button value="Cancel Changes" id="button2">
                <xp:eventHandler event="onclick" submit="false">
                    <xp:this.script><![CDATA[rsVictims.revert();]]></xp:this.script>
                </xp:eventHandler>
            </xp:button>
<xe:djxDataGrid id="djxDataGrid1" storeComponentId="rsVictims"
            autoHeight="90">

            <xe:djxDataGridColumn id="djxDataGridColumn1"
                label="Target" width="35px" field="victimTarget">
            </xe:djxDataGridColumn>
            <xe:djxDataGridColumn id="djxDataGridColumn2" label="Oct"
                width="35px" field="month_10" editable="true">
            </xe:djxDataGridColumn>
            <xe:djxDataGridColumn id="djxDataGridColumn3"
                label="Nov" width="35px" field="month_11" editable="true">
            </xe:djxDataGridColumn>
            <xe:djxDataGridColumn id="djxDataGridColumn4"
                label="Dec" width="35px" field="month_12" editable="true">
            </xe:djxDataGridColumn>
            <xe:djxDataGridColumn id="djxDataGridColumn5"
                label="Jan" width="35px" field="month_1" editable="true">
            </xe:djxDataGridColumn>
            <xe:djxDataGridColumn id="djxDataGridColumn6"
                label="Feb" width="35px" field="month_2" editable="true">
            </xe:djxDataGridColumn>
            <xe:djxDataGridColumn id="djxDataGridColumn7"
                label="Mar" width="35px" field="month_3" editable="true">
            </xe:djxDataGridColumn>
            <xe:djxDataGridColumn id="djxDataGridColumn8"
                label="Apr" width="35px" field="month_4" editable="true">
            </xe:djxDataGridColumn>
            <xe:djxDataGridColumn id="djxDataGridColumn9"
                label="May" width="35px" field="month_5" editable="true">
            </xe:djxDataGridColumn>
            <xe:djxDataGridColumn id="djxDataGridColumn10"
                label="June" width="35px" field="month_6" editable="true">
            </xe:djxDataGridColumn>
            <xe:djxDataGridColumn id="djxDataGridColumn11"
                label="July" width="35px" field="month_7" editable="true">
            </xe:djxDataGridColumn>
            <xe:djxDataGridColumn id="djxDataGridColumn12"
                label="Aug" width="35px" field="month_8" editable="true">
            </xe:djxDataGridColumn>
            <xe:djxDataGridColumn id="djxDataGridColumn15"
                label="Sept" width="35px" field="month_9" editable="true">
            </xe:djxDataGridColumn>
            <xe:djxDataGridColumn id="djxDataGridColumn13"
                label="Total" width="45px" field="victimTotal">
            </xe:djxDataGridColumn>
            <xe:djxDataGridColumn id="djxDataGridColumn14"
                width="200px" label="Description" field="$Desc">
            </xe:djxDataGridColumn>
        </xe:djxDataGrid>

我浏览了 Brad Balassastis 的优秀教程:http://xcellerant.net/2013/04/25/dojo-data-grid-11-editable-columns/

I went through Brad Balassastis' excellent tutorial: http://xcellerant.net/2013/04/25/dojo-data-grid-11-editiable-columns/

任何帮助都会很棒 - 谢谢!

Any help would be great -- thanks!

编辑/附加信息:

我们有一个 REST 服务和 Dojo DataGrid,它们不会在初始加载时保存对可编辑列的更改——这意味着 XPage 加载和更改已完成.保存更改的唯一方法是在调用 REST 服务的 close() 或 revert() 方法之后,然后调用 save() 方法.REST 服务指向同一服务器上的另一个数据库,并使用 keys 属性:

We have a REST Service and Dojo DataGrid that does not save the changes to editable columns on the initial load -- meaning the XPage loads and changes are made. The only way the changes are saved is after the close() or revert() method for the REST service is called, then the save() method is called. The REST Service is pointing to another database on the same server, and uses the keys property:

<xe:restService id="rsVictims" pathInfo="rsVictimsData">
<xe:this.service>
    <xe:viewItemFileService defaultColumns="true"
        viewName="InvoiceGridVictims" contentType="application/json"
        databaseName="voca\vocadatastore.nsf" keys="k28ts71zrjsw">
    </xe:viewItemFileService>
</xe:this.service>
</xe:restService>

这是数据网格:

<xe:djxDataGrid id="djxDataGrid1" storeComponentId="rsVictims"
    autoHeight="90">
    <xe:djxDataGridColumn id="djxDataGridColumn1"
        label="Target" width="35px" field="victimTarget">
    </xe:djxDataGridColumn>
    <xe:djxDataGridColumn id="djxDataGridColumn2"
        label="Oct" width="35px" field="month_10" editable="true">
    </xe:djxDataGridColumn>
</xe:djxDataGrid>

它是这样流动的:

使用 REST 服务和 DataGrid 打开 XPage

Open the XPage with the REST service and DataGrid

 <xp:button value="Save Changes" id="victimsSaveButton">
                <xp:eventHandler event="onclick" submit="false">
                    <xp:this.script><![CDATA[// Save the changes...
editedRows = [-1];
var args = {onError: function() {alert('error!');}};
rsVictims.save(args);

//Refresh the grid
rsVictims.close();
dijit.byId('#{id:djxDataGrid1}')._refresh();]]></xp:this.script>
                </xp:eventHandler>
            </xp:button>

DataGrid 已关闭、刷新,但未保存更改

DataGrid is closed, refreshed, but changes are NOT saved

我注意到在打开 XPage 时 DataGrid 加载了两次 -- 我在 Net 选项卡中看到这是 Firebug.在第一个 GET 中,它正确检索了网格——响应是正确的,JSON 格式正确,并且 start=0 和 count=25.

What I have noticed is that the DataGrid is loaded twice when the XPage is opened -- I see this is Firebug in the Net tab. On the first GET, it retrieves the grid correctly -- the Response is correct, the JSON is formatted correctly, and the start=0 with a count=25.

在第二次 GET 中,似乎丢失了网格——响应为空,JSON 项为空,start=25,count=25.我尝试将 REST 服务中的 start 属性设置为 0,但这没有任何作用.我也尝试将 count 属性设置为 500,但这也不能解决问题.

On the second GET, it seems to lose the grid -- the Response is empty, the JSON items is empty, and the start=25 with the count=25. I have tried setting the start property in the REST Service to 0, but that does not do anything. I have tried setting the count property to 500 as well, but that does not fix it either.

关于这一点的有趣事实是,当视图在当前数据库中移动时——因此不使用 REST 服务上的 databaseName 属性——保存按钮工作正常.此外,加载 DataGrid 时只有一个 GET,而指向同一服务器上另一个数据库中的视图时则没有两个 GET.我知道在寻找另一台服务器时会出现一些问题,但这些数据库位于同一台服务器上.

The interesting fact about this is, when the view is moved inside the current database -- so the databaseName property on the REST Service is not used -- the Save button works perfectly. Also, there is only one GET when loading the DataGrid, not two GETs when pointing to a view in another database on the same server. I know there are some issues when looking to another server, but these databases are on the same server.

提前致谢!

推荐答案

Dan,

我在当前项目中遇到了几乎相同的情况.我的工作很完美,所以我想我可以提供帮助.我假设您已经接受了上面 Per Lausten 的建议.如果不这样做,您将根本无法保存.

I have nearly an identical situation in my current project. I have mine working perfect so I think I can help. I assume that you already took Per Lausten's suggestion above. You wouldn't be able to save at all if you didn't.

您的代码和我的代码之间的区别在于我使用的是 xe:viewJSONService 而不是 xe:viewFileItemService.扩展库书籍说,如果您希望它可更新,则必须使用 viewFileItem,但事实并非如此.

The difference between your code and mine is that I am using a xe:viewJSONService instead of a xe:viewFileItemService. The extention library book says that you have to use the viewFileItem if you want it updatable, but this is NOT true.

我在 viewItemFileService 上遇到了麻烦,请参阅这篇博客文章了解我遇到的问题(http://notesspeak.blogspot.com/2013/07/going-with-extjs-grid-and-giving-up-on.html) 我几乎完全放弃了道场网格,但又回到了它,因为它适用于移动设备.

I had nothing but trouble with the viewItemFileService, see this blog post for the issues I had (http://notesspeak.blogspot.com/2013/07/going-with-extjs-grid-and-giving-up-on.html) I nearly gave up entirely on the dojo grid, but came back to it because it works on mobile.

使用 viewJSONService 就可以了.使用类别过滤器而不是键属性.对于您的类别有类似这样的代码:

Using the viewJSONService just works. Instead of a keys property, use the category filter. For you category have code similar to this:

var category:String = lineItemBean.getThisUNID();
if(category == null){
    return "show nothing"
} else {
    return lineItemBean.getThisUNID();
}
//prevents all records from being returned

你需要小心,因为如果类别为空,则返回所有记录,这可能是一个大问题或安全漏洞.在我的示例中,我从 bean 中提取,但您也可以将文档引用放在那里.

You need to be careful, because if the category is null, all records are returned, which could be a big problem or security hole. In my example, I pull from a bean, but you could put a document reference there as well.

这篇关于XPage Dojo Grid 可编辑单元格在调用 REST 服务 save() 方法时不保存值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆