Monday, October 25, 2010

Using Image as a submit button



name="downloadFormPOST"
method="post"
action="http://theurl"
>




function openElt() {

var jsonRequest =
{
"template": {
"id": [currentQueryParams.identifier],
"class": "com.erdas.rsp.babel.model.CatalogItem"
},
"maxresults": -1,
"profile": "eac-brief"
};

var AjaxObject = {

handleSuccess:function(o) {
var xmlToDownload = o.responseText;
var downloadForm = window.document.forms['downloadFormPOST'];

var xmlInput = document.getElementById("xmlToDownload");
xmlInput.value = xmlToDownload;
downloadForm.submit();

},


handleFailure:function(o) {
},


startRequest:function() {

var jsonString = YAHOO.lang.JSON.stringify(jsonRequest);
YAHOO.util.Connect.initHeader('Accept', 'application/x-vnd.elt+xml; charset=utf-8', true);
YAHOO.util.Connect.asyncRequest('POST',
'http://<%=request.getServerName()%>:<%=request.getServerPort()%>/erdas-apollo/catalog/content/search',
callback,
jsonString
);
}

};


var callback = {
success:AjaxObject.handleSuccess,
failure:AjaxObject.handleFailure,
scope: AjaxObject
};


AjaxObject.startRequest();
}


<%
String xmlToDownload = request.getParameter("xmlToDownload");
if( xmlToDownload != null && !"".equals(xmlToDownload) ) {

response.setContentType("application/x-vnd.elt+xml; charset=utf-8");
String outputExtension = "elt";
String nowStr = new SimpleDateFormat("yyyy_MM_dd-HH_mm_ss").format(new Date());
response.setHeader("Content-Disposition", "attachment; filename=results-" + nowStr + "." + outputExtension);
PrintWriter writer = response.getWriter();
writer.println(xmlToDownload);
}
%>

No comments:

Post a Comment