简体   繁体   English

找出哪个XHTML页面称为托管bean的方法

[英]Find out which XHTML page called managed bean's method

我有托管bean,并希望根据哪个页面调用其中一个方法来划分逻辑,是否存在某种方式来实现这一点?

This is available by UIViewRoot#getViewId() . 这可以通过UIViewRoot#getViewId()

String viewId = FacesContext.getCurrentInstance().getViewRoot().getViewId();

I must however say that this is somewhat a smell. 但我必须说这有点气味。 Depending on the concrete functional requirement for which you thought that examining the calling XHTML page would be the right solution, there may be better ways to achieve the concrete functional requirement. 根据您认为检查调用XHTML页面将是正确解决方案的具体功能要求,可能有更好的方法来实现具体的功能要求。

I think in two approachs the first is to get the referer header from the Http request it may have the url from the requesting page 我认为在两种方法中,第一种方法是从Http请求获取referer头,它可能有来自请求页面的url

FacesContext.getCurrentInstance().getExternalContext().getRequestHeaderMap().get("referer")

Other option is to navigate sending parameters, for example adding the viewId as parameter in the query string, in jsf-2 you can send parameters when the page navigate using the 其他选项是导航发送参数,例如在查询字符串中添加viewId作为参数,在jsf-2中,您可以在页面导航时使用

I hope this will help you 我希望这能帮到您

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM