2
votes

I'm using Mark Hughes picklist on my xpage which is using a datasource. The view from which I pick the values is listing documents having another datasource.

I put the selected value into an <xp:inputText>. I do want to create a link which should redirect me to the listed document from the view ( from it I took the value ). In other words, I do want to find out the UNID of the document from the view, which I did selected it.

I tried the following code for the ssjsSelectFunction:

var unid = viewScope.unid;

if(typeof unid != "undefined" && unid != null)
{
var doc = database.getDocumentByUNID(unid);
var val1 = doc.getItemValueString("txt_numeAcord_1");
var val2 = doc.getUniversalID();

getComponent("inputText24").setValue(val1);
getComponent("inputText25").setValue(val2);
}

But after selecting the desired doc. from the picklist, only inputText25 is updated with the value ( UNID ), the inputText24 is empty. Only if I open again the picklist and select the doc., the inputText24 field value is added. I guess I'm missing something.

How can I achieve this?

My xpage code:

<?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"
    xmlns:xe="http://www.ibm.com/xsp/coreex" >
    <xp:this.data>
        <xp:dominoDocument var="Contr" formName="(fmFormularCIP)"></xp:dominoDocument>
        <xp:dominoView var="view1" viewName="vwAcord"></xp:dominoView>
    </xp:this.data>
    <xp:panel id="AcordCadru">
        &#160;&#160;&#160;

        <xp:br></xp:br>
        &#160;&#160;
        <xp:checkBox text="Acord cadru" id="checkBox6"checkedValue="Da" uncheckedValue="Nu" value="#{Contr.chkAcord}">

            <xp:eventHandler event="onchange" submit="true"
                refreshMode="partial" refreshId="AcordCadru">
            </xp:eventHandler>
        </xp:checkBox>
        &#160;

        <xp:inputText id="inputText24" value="#{Contr.acord}">


        </xp:inputText>

        <xc:viewpicklist rowsPerPage="10"
            buttonImage="./folder_explore.png" tableClass="tablecellgreen"
            headerClass="headerclass" rowClass="odd, even" searchBar="false"
            searchButtonText="Search" searchButtonClass="button2"
            searchBarClass="headerclass" pagerStyleFirst="navbutton1"
            pagerStylePrevious="navbutton2" pagerStyleCurrent="navbutton4"
            pagerStyleNext="navbutton2" pagerStyleLast="navbutton3"
            typeAheadBar="false" select="UNID" onReturn="Set Scope Value"
            bottomBarClass="bottomround headerclass" cancelButtonText="Cancel"
            cancelButtonClass="button2 floatthisright" type="Single Value"
            finishButtonText="Finish" finishButtonClass="button2 floatthisright"
            multiSelectButtonAddImg="./add.png"
            multiSelectButtonRemoveImg="./delete.png"
            picklistButtonClass="button" openDialogWith="Button"
            picklistLinkImg="./add.png" multiSelectLinkAddImg="./add.png"
            multiSelectLinkRemoveImg="./delete.png" selectWith="Button"
            multiValueSeparator="," clearSearchImg="./cross.png"
            SelectCellWidth="30px" dialogID="dialog1"
            dialogTitle="Alegeti nr. acord cadru" fieldName="inputText24"
            refreshID="AcordCadru" datasrc="view1" selectColumn="0"
            varName="viewScope.unid">
            <xc:this.viewColumn>
                <xp:value>0</xp:value>




                <xp:value>1</xp:value>
                <xp:value>2</xp:value>
                <xp:value>3</xp:value>
                <xp:value>4</xp:value>
            </xc:this.viewColumn>

            <xc:this.ssjsSelectFunction><![CDATA[#{javascript:
var unid = viewScope.unid;

if(typeof unid != "undefined" && unid != null)
{

var doc = database.getDocumentByUNID(unid);
var val1 = doc.getItemValueString("txt_numeAcord_1");
var val2 = doc.getUniversalID();


Contr.setValue("acord",val1);
Contr.setValue("sv",val2);
}}]]></xc:this.ssjsSelectFunction>
        </xc:viewpicklist>
        <xp:br></xp:br>
        &#160;&#160;&#160;

        <xp:inputText id="inputText25" value="#{Contr.sv}">


        </xp:inputText>
    </xp:panel>


</xp:view>
1
a) Does your document have a txt_nume_Acord_1 ? b) Don't go after components... set the value of the item the component is bound to. Always keep in mind: a component is part of the VIEW. You update the MODEL. If you update the view there is a risk that the model updates your VIEW and overwrites the changes you madestwissel
@stwissel a) Yes, there is a txt_numeAcord_1 ( and not a txt_nume_Acord_1 ). b) I also try: Contr.setValue("acord",val1); - where Contr is the datasource of the doc where the cc lays and acord is a field. Still the same result: after I select a doc. from picklist: the 2nd field is updated immediately with the UNID, but the 1st field isn't completed. I must reopen the picklist and reselect again the value as the 1st field to be updated with the txt_numeAcord_1 value.Florin M.
Can you create a minimal example and paste the entire page. There must be a detail we overlook right nowstwissel
@stwissel I added my code. Hope to get it work.Florin M.
Florin, there are quite some dependencies in your code. So when I paste it into a XPage it doesn't run. The form is missing, the view is missing, the sample data is missing. Create a new empty database with a minimal working example and upload it somewhere.stwissel

1 Answers

1
votes

inputText24 doesn't get the selected value because the execution of ssjsSelectFunction's code is too late. It gets executed during the refresh of panel "AcordCadru" caused by parameter refreshID. All fields positioned in front of xc:viewpicklist get refreshed before ssjsSelectFunction's code execution. That's why inputText24 doesn't get the new selected value but inputText25 which comes after xc:viewpicklist does.

If you put inputText24 behind xc:viewpicklist then it will get the new selected value.

But, probably you want to have field inputText24 first and the picklist button xc:viewpicklist after. For this

  • delete the ssjsSelectFunction code
  • add a computed field in front of inputText24 with pretty the same code

    <xp:text
        escape="true"
        id="computedField1">
        <xp:this.value><![CDATA[#{javascript:
            var unid = viewScope.unid;          
            if (unid && unid !== Contr.sv) {
                var doc = database.getDocumentByUNID(unid);
                var val1 = doc.getItemValueString("txt_numeAcord_1");
                Contr.setValue("acord",val1);
                Contr.setValue("sv",unid);
            }
            return "";
            }]]></xp:this.value>
    </xp:text>
    

    It will set the new selected values to document and made them visible in inputText24 and inputText25 right away.