【问题标题】:How to use command link to link to complete action AND then direct user to a URL - JSF (NetBeans)如何使用命令链接链接到完成操作,然后将用户定向到 URL - JSF (NetBeans)
【发布时间】:2014-11-27 22:21:34
【问题描述】:

我怎样才能做到这一点,以便在用户单击弹出框上的“确定”时,除了执行 .java 文件中的命令之外,我的命令链接还将链接到 URL

       <h:commandLink
                       onclick = "if (! confirm ('Are you sure?')) return false"
                       value ="VALUE"
                       action ="#{bean.setBooked(item)}"
                       rendered = "#{item.booked >0}">
      </h:commandLink>

以及java文件中的可执行代码

    public void setBooked (Shop shop)
   { int booking=plot.getBooked();
   plot.setBooked(booking-1);
   updateEntity(plot);
   }

我想让它在用户确认 OK 按钮后被重定向到订单完成页面。我该怎么办?

谢谢。

【问题讨论】:

  • 只需通过 h:commandLink 操作返回您要导航到的页面名称。

标签: java html jsf netbeans


【解决方案1】:

只需从 action 方法返回 String,而不是 void。它将作为标准导航规则处理。

public String setBooked (Shop shop) {
    int booking=plot.getBooked();
    plot.setBooked(booking-1);
    updateEntity(plot);
    return "orderComplete"
}

相当于action="orderComplete"上的&lt;h:commandLink&gt;。

【讨论】:

  • 嗨,当我添加 return "orderComplete.xhtml" 时,我得到了 "unexpected return value"
  • @tyronejavajava 不需要 .xhtml,如果这是您的页面名称,请尝试使用“orderComplete”。请查看 this 以获取 JSF 2 导航规则示例。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多