【问题标题】:Redirect in primefaces Issue在 primefaces 问题中重定向
【发布时间】:2018-09-12 12:08:32
【问题描述】:

您好,我遇到了重定向问题。

我有一个 API,当我点击图片时会调用它,它会获取用户联系号码并从软件拨打电话。

一切正常,但问题是,API 重定向到我不想要的其他页面。

我只想显示呼叫消息,但焦点应保持在同一页面上。

这是我的 xhtml 代码

Cell No.
                                            <h:outputText value="#{informationManagerBean.cust.cellNo}" styleClass="textColorChange"/>
                                            Direct Dial

                                            <h:outputLink style="margin: 25px" id="tool_dial"  onclick="PF('callDialog').show();
                                                    {
                                                        return true;
                                                    }" value="http://199.199.333.94/calling.php" >
                                                <img src="Resources/images/dialer.png" alt="NR Letter" align="top" style="margin: 25px"/>
                                                <f:param name="cli"  value="#{informationManagerBean.cust.cellNo}"  />
                                                <f:param name="userid"  value="000001"  />
                                            </h:outputLink>
                                            <p:dialog id="callDialog1" onShow="myFunction();" onHide="myStopFunction();"  header="Calling..."
                                                      width="200px" widgetVar="callDialog"
                                                      position="center" draggable="true" resizable="false" closable="false"
                                                      closeOnEscape="true" appendTo="@(body)" modal="true">


                                            </p:dialog>

这里是 java 脚本:

<script>
        var myVar;

        function myFunction()
        {
            myVar = setTimeout(function() {
                PF('callDialog').hide()
            }, 3000);
        }

        function myStopFunction()
        {
            clearTimeout(myVar);
        }

    </script>

谢谢

【问题讨论】:

  • 你试过onclick="PF('callDialog').show(); return false;"吗? return false 抑制进一步的操作,即 goto href。
  • @Holger in outlin 我用过,如果我用false它不会拨打电话,只显示消息
  • 啊,抱歉,calling.php 执行调用....
  • &lt;p:commandLink actionListener="#{mybean.mycallFn()}" ajax="true" partialSubmit="true" process="@this" oncomplete="PF('callDialog').show()"/&gt; 和 mybean.mycallFn() 你使用 URLConnection 就像在答案中
  • @Holger 喜欢答案吗?

标签: javascript php html jsf primefaces


【解决方案1】:

通过这样的功能,您可以从 bean 中触发您的拨号器

public int doCall(String cli, String userid) {
  HttpURLConnection conn = (HttpURLConnection) new URL("http://199.199.333.94/calling.php?cli="+cli+"&userid="+userid).openConnection();
  conn.setDoOutput(false);
  int responseCode = conn.getResponseCode();
  conn.disconnect();
  return responseCode;
}

【讨论】:

    【解决方案2】:

    h:outputLink 应该重定向到另一个 uri。我建议您从托管 bean 调用 http://199.199.333.94/calling.php 上的 REST api,您可以通过 p:commandLinkp:commandButton 引用它。 ajax 调用将阻止重定向到 api 的 uri。

    编辑:

    有关从 java 进行 http 调用的示例,请参见以下内容 How to use java.net.URLConnection to fire and handle HTTP requests

    Primefaces 命令链接https://www.primefaces.org/showcase/ui/button/commandLink.xhtml

    【讨论】:

    • 你能给我举个例子如何称呼它吗?
    猜你喜欢
    • 1970-01-01
    • 2018-07-19
    • 2011-02-04
    • 2015-12-12
    • 1970-01-01
    • 1970-01-01
    • 2021-03-30
    • 2021-03-28
    相关资源
    最近更新 更多