ZK - Open Source Ajax Java FrameworkZK - Open Source Ajax Java Framework

ZK spreadsheet - spreadsheet not displayed

rose83
21 Dec 2011 21:26:02 GMT
21 Dec 2011 21:26:02 GMT

I tried deploying the jsf appliction with zk spreadsheet. It displays just the xhtml but not the exel within it. Can you please troubleshoot? We are planning to opt zk into our project as its largely based on exel sheets.

samchuang
22 Dec 2011 02:00:09 GMT
22 Dec 2011 02:00:09 GMT

Hi

you could refer to ZK Spreadsheet As JSF Component

what's the JSF version you are using ? could you post you web.xml config about JSF ?

rose83
22 Dec 2011 17:03:32 GMT
22 Dec 2011 17:03:32 GMTHi Samchung , I had followed the process mentioned at site ZK Spreadsheet As JSF Component. I am pasting here my web.xml and xhtml contents. I created a seperate dynamic web project for this purpose and imported all the jars from zk lib, zk spreadsheet lib as mentioned here We are using 2.0.6 JSF,zk - zk-bin-5.0.9,zss-zss-bin-2.1.1. I have pasted the web.xml & xhtml below. My questions are as below- a) The zk tag is not being recognized. The zk & ZSS lib both have some common libs. The site asks to put everything under web-inf/lib which causes the common libs to be overriden b) The path of exel is not found. (I did try putting the exel inside web-inf, inside WebContent & directly under the project too) Can you tell me what Iam doing wrong.
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>myZsskJsf</display-name>
  <servlet>
		<description>The asynchronous update engine for ZK</description>
		<servlet-name>auEngine</servlet-name>
		<servlet-class>org.zkoss.zk.au.http.DHtmlUpdateServlet</servlet-class>
	</servlet>
	<servlet-mapping>
		<servlet-name>auEngine</servlet-name>
		<url-pattern>/zkau/*</url-pattern>
	</servlet-mapping>
	<servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:zk="http://www.zkoss.org/2005/zul">
    <h:head>
    <title>My First ZK Spreadsheet JSF application</title>
</h:head>
<h:body>
Hi


    <zk:spreadsheet id="myzss" src="HelloZSS.xlsx" width="100%"
        height="800px" maxrows="200" maxcolumns="40">
    </zk:spreadsheet>
</h:body>
    
    
</html>
samchuang
26 Dec 2011 01:13:24 GMT
26 Dec 2011 01:13:24 GMT

hi from the description, seems you have exception that could locate excel file ?

from this line src="HelloZSS.xlsx", you shall find exccel file under WebContent, if you wish to put file to WEB-INF, you could use src="/WEB-INF/HelloZSS.xlsx"

from the zul code, zk tag shall be xmlns:zk="http://www.zkoss.org/jsf/zss", refer to Using ZK Spreadsheet JSF Component

rose83
28 Dec 2011 18:11:21 GMT
28 Dec 2011 18:11:21 GMT

Hi ,

I tried putting the code in an existing jsf project and xhtml. In the existing xhtml i added xmlns:zk="http://www.zkoss.org/jsf/zss to the namespace and then added the code

<zk:spreadsheet id="myzss" src="/#{applicationScope.context}/t3resources/HelloZSS.xlsx" width="100%"
height="800px" maxrows="200" maxcolumns="40">
</zk:spreadsheet>

to the body.

Currenlty I am getting the below mentioned exception. None of the zss jsf component demo code in the site mention the declation of the below servlet on startup. Also Using ZK Spreadsheet JSF component doesnt share the faces-config,web.xml . Can you help.

Error Rendering View[/t3/Testmaps.xhtml]
org.zkoss.zk.ui.UiException: The Web manager not found. Make sure <load-on-startup> is specified for org.zkoss.zk.ui.http.DHtmlLayoutServlet
at org.zkoss.zk.ui.http.WebManager.getWebManager(WebManager.java:331)
at org.zkoss.zkplus.embed.Renders.render(Renders.java:116)
at org.zkoss.zkplus.embed.Renders.render(Renders.java:94)

rose83
28 Dec 2011 20:27:41 GMT
28 Dec 2011 20:27:41 GMT

Hi,

I added the below entries to the web.xml to fix the above error. But I am currently getting java.lang.NoClassDefFoundError: org/zkoss/zkex/ui/comet/CometServerPush.

The class CometServerPush is available in the other jars but I dont knw why its being referred from the above path where it doesnt exists in the zk. Can you help. I switched to zk and zss ee versions.

<servlet-name>zkLoader</servlet-name>
<servlet-class>org.zkoss.zk.ui.http.DHtmlLayoutServlet</servlet-class>
<init-param>
<param-name>update-uri</param-name>
<param-value>/zkau</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>zkLoader</servlet-name>
<url-pattern>*.xlsx</url-pattern>
</servlet-mapping>

samchuang
30 Dec 2011 05:07:50 GMT
30 Dec 2011 05:07:50 GMT

Hi

I think you need put zkex.jar in your project

rose83
30 Dec 2011 19:16:04 GMT
30 Dec 2011 19:16:04 GMT

Hi,

The zkex.jar is already in but the mentioned class is there only in zkmax and not in zkex. if you have one that has it can you share? I retracted from this process and wrote a ZKSpreadsheetTag class, taglib.xml and gave the configuration in the web.xml.

Its now recognizing the zk tag, applying properties etc. But inside the Render.renders method something is happening and Iam getting the error mentioned below. I have also pasted the code for the tag class, xml and web.xml herewith. Can you please troubleshoot. I am using Java 1.6, ZK ZSS - EE and Tomcat server.

ZKSpreadhsheetTag.class

package com.pearson.t3.customTags;

import java.io.IOException;
import java.io.Serializable;
import java.util.*;

import javax.faces.component.FacesComponent;
import javax.faces.component.UIComponentBase;
import javax.faces.context.*;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.zkoss.lang.Classes;
import org.zkoss.util.logging.Log;
import org.zkoss.zk.ui.GenericRichlet;
import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.metainfo.Property;
import org.zkoss.zk.ui.metainfo.PropertyNotFoundException;
import org.zkoss.zk.ui.util.Composer;
import org.zkoss.zkplus.embed.Renders;
import org.zkoss.zss.ui.Spreadsheet;
@FacesComponent(value="spreadsheet")
public class ZKSpreadsheetTag extends UIComponentBase{
  
	 private static final Log log = Log.lookup(ZKSpreadsheetTag.class);
	 private Spreadsheet spreadsheet;
	 
	 public String getFamily()
	    {
	        return "spreadsheet";
	    }

	    public Spreadsheet getSpreadsheet()
	    {
	        return spreadsheet;
	    }
	 
	 public void encodeBegin(FacesContext context) throws IOException {
		 ServletContext svlctx = (ServletContext)context.getExternalContext().getContext();
	        HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
	        HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
	        ResponseWriter responseWriter = context.getResponseWriter();
	      
	        
	        try {
	            Renders.render(svlctx, request,response, 
	                    new GenericRichlet() {  
	                        public void service(Page page) throws Exception {
	                        	spreadsheet = new Spreadsheet();
	                        	spreadsheet.setPage(page);
	                            applyProperties();
	                            spreadsheet.setId(getClientId());
	                            doAfterCompose();
	                        }
	                    }, null, responseWriter);
	            Object priya = new Object();
	        } catch (ServletException e) {
	        	 log.debug(e.getMessage());
	        	 System.err.println(e.getMessage());
	             throw new IOException(e.getMessage());
	        } catch(IOException e)
	        {
	        	System.err.println(e.getMessage());
	        	 throw new IOException(e.getMessage());
	        }
		 
	 }
	 
	 /** apply ZK component properties as retrieved from JSF custom component tag */
	    private void applyProperties() {
	        Map<String, Object> attrs = getAttributes();
	        Set<String> attrNames = attrs.keySet();
	         
	        for (Iterator iterator = attrNames.iterator(); iterator.hasNext();) {
	            String attrName = (String) iterator.next();
	            if(!"apply".equals(attrName)) {
	                try {
	                    Property.assign(spreadsheet, attrName, attrs.get(attrName).toString());
	                } catch(PropertyNotFoundException pnfe) {
	                   System.err.println(pnfe.getMessage());
	                }
	            }
	        }
	    }
	    
	    /** apply composer by calling doAfterCompose after ZK component is composed */
	    private void doAfterCompose() throws Exception {
	        Object o = getAttributes().get("apply");
	        if(o!=null)
	        {
//	          System.out.println("o class name"+o.getClass().getName());
		        if(o instanceof String) {
		            o = Classes.newInstanceByThread(o.toString());
		        }
		        if(o instanceof Composer) {
		            ((Composer)o).doAfterCompose(spreadsheet);
		        }
	        }
//	        System.out.println("Hi");
	        Object priya1 = new Object();
	    }
	    
	    
}


jsfzss-taglib.xml

<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd"
	version="2.0">
	<namespace>http://www.zkoss.org/jsf/zss</namespace>
	<tag>
		<tag-name>spreadsheet</tag-name>
		<component>
			<component-type>spreadsheet</component-type>
		</component>
	</tag>
</facelet-taglib>

web.xml

 <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
<servlet>
  	<description>
  	The asynchronous update engine for ZK</description>
  	<servlet-name>auEngine</servlet-name>
  	<servlet-class>
  	org.zkoss.zk.au.http.DHtmlUpdateServlet</servlet-class>
  </servlet>
  <!--  T3 changes - End -->  
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
  </servlet-mapping>
 <servlet-mapping>
  	<servlet-name>auEngine</servlet-name>
  	<url-pattern>/zkau/*</url-pattern>
  </servlet-mapping>
 <context-param>
		<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
		<param-value>/WEB-INF/jsfzss-taglib.xml</param-value>
	</context-param>


Error

SEVERE: Error Rendering View[/t3/Testmaps.xhtml]
java.io.IOException: Cannot inherit from final class
at com.pearson.t3.customTags.ZKSpreadsheetTag.encodeBegin(ZKSpreadsheetTag.java:80)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1611)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:848)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1613)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:380)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:126)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:127)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)