[英]Passing parameters by URL in JSF
I need to go to page by selecting data table row. 我需要通过选择数据表行转到页面。 Using ajax event have some problems.
使用ajax事件有一些问题。
FacesContext context = FacesContext.getCurrentInstance();
NavigationHandler navigationHandler = context.getApplication().getNavigationHandler();
navigationHandler.handleNavigation(context, null, "/views/questionnaires/viewDetails.xhtml?faces-redirect=true&questionnaireId=" + 1);
But also i need to pass parameter to target page bean. 但是我还需要将参数传递给目标页面bean。
@ManagedProperty(value = "#{param.questionnaireId}")
private Long questionnaireId;
And it's not working. 而且它不起作用。 How to do it correctly?
如何正确做?
The most obvious thing that needs to be done is that you need to include includeViewParams=true
in that URL for the parameter to survive the redirect. 需要做的最明显的事情是,您需要在该URL中包括
includeViewParams=true
,以使该参数在重定向后仍然有效。 So you'll have: 因此,您将拥有:
navigationHandler.handleNavigation(context, null, "/views/questionnaires/viewDetails.xhtml?faces-redirect=true&includeViewParams=true&questionnaireId=" + 1);
Another concern might be the scope of the target bean. 另一个问题可能是目标bean的范围。 Per JSF spec,
@ViewScoped
beans are not valid targets for #param
bean injection 根据JSF规范,
@ViewScoped
bean不是#param
bean注入的有效目标
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.