how to define a conditional xp:confirm?

假如想象 提交于 2019-12-11 20:54:38

问题


I would like to use the xp:confirm action on a conditional status. Is there a way to compute the rendered property of this control?

I can compute the rendered property for the whole xp:eventHandler but not for an xp:actionGroup or xp:confirm.


回答1:


xp:confirm just adds client-side JavaScript to the button with:

if (!XSP.confirm("YOUR MESSAGE")){
    return false;
}

XSP.confirm() is an XPages wrapper for JavaScript confirm. The most flexible approach is to code the client-side JavaScript you want on the "Client" tab of the button, doing return false to prevent the button sending to the server as required.




回答2:


This is a very synthetic snippet which you however can fit to your needs, if I got you right and if it suits your use case. Not so elegant, but works.

<xp:panel id="mainPanel">
    <xp:button id="myBtn1"
        value="Ask confirmation on submit">
        <xp:eventHandler event="onclick" submit="true"
            refreshMode="partial" refreshId="mainPanel">
            <xp:this.action>
                #{javascript:
                    requestScope.put('myAnyVar', 'askConfirmation');
                }
            </xp:this.action>
        </xp:eventHandler>
    </xp:button>
    <xp:button id="myBtn2"
        value="Dont ask confirmation on submit">
        <xp:eventHandler event="onclick" submit="true"
            refreshMode="partial" refreshId="mainPanel">
            <xp:this.action>
                #{javascript:
                    requestScope.put('myAnyVar','dontAskConfirmation');
                }
            </xp:this.action>
        </xp:eventHandler>
    </xp:button>
    <input type="hidden" id="doConfirm"
        value="#{requestScope.myAnyVar eq 'askConfirmation' ? '1' : '0'}">
    </input>
</xp:panel>
<br />
<br />
<xp:button id="btnSubmit"
    value="Submit">
    <xp:eventHandler event="onclick" submit="true"
        refreshMode="complete">
        <xp:this.script>
            var confirmOption = dojo.byId('doConfirm').value;
            if (confirmOption === '1') {
                if (confirm('Proceed the submit?')) {
                    return true;
                } else {
                    return false;
                }
            } else {
                return true;
            }
        </xp:this.script>
        <xp:this.action>
            #{javascript:
                viewScope.smthSubmitted = new java.util.Date();
            }
        </xp:this.action>
    </xp:eventHandler>
</xp:button>
<br />
<br />
<xp:text value="Submit time: #{viewScope.smthSubmitted}" />


来源:https://stackoverflow.com/questions/51999943/how-to-define-a-conditional-xpconfirm

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!