Search code examples
xpageslotus-noteslotus-dominoxpages-ssjs

Getting value via getComponent on compositeData


A check is made on a input field during save, if value exit then it should pass. The input field value exist as a compositeData, but the check keeps failing. Whats the best way of validating or getting the value of the input field?

I have tried getting this value using the getComponent function.

<xp:inputText id="fieldname" value="#{compositeData.dataSource.fieldname}">
    <xp:this.attrs>
        <xp:attr name="placeHolder" value="type here"></xp:attr>
    </xp:this.attrs>
    <xp:eventHandler event="onchange" submit="true" refreshMode="partial" refreshId="inputTextContainer" execId="fieldname">
        <xp:this.action><![CDATA[#{javascript:try { 
            var vVal = getComponent("fieldname").getValue();
            viewScope.put("fieldNameScope", vVal);
            print("vVal: " + vVal);                                                     
        }catch(e) {
            print("Fieldname error: " + e.toString());
        }
        }]]></xp:this.action>
    </xp:eventHandler>
</xp:inputText>

//var field = getComponent("fieldname").getSubmittedValue(); //returns null.
var field = viewScope.fieldNameScope; //getComponent("fieldname").getValue(); //returns nothing.
if(field == "" || field == null){
   vContinue = false;
   viewScope.MessageType = "Error";
   viewScope.MessageText = "Please field is empty";
   return context.redirectToPage( "home.xsp" );
}else{
   vContinue = true;
}

I was expecting the check to pass if value exist in the field, but the actual result is null.


Solution

  • I stored the value into a viewscope and then call the viewscope instead of using the getComponent. I will update my question with the onchange eventhandler.