2014-01-11 13 views
1

我在sigma.js JavaScript庫中使用gexf文件格式在JSF中繪製圖形。在graph.xhtml文件中這樣片段標籤:如何在JSF中將xhtml gexf文件作爲XML下載或導出?

<?xml version="1.0" encoding="UTF-8"?> 
<ui:fragment xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:ui="http://java.sun.com/jsf/facelets"> 
    <gexf xmlns="http://www.gexf.net/1.2draft" version="1.2"> 

的sigma.js庫使用這樣的graph.xhtml:

sigInst.parseGexf('#{request.contextPath}/user/graph/graph.jsf'); 

我在UI保存gexf模板parogram使用ManagedBean以這種方式初始化graph.xhtml文件中的節點和邊緣值:

<ui:repeat value="#{graphInfoBean.edges}" var="edge" varStatus="indexVar"> 
       <edge id="#{indexVar.index}" source="#{edge.source}" target="#{edge.target}" 

一切工作正常,繪製圖表。 我希望用戶能夠將graph.xhtml文件下載/保存爲XML格式,以便能夠在Gephi等其他實用軟件中使用它。

我該如何做到這一點,所以我可以將xhtml文件轉換爲xml?

謝謝。

回答

1

使用preRenderView事件來改變頁面的標題:

<f:event type="preRenderView" listener="#{graphInfoBean.changeHeader}"/> 

和changeHeader功能是:

public void changeHeader() { 
    HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse(); 
    response.setHeader("content-disposition", "attachment;filename=testFile.xml"); 
    response.setContentType("text/xml"); 
} 
相關問題