Save gridweb as stream in java from a bean class

Hi,

I want to add a button under gridweb from where to download the gridweb stream or to the xls to a specific path, the method being implemented in a primefaces bean.
Is this possible?

Thank you!

@nenciuioa,

Could you please elaborate your requirements/issue more. What issue you are facing in your current scenario/case, share your sample code for reference. Do you need to render to XLSX (from GridWeb matrix) on a custom button’s click?

I attach the page here:
image.png (159.5 KB)
the bean method I want to call is:
image.png (44.3 KB)

The parameter gridweb is null, my question is how can I make this connection between these two, to call the bean function with gridweb as parameter

@nenciuioa,

I guess if you need to obtain GridWeb data from a custom command button, you need to register your command button to sink events for getting GridWeb data. This is a line we can normally use on Page_Load event in ASP.NET, e.g.
Button1.Attributes["onclick"] = "GridWeb1.updateData(); return GridWeb1.validateAll();";
so, you may write parallel java code for it at some place where you do initialization for the objects/controls.

1 Like

Can you please show me the Javascript code that the button calls, please?
Thank very much for your help!

@nenciuioa,

We will get back to you soon.

1 Like

we can achiev it through custom button,
here is .net version guide.

however ,there is a bug CELLSJAVA-44838 in java version when using custom command buttons.

We 've fixed it in v22.8.1 .
We will publish the java release version 22.9 in next month.
We will also update the demo in Github and add the java document guide

thank you,
but can it be achieved by adding an external button, not as component in the grid, just on the page? and after get the right instance of the GridWebBean to have the gridweb object in java class?

@nenciuioa,

Ok, we will get back to you to provide assistance on achieving your task via external command button.

1 Like

in page:add a button to trigger js:
//here mycomponent is the gridweb div id ,the second parameter ,just use false is ok
//get gridweb instance and call postBack function
document.getElementById(‘mycomponent’).postBack(‘CCMD:hello’,false);
in servlet

  class MyCommandEventHandler implements CustomCommandEventHandler,Serializable{
	 
 
	private static final long serialVersionUID = 1L;

	@Override
	public void handleCellEvent(Object sender, String command) {
		GridWebBean gridweb = (GridWebBean) sender;
               //do some thing here ,and get command: hello will be printed
		System.out.print("get command:"+command+"  "+gridweb.getActiveSheet().getName());
		gridweb.getActiveSheet().getCells().get("F9").putValue(command);
		
	}

}
 gridweb.CustomCommand=new MyCommandEventHandler();

Here I have my java class:
public class SaveGridWebServlet implements CustomCommandEventHandler,Serializable{

private static final long serialVersionUID = 1L;

@Override
public void handleCellEvent(Object sender, String command) {
GridWebBean gridweb = (GridWebBean) sender;
//do some thing here ,and get command: hello will be printed
System.out.print(“get command:”+command+" "+gridweb.getActiveSheet().getName());
gridweb.getActiveSheet().getCells().get(“F9”).putValue(command);

}

// gridweb.CustomCommand=new SaveGridWebServlet();
}

this is how I called it from the button:


<h:form id=“gridwebForm”
onkeypress=“if (event.keyCode == 13) { return false; }”>
<p:commandButton value=“Back” action="#{nodesBean.backHome}" styleClass=“gridwebButton”
process="@this" />
<p:commandButton value=“Save” onclick=“document.getElementById(‘gridweb’).postBack('CCMD:hello’,false);” styleClass=“gridwebButton”
process="@this" />
</h:form>

It does not seem to call the method when clicking on the button. Have I added it wrongly?
thank you for your support!

please provide your page file.
only normal html button is enough, do not use p:commandButton
just something like:

<button onclick=“document.getElementById(‘gridweb’).postBack('CCMD:hello’,false);console.log('click happen');”>test save</button>

it does not need any form.

1 Like

This is my page file, it is an .xhtml file.

<f:view xmlns=“XHTML namespace”
xmlns:ui=“Oracle Java Technologies | Oracle”
xmlns:f=“Oracle Java Technologies | Oracle”
xmlns:h=“Oracle Java Technologies | Oracle”
xmlns:custom=“http://siemens.com/jsf/component/tags”
xmlns:p=“UI Kit Licenses – PrimeFaces” contentType=“text/html”
locale=“#{identity.locale}”>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">

<h:head>

<link rel="stylesheet" type="text/css" href="grid/acw_client/menu.css" />
<link rel="stylesheet" type="text/css" href="Scripts/jquery-ui.css" />


<script src="grid/acw_client/acwmain.js" type="text/javascript"></script>
<script src="grid/acw_client/lang_en.js" type="text/javascript"></script>
<script src="Scripts/jquery-2.1.1.js" type="text/javascript"></script>
<script src="Scripts/jquery-ui.js" type="text/javascript"></script>
<script src="grid/acw_client/jquery-1.7.2.min.js"
	type="text/javascript"></script>

<script>
	function doClick(method) {
		$.post("FunctionServlet", {
			flag : method.id,
			gridwebuniqueid : $("#mycomponent").attr("webuniqueid")
		}, function(data) {
			$("#Stylemycomponent").remove();
			$("#gridweb").html(data);
		}, "html");
	}

	$(document).ready(function() {

		//loadHead();//

		var method = {
			id : "autoFilter"
		};
		doClick(method);
	});
	
	
	
</script>

</h:head>
<h:body>

<div id="gridweb"></div>
<h:form id="gridwebForm"
	onkeypress="if (event.keyCode == 13) { return false; }">
	<p:commandButton value="Back" action="#{nodesBean.backHome}" styleClass="gridwebButton"
		process="@this" />
	<p:commandButton value="Save" onclick="document.getElementById('gridweb').postBack('CCMD:hello',false);" styleClass="gridwebButton"
		process="@this" />
</h:form>

</h:body>

</f:view>

In your page gridweb div id is: mycomponent

so you need to write : document.getElementById(‘mycomponent’).postBack('CCMD:hello’,false);

1 Like
  <div id="gridweb"></div>
    <button onclick=“document.getElementById(‘mycomponent’).postBack('CCMD:hello’,false);console.log('click happen');”>test save</button>
1 Like

Tried this way, thank you, on browser console it is printed the ‘click happenned’ text, but on the server side, the java method is not called

springdemo.zip (858.2 KB)
open and run the project
navigate to
http://localhost:8080/gridwebdemo/commandbutton
uncheck “show save button”
then click the " test button"

Hi Peter,
I have a question: with what version of aspose-cells should I try it in order to work?
Thank you very much for help!

@nenciuioa,

Please try using latest Aspose.Cells.GridWeb (Java) with latest resource files.