0

On my exchange rate XPage, I want to be able to confirm the value the user has entered using a simple action. Using getComponent, I'm able to get a handle to the localCurrency (combobox) and effectiveDate (inputText that's a date). Those values are then easily displayed in the confirmation dialog. However, the exchangeRate always returns null.

Here's the exchangeRate inputText:

<xp:inputText style="width:75.0px;text-align:right;" id="exchangeRate"
    value="#{exchangeRateDoc.exchangeRate}"
    readonly="#{javascript:!exchangeRateDoc.isEditable();}"
    disabled="#{javascript:!@IsNewDoc();}">
    <xp:this.converter>
        <xp:convertNumber type="number"></xp:convertNumber>
    </xp:this.converter>
</xp:inputText>

...and here's the confirm, which brings in the localCurrency and effectiveDate values without a problem, but always reports exchangeRate as null.

<xp:confirm>
    <xp:this.message><![CDATA[#{javascript:var baseText = "Are you sure that you want to set the exchange rate for ";
var effectiveDate = getComponent("effectiveDate").getValue().toString();
var localCurrency = getComponent("localCurrency").getValue();
var exchangeRate = getComponent("exchangeRate").getValue();
return baseText + localCurrency + " to " + exchangeRate + " as of " + effectiveDate + "?"; }]]></xp:this.message>
</xp:confirm>

Where did I go wrong in my code that it cannot get the value of that inputText?

2 Answers 2

2

Do localCurrency and effectiveDate pick up values entered in the browser, or values defined last time that area of the page was refreshed to the browser?

You're computing SSJS to pass to a CSJS confirm() message. I would expect it to display values at the last refresh, not values just entered by the user. If you want the latest values, I think you'll need to access them via CSJS.

1
  • Ah, you're right, it returns the default values for those two fields, not the values the user has selected! Thanks! Sep 11, 2014 at 15:47
0

It's a classic error of confusing client-side with server-side. The values the user has entered on the client side are not accessible on the server-side until they've made it to the server. Since the confirm simple action is available on the server-side actions, you can only access server-side values when using it.

However, as Paul pointed out, the window.confirm method is available on the client-side and one can easily do the confirmation there, accessing the client-side values.

Functioning code for this would be:

   <xp:eventHandler event="onclick" submit="true" refreshMode="complete"
        immediate="false" save="true" id="eventHandler3">
        <xp:this.script><![CDATA[var baseText = "Are you sure that you want to set the exchange rate for ";
    var effectiveDate = document.getElementById("#{id:effectiveDate}").value;
    var localCurrency = document.getElementById("#{id:localCurrency}").value;
    var exchangeRate = document.getElementById("#{id:exchangeRate}").value;
    return window.confirm (baseText + localCurrency + " to " + exchangeRate + " as of " + effectiveDate + "?");]]></xp:this.script>
        <xp:this.action><![CDATA[#{javascript:exchangeRateDoc.save();
    context.redirectToPage("/pro_exchangeRate_view.xsp")}]]></xp:this.action>
   </xp:eventHandler>

Many thanks to Paul for pointing out my mistake!

Edit: Make sure that the client-side script returns a value. In my initial version of this script, it just had the window.confirm command, which offers the dialog to the user, but it disregards the response and executes the server-side commands anyway! Oops!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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