In a SSJS button I have got a NotesViewEntryCollection

两盒软妹~` 提交于 2020-01-16 19:25:01

问题


by veCol = vw.getAllEntriesByKey(key,false) where key is a value from a control on the 'form'. If the count in the veCol is Zero I return a message that the search failed, if the count is 1 (One) I set some values and redirect the page to an input page, however, if the count is greater than one I want to display the veCol to a repeat control. I thought of setting a viewScope variable to the veCol but I have seen the admonished don't store a Notes Object in a Scope variable because they are not serialized. So my question is "Is there a way to pass my veCol to a repeat control on the same custom control?" Actually the control is a dialog but that shouldn't matter.

In another instance I took the collection and turned it into an array of UNIDs in a viewScope variable then bound the repeat to the variable. This means that I have to get each document again using the UNID which works, but the veCol already contains everything that I need, just being able to pass it would be more efficient. So I know I can make it work but with a fair bit of overhead.

The code is pretty simple in my button I execute var veCol:NotesViewEntryCollection = vw.getAllEntriesByKey(key, false);

in the same dialog that contains the button I want a repeat using the value returned as veCol.

Any help appreciated.


回答1:


You could create your own ValueBinding and overwrite the exitsing one of the repeat:

<xp:button
    value="Label"
    id="button1">
    <xp:eventHandler
        event="onclick"
        submit="true"
        refreshMode="partial"
        refreshId="repeat1">
        <xp:this.action>
            <![CDATA[#{javascript:
                var valueExpr = "#{javascript:vw.getAllEntriesByKey(key, false);}";
                var value:javax.faces.el.ValueBinding = facesContext.getApplication().createValueBinding(valueExpr);
                var veCol:NotesViewEntryCollection = value.getValue( facesContext );

                if( veCol.getCount() > 0 ){
                    var cmpRepeat:com.ibm.xsp.component.xp.XspDataIterator = getComponent('repeat1');
                    cmpRepeat.setValueBinding( "value", value );
                }else{
                    // do redirect
                }
        }]]></xp:this.action>
    </xp:eventHandler>
</xp:button>

Or just define a SSJS variable in your button, and test if the variable exists:

<xp:repeat
    id="repeat1"
    rows="30"
    var="doc">
    <xp:this.value>
        <![CDATA[#{javascript:
            if(  typeof( veCol ) != "undefined" ){
                return veCol;
            }
        }]]>
    </xp:this.value>
    <xp:label
        value="#{javascript:if( doc != null ) doc.getUniversalID()}"
        id="label1">
    </xp:label>
</xp:repeat>



回答2:


Well I'd love to see some code or even a little diagram of the flow.

First you can pass a Viewentrycollection to a repeat control. I've asked this myself actually. :) How do you pass a NotesDocument / NotesViewEntry Collection into a Custom Control via custom property?

I agree you do not want to try and store your collection inside viewScope itself. In the Java world this is relatively simple I'd think but let's keep it non java since that's what you're asking about.

check this question out: How to pass variable parameters to an XPages SSJS function?

Rather then an ArrayList of UNIDS of your collection you could create a javascript Object for each document and put the field names and values inside there... It's kinda like JSON in a way... least that's how I think of it. Now it's "safe" so you can put that in scope or return that or whatever if you don't want to pass the domino object to the repeat control itself...



来源:https://stackoverflow.com/questions/25856437/in-a-ssjs-button-i-have-got-a-notesviewentrycollection

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