1
votes

I have a repeat control on an XPage displaying item summary. To view other details, the user clicks on a button (inside the repeat) which will set a viewScope variable to the rowIndex of the repeat and then open up a modal to display the remeaining item details.

I am unable to set the viewScope variable from the button. It's like it cannot get a handle to the rowIndex.

I have a computed text field set to display the rowIndex at the beginning of the repeat (which works fine).

I'm obviously missing something elementary. Any assistance would be appreciated.

Relevant source code follows:

<xp:repeat id="repeat1" rows="50" var="entry" indexVar="rowIndex">
<xp:this.value><![CDATA[#{javascript:var m = sessionScope.assetMap;
if(m!=null){
m.entrySet()
}}]]></xp:this.value>
<div>
    <small>                 
    <label>
    <xp:text escape="true" id="num">
    <xp:this.value><![CDATA[#{javascript:var itemNum:Number =     parseInt(rowIndex + 1);
itemNum.toPrecision(0);}]]></xp:this.value>
    </xp:text>
    .&#160; Description:&#160; &#160;
    </label>
    <xp:text escape="true" id="desc">
    <xp:this.value><![CDATA[#{javascript:@Word(entry.getValue(),"~",3);}]]>    </xp:this.value>
    </xp:text>
    </small>
</div>
<br></br>
<div>
<xp:button type="button" value="Details ..." id="button2">
<xp:eventHandler event="onclick" submit="true" refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:try{var itemNum:Number =     parseInt(rowIndex + 1);
viewScope.currentItem = itemNum.toPrecision(0);
}catch(e) {
requestScope.errstatus = e.toString();}}]]></xp:this.action>
</xp:eventHandler>
</xp:button>

02/04/2015 Update:

I have isolated the problem to the rendered property of the custom control. The code works if I don't use the rendered property.

The code in the onCLientLoad of my XPage (CSJS) is:

$(window).on('load resize', function(){
var screenWidth = $(window).width();
var sDevice = '';

switch(true){
    case (screenWidth < 768):
        sDevice = 'mobile';
        break;
    case (screenWidth < 922):
        sDevice = 'tablet';
        break;
    case (screenWidth >= 922):
        sDevice = 'desktop'
}

XSP.partialRefreshPost( '#{id:pnlList}', {params: {'sDevice': sDevice}} );

});

And the source for my custom control in the XPage with the rendered property is:

<xp:panel rendered="#{javascript:param.sDevice == 'mobile'}">
        <xc:ccSYS_AppLayoutReq_p xp:key="panelContentFacet">
            <xp:this.facets>
                <xc:cc_cartracking_p xp:key="contentFacet"></xc:cc_cartracking_p>
            </xp:this.facets>
        </xc:ccSYS_AppLayoutReq_p>  
        </xp:panel>

Thanks,

Dan

1
Dan, maybe try changing your var itemNum:int instead of Number. Or try removing the type altogether. Also if you wrap rightside of code in print() statements are you getting the expected values in the log?Steve Zavocki
Thanks Steve. I don't think it has to do with itemNum:Number because that's being used in the computed field and works just fine there. Also, my try catch is not generating any errors.Dan Soares
What is the result of print(parseInt(rowIndex + 1)) and print(itemNum) and print(itemNum.toPrecision(0)). I am thinking that one of them is null or an unexpected result that might give you a clue where it is failing.Steve Zavocki
Yes, it does work for me. Starting from your working example in question and adding piece by piece will be a good way to find the issue. Good luck :)Knut Herrmann
Dan, your button use refreshMode="complete", meaning you reload the whole xpage. So you set your viewscope variable, and then reload the whole page. At this time,the value in the viewscope is gone because the page was reloaded! You have to use a partial refresh if you want to use a viewscope variable. If you need a complete refresh, you'll have to use a sessionScope variableRenaud Thiévent

1 Answers

2
votes

You have to set option "Set partial execution mode" execMode="partial" in your button.

Look for the whole answer at your colleague's question https://stackoverflow.com/a/28330481/2065611