【问题标题】:How to attach for example a #top reference to a <p:commandLink>?例如,如何将#top 引用附加到 <p:commandLink>?
【发布时间】:2014-01-21 01:48:13
【问题描述】:

我只是想知道如何将 #top 之类的引用附加到 commandLink 的目标操作?

在我的情况下,这个 &lt;p:commandLink&gt; 基本上位于 &lt;p:dataTable&gt; 中,并将行值设置为 bean 的 current-Property:

<p:commandLink ajax="false"
               action="#{bean.viewSomePage()}"
               value="#{record.name}">
        <f:setPropertyActionListener value="#{record}"
                                     target="#{bean.current}" />
</p:commandLink>

在 bean 中,viewSomePage()-Method 只是传递导航目标:

public String viewSomePage() {
    return "index?faces-redirect=true";
}

浏览器的地址栏显示index.xhtml。但是我怎样才能实现类似index.xhtml#statusis 的显示?

我想做的是根据这个answer链接&lt;p:tabView&gt;的特定&lt;p:tab&gt;。它已经在工作,但我无法通过&lt;p:commandLink&gt; 链接它。当然,我已经尝试简单地将其附加到viewSomePage()-Method 中,但没有成功。

感谢您的帮助!

【问题讨论】:

    标签: jsf-2 primefaces


    【解决方案1】:

    JSF 导航处理程序不支持此功能。最好的办法是手动调用 ExternalContext#redirect() 并使用所需的 URL 和所需的片段标识符:

    public void viewSomePage() throws IOException {
        ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
        ec.redirect(ec.getRequestContextPath() + "/index.xhtml#status");
    }
    

    或者,如果您碰巧已经使用 JSF 实用程序库 OmniFaces

    public void viewSomePage() throws IOException {
        Faces.redirect("index.xhtml#status");
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-04
      • 2015-04-10
      • 2012-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多