在自定义控件上的复合数据中定义对象属性 [英] defining an object property in a compositeData on a custom control

查看:25
本文介绍了在自定义控件上的复合数据中定义对象属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个具有 mainDoc 的应用程序,其中可以包含一个或多个相关的注释文档.在 mainDoc 中,有一个重复控件绑定到 Payments.getAllItems(WFSMainDoc.getValue("LinkKey")); Java 类 Payments 具有操作 PaymentItems 和 ArrayList 的方法.getAllItems 方法获取所有相关的 NotesDocuments 并将它们加载到 ArrayList 中.如果 ArrayList 已经存在,它只返回先前构建的 ArrayList.重复中的按钮设置 viewScope.vsRIndex = rIndex;viewScope.vsShowPayment = true; 现在显示 panelPaymentDetail 和具有类型 java 的自定义属性的自定义控件.lang.Object 并使用 pItem = Payments.getItem(rIndex); 加载 pItem;return pItem;

I'm building an application where I have mainDoc which can have one or more related notes Documents. In the mainDoc there is a repeat control that is bound to Payments.getAllItems(WFSMainDoc.getValue("LinkKey")); The java class Payments has methods that manipulate and ArrayList of PaymentItems. The getAllItems method grabs all of the related NotesDocuments and loads them into an ArrayList. If the ArrayList already exists it just returns the previously built ArrayList. The button in the Repeat sets viewScope.vsRIndex = rIndex; and viewScope.vsShowPayment = true; which now displays the panelPaymentDetail and the custom control that has a custom property of type java.lang.Object and load pItem using pItem = Payments.getItem(rIndex); return pItem;

上述所有工作都有效,我在下面有几个示例控件.我有两个问题:1. compositeData.pItem 被一遍又一遍地计算,据我所知,即使我正在从 Payments.getAllItems() 返回原始值在付款输入表单"中编辑它们 - 那么问题是如何阻止这种重复计算?

all of the above works and I have a couple sample controls below. I have two issues: 1. The compositeData.pItem is computed over and over again and as far as I can tell keeps returning the original values from the Payments.getAllItems() even though I'm editing them in the payment input 'form' -- the question then is how can I block this repeated calculation?

  1. 付款输入自定义控件中的保存按钮似乎没有触发(单击时不会出现任何打印语句)我认为重新加载对象 pItem 会造成障碍.

测试主文档控件:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" 
xmlns:xc="http://www.ibm.com/xsp/custom">
    <xp:this.data>
        <xp:dominoDocument var="WFSMainDoc" formName="frmMainDoc"
            computeWithForm="onsave" ignoreRequestParams="false">
            <xp:this.documentId><![CDATA[${javascript:var UNID:String = sessionScope.get("ssUNID");
(UNID == null || UNID == "") ? "" : UNID}]]></xp:this.documentId>
            <xp:this.action><![CDATA[${javascript:if (sessionScope.containsKey("ssUNID")){
    if(sessionScope.get('ssUNID').length){
        sessionScope.get('ssAction') == 'edit' ? 'editDocument':'openDocument'
    } else {
        return 'createDocument'
        break;
    }
}else{
    return "createDocument";
    break;
}}]]></xp:this.action>
            <xp:this.databaseName><![CDATA[${appProps[sessionScope.ssApplication].appFilePath}]]></xp:this.databaseName>
        </xp:dominoDocument>
    </xp:this.data>

    Main document
    <xp:br></xp:br>

    <xp:inputText id="inputText1" value="#{WFSMainDoc.LinkKey}"
        defaultValue="#{javascript:@Unique}">
    </xp:inputText>

    <xp:br></xp:br>
    Other Fields and controls
    <xp:br></xp:br>
    <xp:panel id="panelPaymentContainer">
        <xp:repeat id="repeatData" rows="10" var="pItem"
            indexVar="rIndex">
            <xp:this.value><![CDATA[#{javascript:Payments.getAllItems(WFSMainDoc.getValue("LinkKey"));}]]></xp:this.value>
            <xp:button id="buttonEditPayment"
                rendered="#{javascript:(WFSMainDoc.isEditable())}">
                <xp:eventHandler event="onclick" submit="true"
                    refreshMode="partial" refreshId="panelPaymentsContainer">
                    <xp:this.action><![CDATA[#{javascript:try{
viewScope.vsRIndex = rIndex;
viewScope.vsShowPayment = true;
break;
}catch(e){
    WFSUtils.sysOut("Error in calling dialogPayment " + e.tostring)
}}]]>
                    </xp:this.action>
                </xp:eventHandler>
            </xp:button>
            <br />

        </xp:repeat>
        <xp:panel id="panelPaymentInput">
            <xp:this.styleClass><![CDATA[#{javascript:(viewScope.vsShowPayment) ? "" : "display=none";}]]></xp:this.styleClass>


            <xc:ccTestPaymentInput rendered="#{javascript:(viewScope.vsShowPayment)}">
                <xc:this.pItem><![CDATA[#{javascript:try{
        var debug:Boolean = true;
        if (debug) WFSUtils.sysOut("Open existing row = " + viewScope.vsRIndex)
        rIndex = parseInt(viewScope.vsRIndex.toString());
        if (debug) WFSUtils.sysOut("rIndex = " + rIndex);
        pItem = Payments.getItem(rIndex);
        return pItem;

}catch(e){
    WFSUtils.sysOut("Failure in Custom Prop of add item " + e.toString());
    return null;
}}]]></xc:this.pItem>
            </xc:ccTestPaymentInput>
        </xp:panel>
    </xp:panel><!-- panelPaymentContainer -->
    <xp:br></xp:br>
    <xp:br></xp:br>
</xp:view>

支付输入控件

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">

    <xp:br></xp:br>

    Actual Pay Date:&#160; 
    <xp:inputText id="actualPayDate"
        value="#{compositeData.pItem.actualPayDate}">
        <xp:dateTimeHelper id="dateTimeHelper1"></xp:dateTimeHelper>
        <xp:this.converter>
            <xp:convertDateTime type="date"></xp:convertDateTime>
        </xp:this.converter>
    </xp:inputText>
    <br /> <br />
    <xp:button value="Save" id="button1">
                            <xp:eventHandler event="onclick"
                                submit="true" refreshMode="partial" refreshId="panelPayments">
                                <xp:this.action><![CDATA[#{javascript:try{

var debug:Boolean = true;
if (debug) print("Start Payment save");
var pos:Integer = parseInt(viewScope.vsRIndex.toString());
if (debug) print("Working with pos = " +  pos + " Call saveThisItem");

if (Payments.saveThisItem(compositeData.pItem , pos)){
    if (debug) print("save Payments Worked ");
}else{
    if (debug) print("save Payments FAILED ");
}

}catch(e){
    print("payment save Error " + e.tostring);

}finally{
    viewScope.vsExpPayDate = "";
    viewScope.remove("vsShowPayment");
    viewScope.remove("vsRIndex");
    viewScope.remove("vsGotItem")
}}]]></xp:this.action>
                            </xp:eventHandler>
    </xp:button>


</xp:view>

推荐答案

这一切都非常复杂,我还远远不能理解您在这里想要实现的目标.但至少我在你的代码中发现了一些奇怪的地方:

This is all very complicated, and I'm far from understanding what you're trying to achieve here. But at least I found a few oddities in your code:

广告 1:有一个 id="panelPaymentContainer" 包含重复的面板.在重复中,有一个按钮在 id="panelPaymentsContainer" >> 上执行了 partialRefresh,这是一个错字吗(Payment(s)"中的复数与单数形式)?按钮是否应该刷新面板?假设这个假设是正确的:每次单击按钮时,面板及其所有内容都会刷新,因此也会刷新重复的数据源.因此 pItem 将始终从由外向内"推送到您的重复内容中.- 如果 refreshId 不是错字,那应该是什么?我很努力地阅读了整个代码,但是代码太多了,所以我可能错过了一些东西

ad 1: there is a panel with id="panelPaymentContainer" containing a repeat. Inside that repeat is a button doing a partialRefresh on an id="panelPaymentsContainer" >> is this a typo (plural vs. singular forms in "Payment(s))? Should the button be refreshing the panel? Assuming that this assumption is true: every time you click the button the panel is refreshed together with all its contents, thus also refreshing the repeat's datasource. And so pItem will always be pushed from "outside in" into the content of your repeat. - If the refreshId thing is NOT a typo, then what should it be? I tried hard to read the entire code, but there's a lot of it, so I might have missed something

广告 2:此处类似:保存按钮尝试使用 id="panelPayments" 刷新某些内容,但我看不到任何具有此 ID 的内容.所以难怪它似乎没有做任何有用的事情.

ad 2: similar thing here: the save button tries to refresh something with an id="panelPayments", but I cannot see anything with this id. So no wonder it doesn't appear to do anything useful.

我对此类复杂任务的建议:尝试将所有内容剥离到最基本的部分;你的代码越复杂,就越难发现它的错误.从一个面板、一个重复和一些简单的控件(如按钮和一堆计算字段)开始,以显示一些测试值.然后,一旦这个非常简单的模型开始工作,您就可以开始添加它.- 顺便说一句,简化还可以帮助其他人发现您的概念中的错误.

My recommendation for complicated tasks like these: try to strip everything down to the bare essentials; the more complicated your code is the harder it is to find its mistakes. Start with a panel, a repeat and a few simple controls like a button and a bunch of computed fields to display some test values. Then as soon as this very simple model is working you can start to add to it. - Simplifying also helps others to find mistakes in you concept, btw.

这篇关于在自定义控件上的复合数据中定义对象属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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