是否可以在视图中进行数据绑定? [英] Is it possible to have data binding in the view?

查看:33
本文介绍了是否可以在视图中进行数据绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自这个帖子,感谢 Simon Delicata 的回答和评论.我可以保存从视图中获取选定的文档并另存为单独的文档.

From this post, thank you Simon Delicata's answer and comment. I can save get selected documents from a view and save as separate documents.

我对这种方法有疑问.如果我编辑文档,我点击链接将我重定向到编辑页面,编辑页面类似于以前的帖子的设计:顶部的组合框,带有复选框的视图(此视图用于选择),一个按钮,用于保存视图和组合框中的选择值.还有另一个视图将显示保存的值.

I have a question about this approach. If I edit the document, I click the link which will redirect me to the edit page, the edit page is similar to previous post's design: a combo box on the top, a view with check box (this view is used for selection), a button for save the selection values from the view and the combo box. Also there will another view which will display the saved values.

这里的代码,它可以保存为单独的文档,但它不能显示保存的值并在复选框中放置一个勾号"符号.

Here code and it can save as separate documents but it cannot show the saved value and put a "tick" symbol in the checkbox.

<xp:table id="table1a">
    <xp:tr>
        <xp:td id="table1">
            <xp:comboBox id="comboBox1"
                dojoType="dijit.form.ComboBox" style="width:250.0px"
                value="#{document1.Category}">
                <xp:selectItems id="selectItems3">
                    <xp:this.value><![CDATA[#{javascript:var SetFirstValueBlank = @Text("");
                    return SetFirstValueBlank;
                }]]></xp:this.value>
                </xp:selectItems>
                <xp:selectItems id="selectItems4">
                    <xp:this.value><![CDATA[#{javascript:@Unique(@DbColumn(@DbName(), "CategoryListView", 1));}]]></xp:this.value>
                </xp:selectItems>
                <xp:eventHandler event="onchange" submit="true"
                    refreshMode="partial" refreshId="table1a">
                </xp:eventHandler>
            </xp:comboBox>
            <xp:text escape="true" id="computedField1">
            </xp:text>
        </xp:td>
    </xp:tr>
    <xp:tr>
        <xp:td>
            <xp:viewPanel rows="10" id="viewPanel1" var="rowData">
                <xp:this.data>
                    <xp:dominoView var="view1"
                        viewName="hListView">
                    </xp:dominoView>
                </xp:this.data>
                <xp:viewColumn columnName="ItemName"
                    id="viewColumn1" style="background-color:rgb(255,255,255)"
                    showCheckbox="true">
                    <xp:viewColumnHeader value="Item Name"
                        id="viewColumnHeader1" rendered="false">
                    </xp:viewColumnHeader>
                </xp:viewColumn>
                <xp:this.facets>
                    <xp:pager partialRefresh="true"
                        layout="Previous Group Next" xp:key="footerPager" id="pager2">
                    </xp:pager>
                </xp:this.facets>
            </xp:viewPanel>
            <xp:br></xp:br>
            <xp:button value="Add" id="button1"
                style="height:35.0px">
                <xp:eventHandler event="onclick" submit="true"
                    refreshMode="complete">
                    <xp:this.action><![CDATA[#{javascript:var Category = getComponent("comboBox1").getValue();
                    var viewPanel=getComponent("viewPanel1");
                    var docIDArray=viewPanel.getSelectedIds();
                    var unidArray = new Array();
                    for(i=0; i < docIDArray.length; i++) {
                   var unid=database.getDocumentByID(docIDArray[i]).getUniversalID();
                      unidArray.push(unid);
                    }
                    viewScope.put("unidArray", @Implode(unidArray, ","));
                for(var i=0; i< unidArray.length;i++ )
                {
                    var mdoc = database.createDocument();
                    mdoc.appendItemValue("Form", "ItemForm");
                    mdoc.appendItemValue("ItemName",unidArray[i]);

                    if(mdoc.computeWithForm(false,false))
                    {       
                        mdoc.save(true, true);  
                        getComponent("computedField9").setValue("Record saved");        
                    }
                    else
                    {
                    }
                }
        }]]></xp:this.action>
                </xp:eventHandler>
            </xp:button>
            <xp:br></xp:br>
            <xp:br></xp:br>
            <xp:viewPanel rows="6" id="viewPanel2">                     
                    <xp:this.data>
                        <xp:dominoView var="view2" viewName="CategoryItemView">
                            <xp:this.categoryFilter><![CDATA[#{javascript:getComponent("comboBox1").getValue();}]]></xp:this.categoryFilter>
                        </xp:dominoView>
                    </xp:this.data>
                    <xp:this.rendered><![CDATA[#{javascript:var value = getComponent("comboBox1").getValue();
                    if(value =="" || value == null)
                    {
                        return false;
                    }
                    else
                    {
                        return true;
                    }}]]></xp:this.rendered><xp:viewColumn id="viewColumn4" columnName="Category" rendered="false">
                        <xp:this.facets>
                            <xp:viewColumnHeader xp:key="header" id="viewColumnHeader4" value="Category">
                            </xp:viewColumnHeader>
                        </xp:this.facets>
                    </xp:viewColumn>
                    <xp:viewColumn id="viewColumn3" columnName="$10">
                        <xp:this.facets>
                            <xp:viewColumnHeader xp:key="header" id="viewColumnHeader3" value="Category">
                            </xp:viewColumnHeader>
                        </xp:this.facets>
                    </xp:viewColumn>
                    <xp:viewColumn columnName="ItemName" id="viewColumn2">
                        <xp:viewColumnHeader value="Item" id="viewColumnHeader2">
                        </xp:viewColumnHeader>
                    </xp:viewColumn>
                    <xp:this.facets>
                        <xp:pager partialRefresh="true" layout="Previous Group Next" xp:key="footerPager" id="pager3">
                        </xp:pager>
                    </xp:this.facets></xp:viewPanel><xp:br></xp:br></xp:td>
                </xp:tr>
            </xp:table>

据我所知,假设有一个编辑框或一个组合框,如果我使用数据绑定绑定到一个字段并保存它,编辑框或组合框在编辑时可以显示保存的值.

So far as I know, suppose there a edit box or a combo box, if I use data binding to bind to a field and save it, the a edit box or a combo box can show the saved value when edit.

所以我想知道类似方法"是否适用于视图?我在互联网上搜索并没有太多关于它的信息.

So I would like to know can the "similar approach" applies to the view? I search on the Internet and not much information about it.

我单击视图并单击属性"选项卡中的数据",我注意到该视图确实具有绑定到表单字段的数据绑定.

I click the view and click Data in Properties tab, I notice the view does has data binding to bind to a form field.

因此可以在视图中进行数据绑定,以便在编辑时视图可以显示保存的值.谢谢.

Therefore is it possible to have data binding in the view so the view can show the saved value when edit. Thank you.

推荐答案

您不是绑定到文档,而是绑定到 dominoDocument 对象中的属性.dominoDocument 对象是数据库中底层文档的 Java 包装器,由于文档是可读写的,因此也将所有字段公开为可读写,允许将可编辑组件绑定到它们.如果编辑框绑定到只读属性,我怀疑它不会显示为可编辑.

You're not binding to a document, you're binding to properties in a dominoDocument object. The dominoDocument object is a Java wrapper for the underlying document in the database that, because the document is read-write also exposes all fields as read-write, allowing editable components to be bound to them. If an edit box was bound to a read only property, I suspect it would not show as editable.

dominoView 对象是底层视图的 Java 包装器,并返回 NotesXspViewEntry 对象的集合,即视图中的每一行.这些不是读写的(Notes Client 可编辑列不编辑视图条目,它们提供了一个可编辑区域,通过后端代码写入底层文档).您需要考虑绑定到视图中视图条目对应的文档".

The dominoView object is a Java wrapper for the underlying view, and returns a collection of NotesXspViewEntry objects i.e. each row in the view. Those aren't read-write (Notes Client editable columns don't edit the view entry, they give an editable area that writes to the underlying document via backend code). You need to think about binding to "documents corresponding to view entries in the view".

视图面板列可以包含组件,而不仅仅是映射到列值.视图面板是具有受限布局和设置的重复控件,因此它是相同的方法.在 ViewPanel 上设置 var 属性 - 这是一个用于获取当前 NotesXspViewEntry 句柄的变量.不能拖放到一列,如果我没记错的话,需要把组件的代码粘贴到相关的地方.

View Panel columns can contain components instead of just mapping to column values. A View Panel is a repeat control with restricted layout and settings, so it's the same approach. Set the var property on the ViewPanel - this is a variable to get a handle on the current NotesXspViewEntry. You can't drag and drop into a column, if I remember correctly, you need to paste the code for the component into the relevant place.

如果您希望它可编辑,则需要一个 dominoDocument 数据源.或者,重现 Notes Client 可编辑视图列方法的方法,绑定到临时变量(例如 requestScope 属性)并在流程完成时更新后端文档.另一种方法是启动一个对话框,传递当前行的 UNID,然后进行编辑.另一种方法是使用 XPage 扩展库中的就地表单.

If you want it editable, you'll need a dominoDocument datasource. Alternatively, reproduce the approach of Notes Client editable view column approach, bind to a temporary variable (e.g. requestScope property) and update the backend document on completion of the process. Another approach is to launch a dialog, passing the current row's UNID, and edit. Yet another approach is to use the In Place Form from XPages Extension Library.

这是来自 IBM Connect 2013 的演示和演示,我在其中做了一些类似的事情来使列可编辑 http://www.intec.co.uk/session-slides-and-sample-database-from-ibm-connect/.

Here's a presentation and demo from IBM Connect 2013 where I do something similar to make a column editable http://www.intec.co.uk/session-slides-and-sample-database-from-ibm-connect/.

更现代的视图组件(如数据视图)使其变得更容易.

More modern view components like the Data View make it easier.

这篇关于是否可以在视图中进行数据绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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