Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Redirect 重定向jsf问题_Redirect_Jsf 2 - Fatal编程技术网

Redirect 重定向jsf问题

Redirect 重定向jsf问题,redirect,jsf-2,Redirect,Jsf 2,我在从a.xhtml重定向到b.xhtml时遇到问题 在localhost:8080/proyect/a.xhtml?idempresa=2&idcontrato=15中,我有一个初始化: @PostConstruct public void init() { HttpServletRequest request=(HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();

我在从a.xhtml重定向到b.xhtml时遇到问题

localhost:8080/proyect/a.xhtml?idempresa=2&idcontrato=15中,我有一个初始化:

@PostConstruct
public void init() {
    HttpServletRequest request=(HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
    setIdempresa(Integer.parseInt(request.getParameter("idempresa")));
    setIdcontrato(Integer.parseInt(request.getParameter("idcontrato")));
    ...... }
在我看来,重定向按钮如下所示

<p:commandButton  action="b.xhtml?faces-redirect=true" ajax="false" ... />

但是当我点击commandButton重定向时,它总是重新加载a.xhtml,没有参数作为localhost:8080/proyect/a.xhtml,因此它产生

java.lang.NumberFormatException:null 位于java.lang.Integer.parseInt(Integer.java:454) 在java.lang.Integer.parseInt(Integer.java:527)处 位于beans.MBcompletadoInter.init(MBcompletadoInter.java:83)

MBcompletadoInter是a.xhtml使用的支持bean的名称

欢迎提供任何建议(Y)


尝试在idempresa和idcontrato上使用调试输出。它打印什么?

是的,它的xhtml,但它就像命令按钮一样,刷新页面,不带参数!必须将ajax与?faces redirect=true结合使用才能导航到另一个页面。你能使用ajax吗?若否,原因为何?尝试使用b.xhtml?faces redirect=true作为操作中的方法的返回值=“#{bean.method}”,而不是作为操作的参数=“b.xhtml?faces redirect=true。或者:您可以使用一个简单的p:button而不是p:commandButton,如图所示:是的,这似乎会有所帮助,唯一的问题是我需要转换为整数,因为它们是字符串,我想这应该是一件大事!parseInt()应该解决问题将字符串转换为整数与使用p:commandButton还是p:button无关,是吗?使用“p:button”或“b.xhtml?faces redirect=true”作为操作方法的返回值是否有助于解决问题?