a bouchenafa
a bouchenafa

Reputation: 272

vaadin generated page doesnt show any component

I have a problem at vaadin framework in general.

I created a class extends vaadin application(MyFirst), after that I created a custom component with vaadin visual designer(MyFormApp).

I did instantiate the custom component MyFormApp, and I added it to the main window of the MyFirst.

After deploying the app, the page generated by vaadin does not show any component.

My code :

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.example.vaadin;

import com.vaadin.Application;
import com.vaadin.ui.*;

/**
*
* @author anis.bouchenafa
*/
public class MyFirst extends Application{


private Button newContact = new Button("Add contact");
private Button search = new Button("Search");
private Button share = new Button("Share");
private Button help = new Button("Help");
private HorizontalSplitPanel horizontalSplit = new HorizontalSplitPanel();
private TextField tf = new TextField();

@Override
public void init() {
    //buildMainLayout();

    MyFirstApp a = new MyFirstApp();
   Window w = new Window("aness conf");
   w.addComponent(a);
   setMainWindow(w);


}

}

my second class is MyFirstApp (custom componant):

package com.example.vaadin;



import com.vaadin.annotations.AutoGenerated;
import com.vaadin.ui.AbsoluteLayout;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.LoginForm;

public class MyFirstApp extends CustomComponent {

@AutoGenerated
private AbsoluteLayout mainLayout;
@AutoGenerated
private LoginForm loginForm_2;

/*- 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 MyFirstApp() {
    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%");

    // top-level component properties
    setWidth("100.0%");
    setHeight("100.0%");

    // loginForm_2
    loginForm_2 = new LoginForm();
    loginForm_2.setStyleName("v-loginform");
    loginForm_2.setImmediate(false);
    loginForm_2.setWidth("340px");
    loginForm_2.setHeight("-1px");
    mainLayout.addComponent(loginForm_2, "top:160.0px;left:200.0px;");

    return mainLayout;
}

}

after the execution of the servlet nothing shows up at browser.

Upvotes: 0

Views: 3639

Answers (3)

micebrain
micebrain

Reputation: 576

With AbsoluteLayout, you need to define the position of display for the components for example:

mainLayout = new AbsoluteLayout();
mainLayout.setWidth("400px");
mainLayout.setHeight("350px");

For more info, refers to: https://vaadin.com/book/-/page/layout.absolutelayout.html

Upvotes: 2

LivePwndz
LivePwndz

Reputation: 616

I had the same problem when using the Visual Editor in Vaadin 7. However, if you change the Layout property from AbsoluteLayout to any other Layout, (i.e GridLayout, HorizontalLayout or VerticalLayout). The component shows. Hope that helps.

Upvotes: 0

luuksen
luuksen

Reputation: 1365

well, you call buildMainLayout() what is visually empty. it only contains an AbsoluteLayout and a LoginForm() without any components in it. It's like generating a borderless HTML table and not add any text.

Your components I think you wanted to add

private Button newContact = new Button("Add contact");
private Button search = new Button("Search");
private Button share = new Button("Share");
private Button help = new Button("Help");
private HorizontalSplitPanel horizontalSplit = new HorizontalSplitPanel();
private TextField tf = new TextField();

should

  1. be declared and initialized in your "class MyFirstApp" and
  2. be added to your layout via addComponent()

Layouts in detail (and other basics) are also explained in Book of Vaadin:

Book of Vaadin: https://vaadin.com/book/-/page/intro.html

Book of Vaadin - Layouts: Layout:https://vaadin.com/book/-/page/layout.html

Vaadin Layout Examples: http://demo.vaadin.com/sampler#Layouts

Upvotes: 1

Related Questions