JSF h:在GET之前的outputLink调用bean方法

时间:2015-04-28 12:48:07

标签: jsf primefaces

我需要将一些参数从一个xhtml发送到另一个xhtml,但我不希望这些参数出现在URL中。怎么做?我可以使用p:commandLink,但后来我不知道如何从bean方法打开目标页面。目标页面应该可以通过友好的URL访问,而不是通过xhtml名称访问。 此代码将打开页面/用户/视图。如何在不显示参数的情况下发送参数?

   <h:outputLink value="/users/view">
      <h:outputText value="#{entry.employee}" />
   </h:outputLink>

1 个答案:

答案 0 :(得分:1)

忽略strange design,您可以使用flash scope中的数据并使用<h:commandLink>操作方法发送redirect

public void view() throws IOException {
    ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
    ec.getFlash().put("employee", employee);
    ec.redirect(ec.getRequestContextPath() + "/users/view");
}

然后在与目标页面关联的支持bean中:

@PostConstruct
public void init() {
    ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
    employee = (Employee) ec.getFlash().get("employee");
}

另见:

相关问题