如何从重复控件中正确存储和保存字段值 [英] how to store and save correctly field values from repeat controls

查看:18
本文介绍了如何从重复控件中正确存储和保存字段值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个简单的重复控件,里面有 2 个简单的 inputTexts.在这个重复控件之外,有一个可编辑的 inputText3 (绑定到 dataSource ).我正在使用它在重复控件中进行一些计算.计算结果正确显示.我有 2 个按钮,分别用于 newLine 和 delete/hideLine.目前,重复控件中的那 2 个字段未绑定到数据源.

I created a simple repeat control, having inside it 2 simple inputTexts. Outside this repeat control, there is an editable inputText3 ( binded to dataSource ). I'm using it to make some calculations inside the repeat control. The calculations are displayed correctly. I have 2 buttons, for newLine and delete/hideLine. For the moment, those 2 fields inside the repeat control are not binded to the datasource.

我有一个保存文档的按钮,并将它列在一个视图面板中,第一列 inputText3 是可点击的.我注意到如果我打开文档(在编辑或阅读模式下)这个可编辑的字段值会正确显示,但重复控件中的字段都是空的,即使我在使用保存方法之前添加了一些值.

i have a button which save the doc., and list it inside a viewPanel, having the first column inputText3, clickable. I noticed that if I open the document ( in edit or read mode ) this editable field value is correctly displayed, but the fields inside the repeat control are all null, even if I add some values before using the save method.

我还尝试在表单中创建 2 个字段 (/datasource) 并将此 inputTexts 绑定到它们,但重复控件字段再次为空.

I try also to create 2 fields inside the form ( / datasource ) and binding this inputTexts to them, but again the repeat control fields are empty.

 <xp:repeat id="repeat1" var="varRepeat" indexVar="index">
 <xp:this.value><![CDATA[#{javascript:parseInt(sessionScope.dField)
 }]]></xp:this.value>

...

 <xp:inputText id="inputText1"></xp:inputText>

 <xp:inputText id="inputText2"></xp:inputText>

重复之外的可编辑字段:

The editable field outside the repeat:

<xp:inputText id="number" value="#{docrepeat.valtotala}"
        defaultValue="100">
</xp:inputText>

.

<xp:this.data>
        <xp:dominoDocument var="docrepeat" formName="docrepeat"></xp:dominoDocument>
    </xp:this.data>

我肯定在这里遗漏了一些东西,希望能找到一个功能性的解决方案.

I'm definitely missing something here, hope to reach to a functional solution.

我应该使用repeat的var属性绑定2个inputText吗?

Should I bind the 2 inputText using the var property of the repeat?

或者我怎样才能做到这一点?

Or how can I achieve this?

重复控制代码:

<xp:repeat id="repeat1" var="test" indexVar="index" rows="8">
            <xp:this.value><![CDATA[#{javascript:parseInt(sessionScope.DField)
}]]></xp:this.value>
<xp:panel>
            <xp:table >
                <xp:tr>
                    <xp:td>

                        <xp:inputText id="inputText1">
                            <xp:eventHandler event="onchange"
                                submit="false">
                                <xp:this.script><![CDATA[try
{
var idx="view:_id1:inputText3";
var index=document.getElementById(idx).value;

var number="view:_id1:number";
var val=document.getElementById(number).value;

var sum = val;

for(var i=0;i<index;i++) {
var input1="view:_id1:repeat1:"+i+":inputText1"
var nr1=document.getElementById(input1).value;

sum-=nr1;
document.getElementById("view:_id1:repeat1:"+i+":inputText2").value = sum;
}
// calculating some %
document.getElementById("view:_id1:test").value = parseInt((sum*100)/val); 

}
catch(e)
{
alert("not working");
}]]></xp:this.script>
                            </xp:eventHandler>
                        </xp:inputText>
                        <xp:inputText id="inputText2"></xp:inputText>
                    </xp:td>
                </xp:tr>
            </xp:table>
            </xp:panel>
        </xp:repeat>

我的小场景描述如下:Xpages 如何获取/创建这个计算模块

推荐答案

我觉得你的数据源里面的repeat 是一个视图.您需要在重复中添加对象数据的数据源.这样做的方法是在重复中创建一个面板,并为该面板提供如下数据源.

I think your datasource inside the repeat is a view. You need to add a datasource of object data inside the repeat. The way to do this is to create a panel inside the repeat and give that panel a datasource as follows.

<xp:repeat id="repeat1" rows="30" value="#{view1}"
            var="rowData">
        <xp:panel>


 <xp:dominoDocument var="objectData1"
                        formName="Item"
                        documentId="#{javascript:return rowData.getNoteID();}"
                        ignoreRequestParams="true" action="openDocument">
</xp:dominoDocument>

!!!put your stuff in the panel!!!


</xp:panel>
</xp:repeat>

所以发生的事情是重复抓取数据源,它是一个视图.因此它将遍历视图中的所有条目.但是视图数据源不知道如何处理文档.因此,您创建了 objectData,它将获取该特定文档的 noteID,并将其作为文档(由 noteID 引用)提供给重复使用.将其作为文档提供将允许它保存值.您可能无法使用值选择器,而只需输入字段名称即可.

So what is going on is the repeat grabs the datasource which is a view. So it will iterate through all of the entries in the view. But the view datasource does not know what to do with documents. So you create the objectData which will grab the noteID of that specific document and make that available to the repeat as a document(referenced by noteID). Making it available as a document will allow it to save values. You probably won't be able to use the value picker but just type in the field names and it will work.

不确定我是否完全理解您的问题.但是您还需要保存数据源.因此,您可以在面板中放置一个保存按钮来保存该特定文档,或者让保存按钮保存所有数据源.我更喜欢能够单独保存每个文档,因为它允许多个应用程序可以同时编辑.

Not sure I am completely understanding your problem. But you also need to save the datasource. So you could either put a save button in the panel to save that specific document or make the save button save all data sources. I prefer being able to save each document separately as it allows for applications that multiple can edit at the same time.

这篇关于如何从重复控件中正确存储和保存字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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