p:commandButton与p:fileDownload并且没有ajax只能在第二次点击 [英] p:commandButton with p:fileDownload and no ajax only works in second click
问题描述
我正在面对这个链接的人的类似问题: href =https://stackoverflow.com/questions/11618450/hcommandbutton-works-from-the-second-click> h:commandButton从第二次点击工作。
像他一样,我没有在< p:commandButton>
中使用ajax,但是我正在使用 p:fileDownload />
在按钮标签内。
我有两个视图:list.xhtml和downloadView.xhtml。在 myBean.java
我从视图list.xhtml发送一个DataModel来查看downloadView.xhtml作为请求属性,如下面的代码所示:
FacesUtil.getServletContext()。setAttribute(myDataModelFromRequest,this.myDataModel);
该bean被标记为 @Scope(view)
在downloadView.xhtml视图中,我成功填充了一个dataTable,并从请求发送了DataModel。但是当我点击按钮下载文件时,会出现问题。它只适用于第二次尝试。
我已经尝试将我的方法的返回值从null更改为downloadView,但问题没有解决。
在调试模式下,我注意到只有输入在downloadMethod()中第二次点击。
任何人都有一个想法来解决?
myBean.java
public String viewListMethod(){
// some在这里工作...
FacesUtil.getServletContext()。setAttribute(myDataModelFromRequest,this.myDataModel);
返回downloadView;
}
downloadView.xhtml
< h:form id =formIdprependId =false>
< p:dataTable
id =dataTableIdvar =myVarvalue =#{myDataModelFromRequest}
selection =#{cargaProcessoControlador.myArray}
paginator =truerows =10paginatorPosition =bottompaginatorAlwaysVisible =false>
< f:facet name =header>
bla bla bla
< / f:facet>
< p:column selectionMode =multiplestyle =width:18px/>
// collumns here ...
< / p:dataTable>
< p:commandButton id =btDownloadajax =falsevalue =下载icon =ui-icon-document>
< p:fileDownload value =#{myBean.downloadMethod()}/>
< / p:commandButton>
< / h:form>
春天的范围视图不存在所以你创建了自己的,对吧?只是为了检查...
我有这样的问题一次,我认为这是与验证有关...
immediate = true属性解决了我的问题。
I'm using JSF 2.0, Primefaces 3.4.2, Spring 3.1.2.
I'm facing a similar problem of the guy of this link: h:commandButton works from the second click.
Like him I'm not using ajax in the <p:commandButton>
but I'm using a <p:fileDownload />
inside the button tag.
I have two views: "list.xhtml" and "downloadView.xhtml". In myBean.java
I send a DataModel from view "list.xhtml" to view "downloadView.xhtml" as a request attribute as shown in the code below:
FacesUtil.getServletContext().setAttribute("myDataModelFromRequest", this.myDataModel);
The bean is anotted with @Scope("view")
In view "downloadView.xhtml" I populated succesfully a dataTable with the DataModel sent from request. But the problem happens when I click in the button to download the file. It only works on second try. I already tried to change the return of my method from null to "downloadView" but the problem was not solved.
In debug mode I noticed that only enter in the "downloadMethod()" on second click.
Anyone have an idea to solve it?
myBean.java
public String viewListMethod() {
//some work here...
FacesUtil.getServletContext().setAttribute("myDataModelFromRequest", this.myDataModel);
return "downloadView";
}
downloadView.xhtml
<h:form id="formId" prependId="false">
<p:dataTable
id="dataTableId" var="myVar" value="#{myDataModelFromRequest}"
selection="#{cargaProcessoControlador.myArray}"
paginator="true" rows="10" paginatorPosition="bottom" paginatorAlwaysVisible="false">
<f:facet name="header">
bla bla bla
</f:facet>
<p:column selectionMode="multiple" style="width:18px" />
//collumns here...
</p:dataTable>
<p:commandButton id="btDownload" ajax="false" value="Download" icon="ui-icon-document" >
<p:fileDownload value="#{myBean.downloadMethod()}" />
</p:commandButton>
</h:form>
The scope "view" on spring doesn´t exist... So you created your own, right? Just to check... I had that kind of problem once, and I think it was something to do with validation... the immediate=true attribute solved my problem.
这篇关于p:commandButton与p:fileDownload并且没有ajax只能在第二次点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!