Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to bind the data to a FORM from a computed field which calculates the amount according to the number of days selected.Please help me!

share|improve this question
1  
add comment

2 Answers

I had the same issue. This may not be the most efficient way to solve this but it works.

var cost1 = getComponent('ItemCost1').getValue(); document1.replaceItemValue("ItemCost_1", cost1),

You can put this in a QuerySave event & it works well.

share|improve this answer
add comment

My preference is to let the Computed Field do the work and put the targeted field into a place that is not displayed to the user but is visible on the XPage. Something like this:

<xp:table id="dataTable">
    <xp:tr>
        <xp:td>
            <xp:label value="Price Per Day" id="label1"></xp:label>
            </xp:td>
        <xp:td>
            <xp:inputText id="PricePerDayEB1" value="#{document1.PricePerDay}" defaultValue="25">
                <xp:this.converter>
                    <xp:convertNumber type="currency"></xp:convertNumber>
                </xp:this.converter>
                <xp:eventHandler event="onchange" submit="true" refreshMode="partial" refreshId="dataTable">
                </xp:eventHandler>
            </xp:inputText>
        </xp:td>
    </xp:tr>
    <xp:tr>
        <xp:td>
            <xp:label value="Days" id="label2"></xp:label>
        </xp:td>
        <xp:td>
            <xp:inputText id="DaysEB1" value="#{document1.Days}" defaultValue="1">
                <xp:this.converter>
                    <xp:convertNumber type="number" integerOnly="true">
                    </xp:convertNumber>
                </xp:this.converter>
                <xp:eventHandler event="onchange" submit="true" refreshMode="partial" refreshId="dataTable">
                </xp:eventHandler>
            </xp:inputText>
        </xp:td>
    </xp:tr>
    <xp:tr>
        <xp:td>
            <xp:label value="Computed Total" id="label3"></xp:label>
        </xp:td>
        <xp:td>
            <xp:text escape="true" id="compTotalCF1">
                <xp:this.value><![CDATA[#{javascript:
var PricePerDayEB1:com.ibm.xsp.component.xp.XspInputText = getComponent("PricePerDayEB1");
var DaysEB1:com.ibm.xsp.component.xp.XspInputText = getComponent("DaysEB1");
var TotalEB1:com.ibm.xsp.component.xp.XspInputText = getComponent("TotalEB1");

var ppd = PricePerDayEB1.getValue();
var days = DaysEB1.getValue();
var total = ppd*days

TotalEB1.setValue(total);
return total;
}]]></xp:this.value>
            </xp:text>
        </xp:td>
    </xp:tr>
    <xp:tr style="display:none;">
        <xp:td>
            <xp:label value="Bound Total" id="label4"></xp:label>
        </xp:td>
        <xp:td>
            <xp:inputText id="TotalEB1" value="#{document1.Total}">
                <xp:this.converter>
                    <xp:convertNumber type="number"></xp:convertNumber>
                </xp:this.converter>
            </xp:inputText>
        </xp:td>
    </xp:tr>
    <xp:tr>
        <xp:td colspan="2">
            <xp:button value="Submit" id="button1">
            <xp:eventHandler event="onclick" submit="true" refreshMode="complete" immediate="false" save="true"></xp:eventHandler></xp:button>
        </xp:td>
    </xp:tr>
</xp:table>

Happy coding

/Newbs

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.