TabClos​​e事件上的ConfirmDialog

时间:2015-03-03 14:06:22

标签: jsf-2 primefaces

如何根据用户的confirmDialog操作处理关闭标签的操作? "是"继续关闭标签," No"中止操作。我在下面制作了这个代码但是标签仍然关闭了。有什么建议吗?

<p:confirmDialog    closable="true" appendToBody="true" id="confirmDialog" message="Are you sure to close ?" header="Test"  widgetVar="confirmation">  
    <h:form>
        <p:commandButton id="confirm" value="Yes" onclick="closeTab=true;" oncomplete=" PF('confirmation').hide();"/>  
        <p:commandButton id="decline" value="No" onclick="PF('confirmation').hide()" /> 
    </h:form>
    </p:confirmDialog>

<p:tabView  onTabClose="return close(function(){return true;});">
        <p:tab title="test tab" closable="true" >
           // Some inputs controls here
        </p:tab>
    </p:tabView>

JS功能

var closeTab = false;
function close(callback) 
{
     PF('confirmation').show();
       var state = false;
       loop();
       function loop() {
            if (!closeTab) {
                console.log('fired');
                setTimeout(loop, 0);
            }
            else {
                callback();
            }
        }
}

1 个答案:

答案 0 :(得分:0)

我会尝试这种方式

<p:confirmDialog closable="true" appendToBody="true" id="confirmDialog" message="Are you sure to close ?" header="Test"  widgetVar="confirmation">  
    <h:form>
        <p:commandButton id="confirm" value="Yes" onclick="PF('confirmation').remove();" oncomplete=" PF('confirmation').hide();"/>  
        <p:commandButton id="decline" value="No" onclick="PF('confirmation').hide()" /> 
    </h:form>
    </p:confirmDialog>

<p:tabView  onTabClose="PF('confirmation').show();return false;">
        <p:tab title="test tab" closable="true" >
           // Some inputs controls here
        </p:tab>
    </p:tabView>

...但是我同意内置的确认将非常有用