Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在XPages中的单个按钮后面执行多个页面更新_Xpages - Fatal编程技术网

如何在XPages中的单个按钮后面执行多个页面更新

如何在XPages中的单个按钮后面执行多个页面更新,xpages,Xpages,这是一个高层次的问题,但确实有具体的答案 我有一个要求,我需要执行一个操作两次,并在第二次尝试该操作之前用消息更新用户。我还想在第一个操作之前更新用户 以下是事件的时间线/顺序: 用户按下按钮 显示消息“操作开始” 执行操作 如果成功,如果操作失败,则显示“操作成功” 显示“操作失败-重试” 重试操作 如果成功,则显示“操作成功”,如果操作失败,则显示“请稍后再试” 当我在java方法中对此进行编码时,唯一显示的是最后一条消息。我试着使用Thread.sleep(1500)为消息提供显示机会,但

这是一个高层次的问题,但确实有具体的答案

我有一个要求,我需要执行一个操作两次,并在第二次尝试该操作之前用消息更新用户。我还想在第一个操作之前更新用户

以下是事件的时间线/顺序:

  • 用户按下按钮
  • 显示消息“操作开始”
  • 执行操作
  • 如果成功,如果操作失败,则显示“操作成功” 显示“操作失败-重试”
  • 重试操作
  • 如果成功,则显示“操作成功”,如果操作失败,则显示“请稍后再试”
  • 当我在java方法中对此进行编码时,唯一显示的是最后一条消息。我试着使用
    Thread.sleep(1500)
    为消息提供显示机会,但仅显示最后一条消息

    然后我尝试使用SSJS来完成这个任务,但结果是一样的。我想我明白为什么会这样


    我的问题是:是否有可能像这样进行多次局部刷新。我可以采取什么样的最佳方法来实现这一要求。任何人都能想到什么样的解决方法或破解方法。

    我曾经试过Mark的帖子,想要一个进度条。没有让它发挥作用,但没有深入努力。解决方案可能就在那里

    你想要的当然是可行的。我想至少你可以用CSJ来完成繁重的工作。让CSJS可能通过RPC或XAgent调用SSJS,这就完成了第一条和第二条消息的所有工作


    我只是简单介绍了实现这一目标的实际细节。:)

    我试过一次马克的帖子,想要一个进度条。没有让它发挥作用,但没有深入努力。解决方案可能就在那里

    你想要的当然是可行的。我想至少你可以用CSJ来完成繁重的工作。让CSJS可能通过RPC或XAgent调用SSJS,这就完成了第一条和第二条消息的所有工作


    我只是简单介绍了实现这一目标的实际细节。:)

    如果您只想尝试两次,可以创建一个rpc控件来实现您想要的功能,然后通过回调调用它

        var deferred = service.doSomethingCool();
        deferred.addCallback(function(data) {
      if (data.status == 'error') {
           //set UI Label Fail
           var insideDeferred = service.doSomethingCool();
           insideDeferred.addCallback(function(data) {
           if (data.status == 'error') {
               //set UI Label Fail
            }
            else {
                //set UI Label Success
            }
        }
      }
    }
    

    假设您有一个名为服务的RPC控件和名为“doSomethingCool”的方法,这应该适用于您。如果您只想尝试两次,您可以创建一个实现所需功能的RPC控件,然后通过回调调用它

        var deferred = service.doSomethingCool();
        deferred.addCallback(function(data) {
      if (data.status == 'error') {
           //set UI Label Fail
           var insideDeferred = service.doSomethingCool();
           insideDeferred.addCallback(function(data) {
           if (data.status == 'error') {
               //set UI Label Fail
            }
            else {
                //set UI Label Success
            }
        }
      }
    }
    

    假设您有一个名为服务的RPC控件和一个名为“doSomethingCool”的方法,这应该对您有用。

    是的,这是可能的。我们可以在一次单击按钮中来回执行客户端和服务器端操作n次

  • 为警报创建一个带有CSJS代码的按钮
  • 为您的操作编写SSJS代码
  • 现在关键在于您的操作是部分刷新还是完全刷新
  • 如果部分刷新,请在eventhandler中使用oncomplete/onfailure事件编写CSJS代码以执行按钮单击操作。使用隐藏输入字段存储重试次数,并确定重试必须停止的次数

    如果完全刷新,则不会触发oncomplete事件。在clientload事件上编写CSJS代码。在这种情况下,创建一个隐藏的输入字段并将其绑定到视图范围变量。使用它将成功或失败存储在SSJS代码中,并检索CSJS代码中的值以进行检查并重试

    我已经包含了一个带有按钮的示例代码,但是它可以用许多不同的方式实现

    <?xml version="1.0" encoding="UTF-8"?>
    <xp:view xmlns:xp="http://www.ibm.com/xsp/core">
        <xp:button value="Label" id="button1">
            <xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="label1">
                <xp:this.script><![CDATA[alert("operation starting");]]></xp:this.script>
                <xp:this.action><![CDATA[#{javascript:viewScope.status = "first operation completed";
    print(getComponent("fail").getValue());}]]></xp:this.action>
                <xp:this.onComplete><![CDATA[alert("first operation completed. starting second");
    document.getElementById("#{id:ihRetry}").value = "False";
    document.getElementById("#{id:button2}").click();]]></xp:this.onComplete>
                <xp:this.onError><![CDATA[if ( document.getElementById("#{id:ihRetry}").value == "False" ) {
        alert("first operation failed. retry again");
        document.getElementById("#{id:ihRetry}").value = "True";
        document.getElementById("#{id:button1}").click();
    } else {
        alert("first operation failed again. starting second");
        document.getElementById("#{id:ihRetry}").value = "False";
        document.getElementById("#{id:button2}").click();
    }]]></xp:this.onError>
            </xp:eventHandler>
        </xp:button>
        <xp:button value="Label" id="button2" style="display:none">
            <xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="label1">
                <xp:this.action><![CDATA[#{javascript:viewScope.status = "second operation completed";}]]></xp:this.action>
                <xp:this.onComplete><![CDATA[alert("second operation completed. starting third");
    document.getElementById("#{id:ihRetry}").value = "False";
    document.getElementById("#{id:button3}").click();]]></xp:this.onComplete>
                <xp:this.onError><![CDATA[if ( document.getElementById("#{id:ihRetry}").value == "False" ) {
        alert("second operation failed. retry again");
        document.getElementById("#{id:ihRetry}").value = "True";
        document.getElementById("#{id:button2}").click();
    } else {
        alert("second operation failed again. starting third");
        document.getElementById("#{id:ihRetry}").value = "False";
        document.getElementById("#{id:button3}").click();
    }]]></xp:this.onError>
            </xp:eventHandler>
        </xp:button>
        <xp:button value="Label" id="button3" style="display:none">
            <xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="label1">
                <xp:this.action><![CDATA[#{javascript:viewScope.status = "third operation completed";}]]></xp:this.action>
                <xp:this.onComplete><![CDATA[alert("third operation completed.");
    document.getElementById("#{id:ihRetry}").value = "False";]]></xp:this.onComplete>
                <xp:this.onError><![CDATA[if ( document.getElementById("#{id:ihRetry}").value == "False" ) {
        alert("third operation failed. retry again");
        document.getElementById("#{id:ihRetry}").value = "True";
        document.getElementById("#{id:button3}").click();
    } else {
        alert("third operation failed again. end");
        document.getElementById("#{id:ihRetry}").value = "False";
    }]]></xp:this.onError>
            </xp:eventHandler>
        </xp:button>
        <xp:inputHidden id="ihRetry">
            <xp:this.value><![CDATA["False"]]></xp:this.value>
        </xp:inputHidden>
        <xp:label value="#{viewScope.status}" id="label1"></xp:label>
    </xp:view>
    

    是的,这是可能的。我们可以在一次单击按钮中来回执行客户端和服务器端操作n次

  • 为警报创建一个带有CSJS代码的按钮
  • 为您的操作编写SSJS代码
  • 现在关键在于您的操作是部分刷新还是完全刷新
  • 如果部分刷新,请在eventhandler中使用oncomplete/onfailure事件编写CSJS代码以执行按钮单击操作。使用隐藏输入字段存储重试次数,并确定重试必须停止的次数

    如果完全刷新,则不会触发oncomplete事件。在clientload事件上编写CSJS代码。在这种情况下,创建一个隐藏的输入字段并将其绑定到视图范围变量。使用它将成功或失败存储在SSJS代码中,并检索CSJS代码中的值以进行检查并重试

    我已经包含了一个带有按钮的示例代码,但是它可以用许多不同的方式实现

    <?xml version="1.0" encoding="UTF-8"?>
    <xp:view xmlns:xp="http://www.ibm.com/xsp/core">
        <xp:button value="Label" id="button1">
            <xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="label1">
                <xp:this.script><![CDATA[alert("operation starting");]]></xp:this.script>
                <xp:this.action><![CDATA[#{javascript:viewScope.status = "first operation completed";
    print(getComponent("fail").getValue());}]]></xp:this.action>
                <xp:this.onComplete><![CDATA[alert("first operation completed. starting second");
    document.getElementById("#{id:ihRetry}").value = "False";
    document.getElementById("#{id:button2}").click();]]></xp:this.onComplete>
                <xp:this.onError><![CDATA[if ( document.getElementById("#{id:ihRetry}").value == "False" ) {
        alert("first operation failed. retry again");
        document.getElementById("#{id:ihRetry}").value = "True";
        document.getElementById("#{id:button1}").click();
    } else {
        alert("first operation failed again. starting second");
        document.getElementById("#{id:ihRetry}").value = "False";
        document.getElementById("#{id:button2}").click();
    }]]></xp:this.onError>
            </xp:eventHandler>
        </xp:button>
        <xp:button value="Label" id="button2" style="display:none">
            <xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="label1">
                <xp:this.action><![CDATA[#{javascript:viewScope.status = "second operation completed";}]]></xp:this.action>
                <xp:this.onComplete><![CDATA[alert("second operation completed. starting third");
    document.getElementById("#{id:ihRetry}").value = "False";
    document.getElementById("#{id:button3}").click();]]></xp:this.onComplete>
                <xp:this.onError><![CDATA[if ( document.getElementById("#{id:ihRetry}").value == "False" ) {
        alert("second operation failed. retry again");
        document.getElementById("#{id:ihRetry}").value = "True";
        document.getElementById("#{id:button2}").click();
    } else {
        alert("second operation failed again. starting third");
        document.getElementById("#{id:ihRetry}").value = "False";
        document.getElementById("#{id:button3}").click();
    }]]></xp:this.onError>
            </xp:eventHandler>
        </xp:button>
        <xp:button value="Label" id="button3" style="display:none">
            <xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="label1">
                <xp:this.action><![CDATA[#{javascript:viewScope.status = "third operation completed";}]]></xp:this.action>
                <xp:this.onComplete><![CDATA[alert("third operation completed.");
    document.getElementById("#{id:ihRetry}").value = "False";]]></xp:this.onComplete>
                <xp:this.onError><![CDATA[if ( document.getElementById("#{id:ihRetry}").value == "False" ) {
        alert("third operation failed. retry again");
        document.getElementById("#{id:ihRetry}").value = "True";
        document.getElementById("#{id:button3}").click();
    } else {
        alert("third operation failed again. end");
        document.getElementById("#{id:ihRetry}").value = "False";
    }]]></xp:this.onError>
            </xp:eventHandler>
        </xp:button>
        <xp:inputHidden id="ihRetry">
            <xp:this.value><![CDATA["False"]]></xp:this.value>
        </xp:inputHidden>
        <xp:label value="#{viewScope.status}" id="label1"></xp:label>
    </xp:view>
    
    
    
    谢谢您的回答。我参与了多个项目,所以我最终会让这个工作顺利进行,并接受最好的答案。谢谢你的回答。我参与了多个项目,因此我最终会让这个问题得到解决,并接受最佳答案。您不会碰巧有使用部分刷新的代码示例。使用示例代码更新了我的答案。ssjs代码打印(getComponent(“fail”).getValue();用于使操作失败。您还可以将ihRetry的逻辑更改为count,而不是true或false,以获得n次重试。感谢您提供代码示例。我不是在使用警报,而是在后端更新一个字段。警报用于显示演示阶段,您可以使用SSJS事件(我在其中设置viewScope.status)来更新后端中的字段值。您不会碰巧有使用pa的代码示例