Unable to use Visual Editor to create a portlet

Hello Experts,

I have created a simple portlet using Vaadin,and it works fine.

But when i try to create the same portlet using Visual Editor, i get the following error

 com.test.SapDemoApp cannot be cast to com.vaadin.Application
javax.portlet.PortletException: java.lang.ClassCastException: com.test.SapDemoApp cannot be cast to com.vaadin.Application

I have searched on the net,but i cannot find appropriate solution for this.
please help me solving this issue.

Regards
Nikhil

Did you try to create the application class using the visual editor?

Visual editor creates CustomComponents, not applications. You can add the component to your (separately written) application or even set it as the content of the application, though.

Hello Henri,

No,i did not.

I created a normal custom component.Following is the code which I’m trying to deploy to liferay.



package com.test;


import com.vaadin.annotations.AutoGenerated;
import com.vaadin.ui.Button;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;

public class SapDemoApp extends CustomComponent {

	@AutoGenerated
	private VerticalLayout mainLayout;
	@AutoGenerated
	private Button button_1;
	@AutoGenerated
	private TextField textField_4;
	@AutoGenerated
	private TextField textField_3;

	/*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */


	
	

	/*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

	/**
	 * The constructor should first build the main layout, set the
	 * composition root and then do any custom initialization.
	 *
	 * The constructor will not be automatically regenerated by the
	 * visual editor.
	 
	 */

	public SapDemoApp()  {
		buildMainLayout();
		
		// TODO add user code here
	}

	@AutoGenerated
	private VerticalLayout buildMainLayout() {
		// common part: create layout
		mainLayout = new VerticalLayout();
		mainLayout.setImmediate(false);
		mainLayout.setWidth("100%");
		mainLayout.setHeight("100%");
		mainLayout.setMargin(false);
		
		// top-level component properties
		setWidth("100.0%");
		setHeight("100.0%");
		
		// textField_3
		textField_3 = new TextField();
		textField_3.setImmediate(false);
		textField_3.setWidth("-1px");
		textField_3.setHeight("-1px");
		textField_3.setSecret(false);
		mainLayout.addComponent(textField_3);
		
		// textField_4
		textField_4 = new TextField();
		textField_4.setImmediate(false);
		textField_4.setWidth("-1px");
		textField_4.setHeight("-1px");
		textField_4.setSecret(false);
		mainLayout.addComponent(textField_4);
		
		// button_1
		button_1 = new Button();
		button_1.setCaption("Button");
		button_1.setImmediate(true);
		button_1.setWidth("-1px");
		button_1.setHeight("-1px");
		mainLayout.addComponent(button_1);
		
		return mainLayout;
	}


}

I’m very new to Vaadin and Liferay platforms.Please guide me through this.

Thanks and Regards
Nikhil

Still it looks like you try to point the “application” parameter in your portlet.xml to this class.

Instead, it should point to something like the new application class created by the Eclipse plug-in when you created the project, where you use mainWindow.setContent(new MyVisuallyComposedComponent()) - or addComponent(…) if you want also other content in the window.

Thanks Henri.

Your answer helped me in resolving the error.Now I have a new problem.

When i deploy the application, Liferay portal shows nothing.Following is the detailed code attached.

1.SapVaadinApplication

public class SapVaadinApplication extends Application {
	
    public void init() {
    	SapDemo sap =new SapDemo();
   	 Window window = new Window("Vaadin Portlet Application");
    	
        window.addComponent(new Label("Hello Vaadin user!"));
        window.setContent(sap);
        setMainWindow(window);
        sap.afterApplicationSet();
        //window.addComponent(sap);
               
    } 
}

2.CustomComponent

public class SapDemo extends CustomComponent {

	@AutoGenerated
	private AbsoluteLayout mainLayout;
	@AutoGenerated
	private TextField textField_2;
	@AutoGenerated
	private TextField textField_1;
	@AutoGenerated
	private Button button_1;
	
	public SapDemo() {
		buildMainLayout();
		setCompositionRoot(mainLayout);

		// TODO add user code here
	}

	@AutoGenerated
	private AbsoluteLayout buildMainLayout() {
		// common part: create layout
		mainLayout = new AbsoluteLayout();
		mainLayout.setImmediate(false);
		mainLayout.setWidth("100%");
		mainLayout.setHeight("100%");
		mainLayout.setMargin(false);
		
		// top-level component properties
		setWidth("100.0%");
		setHeight("100.0%");
		
		// button_1
		button_1 = new Button();
		button_1.setCaption("Button");
		button_1.setImmediate(false);
		button_1.setWidth("-1px");
		button_1.setHeight("-1px");
		mainLayout.addComponent(button_1, "top:154.0px;left:40.0px;");
		
		// textField_1
		textField_1 = new TextField();
		textField_1.setImmediate(false);
		textField_1.setWidth("-1px");
		textField_1.setHeight("-1px");
		textField_1.setSecret(false);
		mainLayout.addComponent(textField_1, "top:60.0px;left:23.0px;");
		
		// textField_2
		textField_2 = new TextField();
		textField_2.setImmediate(false);
		textField_2.setWidth("-1px");
		textField_2.setHeight("-1px");
		textField_2.setSecret(false);
		mainLayout.addComponent(textField_2, "top:120.0px;left:23.0px;");
		
		return mainLayout;
	}
}
}

3.portlet.xml

<?xml version="1.0"?>

<portlet-app
	version="2.0"
	xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
>
	
	<portlet>
		<portlet-name>sapvaadin</portlet-name>
		<display-name>SapVaadin</display-name>
		<portlet-class>
			com.vaadin.terminal.gwt.server.ApplicationPortlet2
		</portlet-class>
		<init-param>
			<name>application</name>
			<value>com.test.SapVaadinApplication</value>
		</init-param>
		<expiration-cache>0</expiration-cache>
		<supports>
			<mime-type>text/html</mime-type>
			<portlet-mode>view</portlet-mode>
		</supports>
		<portlet-info>
			<title>SapVaadin</title>
			<short-title>SapVaadin</short-title>
			<keywords></keywords>
		</portlet-info>
		<security-role-ref>
			<role-name>administrator</role-name>
		</security-role-ref>
		<security-role-ref>
			<role-name>guest</role-name>
		</security-role-ref>
		<security-role-ref>
			<role-name>power-user</role-name>
		</security-role-ref>
		<security-role-ref>
			<role-name>user</role-name>
		</security-role-ref>
	</portlet>
</portlet-app>

Thanks and Regards
Nikhil Joshi

You should to set an explicit size (e.g. in pixels or using setSizeUndefined()) for the top level layout.

With your current code, the portal is probably not defining a size and your custom component defines height 100%, which gets calculated to 100% of 0 pixels as nothing else tells how big the layout or the portlet needs to be.

Thanks Henri.You solved my issue