how to store and save correctly field values from repeat controls

末鹿安然 提交于 2020-01-15 17:54:31

问题


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.

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.

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.

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

Or how can I achieve this?

repeat control code:

<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>

My little scenario was described here: Xpages how to obtain/create this calculations module


回答1:


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>

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.



来源:https://stackoverflow.com/questions/25846541/how-to-store-and-save-correctly-field-values-from-repeat-controls

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!