[英]why occur one desfase between JSF action calls?
我正在使用primefaces 3.5在Liferay 6.2的Portlet应用程序中工作,它有点像文档浏览器。 文档显示在datagrig中,每个元素都是一个链接,用于在新的浏览器选项卡中打开内容。
我当前的代码有效,但有一个很大的错误。 第一个clic不会打开文档,在新选项卡中打开portlet的html片段,第二个打开前一个。 更清楚地说:
我认为这不是执行顺序的问题,因为自第一个clic以来,日志会打印所选文档的正确信息
这是view.xhtml片段
<h:form>
<p:dataGrid var="document" value="#{documentBean.documents}" columns="5" rows="15">
<p:column>
<h:commandLink action="#{documentBean.openDocument}" target="_blank">
<f:setPropertyActionListener target="#{documentBean.selectedDocument}" value="#{document}" />
<p:fileDownload value="#{documentBean.content}" contentDisposition="inline" />
<h:outputText value="Open Document" />
</h:commandLink>
</p:column>
</p:dataGrid>
</h:form>
这是芒果豆最相关的部分
@ManagedBean(name = "documentBean")
@ViewScoped
public class DocumentBean {
private List<DocumentVO> documents;
private DocumentVO selectedDocument;
private StreamedContent content;
@EJB
private DocumentServiceIntegrator documentIntegrator;
private static final Log LOG = LogFactory.getLog(DocumentBean.class);
@PostConstruct
public void init() {
documents = documentIntegrator.getFolderContentByPath("/");
selectedDocument = new DocumentVO();
}
public String openDocument() {
LOG.info("Open document: " + selectedDocument.getId() + " (" + selectedDocument.getName() + ", " + selectedDocument.getMimeType() + ")");
byte[] bytes = documentIntegrator.getDocumentContentById(selectedDocument.getId());
LOG.info("Document content: " + (bytes != null ? bytes.length + " bytes" : "null"));
InputStream stream = new ByteArrayInputStream(bytes);
content = new DefaultStreamedContent(stream, selectedDocument.getMimeType(), selectedDocument.getName());
return null;
}
// getters and setters for: documents, selectedDocument and content
}
关于正在发生的事情以及如何解决的任何想法?
谢谢
我找到了一种解决方法,在view.xhtml中,我删除了h:commandLink的action属性,并在f:setPropertyActionListener之后添加了f:actionListener标记(顺序很重要)
<h:commandLink target="_blank">
<f:setPropertyActionListener target="#{documentBean.selectedDocument}" value="#{document}" />
<f:actionListener binding="#{documentBean.openDocumentActionListener}" />
<p:fileDownload value="#{documentBean.content}" contentDisposition="inline" />
<h:outputText value="Open Document" />
</h:commandLink>
在manage bean中,我使用StreamedContent创建逻辑创建了自定义ActionListener。
@ManagedBean(name = "documentBean")
@ViewScoped
public class DocumentBean {
private List<DocumentVO> documents;
private DocumentVO selectedDocument;
private StreamedContent content;
private ActionListener openDocumentActionListener;
@EJB
private DocumentServiceIntegrator documentIntegrator;
private static final Log LOG = LogFactory.getLog(DocumentBean.class);
@PostConstruct
public void init() {
documents = documentIntegrator.getFolderContentByPath("/");
selectedDocument = new DocumentVO();
openDocumentActionListener = createOpenDocumentActionListener();
}
public ActionListener createOpenDocumentActionListener() {
ActionListener actionListener = new ActionListener() {
@Override
public void processAction(ActionEvent arg0) throws AbortProcessingException {
LOG.info("Open document: " + selectedDocument.getId() + " (" + selectedDocument.getName() + ", " + selectedDocument.getMimeType() + ")");
byte[] bytes = documentIntegrator.getDocumentContentById(selectedDocument.getId());
LOG.info("Document content: " + (bytes != null ? bytes.length + " bytes" : "null"));
InputStream stream = new ByteArrayInputStream(bytes);
content = new DefaultStreamedContent(stream, selectedDocument.getMimeType(), selectedDocument.getName());
}
};
return actionListener;
}
// getters and setters for: documents, selectedDocument, content and openDocumentActionListener
}
我对对象内容不了解,似乎发生了什么事,似乎它是在已创建或准备好的动作中下载的。
希望这对某人有帮助,我不知道如何使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.