Question

I used gexf file format in sigma.js JavaScript library to draw graphs in JSF.

I saved gexf template in ui:fragment tag in graph.xhtml file in this way:

<?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">

The sigma.js library uses the graph.xhtml in this way:

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

The parogram uses a ManagedBean for initializing nodes and edges values in graph.xhtml file in this way:

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

Everything is working properly and the graph is drawn. I want the user to be able to download/save the graph.xhtml file into XML format so to be able to use it in other utility software like Gephi.

How do I do this so I can convert the xhtml file to xml?

Thanks.

Was it helpful?

Solution

use preRenderView event to change the header of page :

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

and the changeHeader function is :

public void changeHeader() {
    HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
    response.setHeader("content-disposition", "attachment;filename=testFile.xml");
    response.setContentType("text/xml");
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top