Vaadin 学习记录

窗口类:

Window

 

Java代码 复制代码
  1. Window

 

 

它主要用来显示。

每一个Application可以设置一个主窗口比如:

Window mainWindow = new Window(messageSource.getMessage( "main.window" , null ,Locale.CHINESE)); //message为国际化,如果直接输入中文则会乱码。
  1. setMainWindow(mainWindow);

 

Java代码 复制代码
  1. Window mainWindow = new Window(messageSource.getMessage( "main.window" , null ,Locale.CHINESE)); //message为国际化,如果直接输入中文则会乱码。
  2. setMainWindow(mainWindow);

 


还可以向主窗口添加多个子窗口如:

Window window= new Window(messageSource.getMessage( "child.window.helloworld" , null , Locale.CHINESE));
  1. mainWindow.addWindow(window);

 

Java代码 复制代码
  1. Window window= new Window(messageSource.getMessage( "child.window.helloworld" , null , Locale.CHINESE));
  2. mainWindow.addWindow(window);

 


可以设置这个窗口的icon

mainWindow.setIcon(icon) //这里需要一个Resource对象来加载图片,Resource的子类中有一个FileResource他的构造需要两个参数,一个是File,一个Application这里如果本身就是在Application 内直接填入this即可如:

 

Java代码 复制代码
  1. mainWindow.setIcon(icon) //这里需要一个Resource对象来加载图片,Resource的子类中有一个FileResource他的构造需要两个参数,一个是File,一个Application这里如果本身就是在Application 内直接填入this即可如:

 

mainWindow.setIcon( new FileResource( new File( "" ), this ));

 

Java代码 复制代码
  1. mainWindow.setIcon( new FileResource( new File( "" ), this ));

 

是当前窗口显示后,背后的窗口变为不可使用。

window.setModal(true);

 

Html代码 复制代码
  1. window.setModal(true);

 

设置是否可以拖拉窗口大小

window.setResizable( false );

spring +vaadin spring ioc依赖注入

package com.xq.vaadin;
import javax.annotation.Resource;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.vaadin.Application;
import com.vaadin.terminal.gwt.server.AbstractApplicationServlet;
import com.vaadin.ui.Window;
@SuppressWarnings("serial")
public class SimpleAddressBook extends AbstractApplicationServlet {
private Class<? extends Application> clazz;
@Override
public void init(ServletConfig config) throws ServletException{
super.init(config);
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(
config.getServletContext());
ResourceBundleMessageSource messageSource=(ResourceBundleMessageSource)wac.getBean(ResourceBundleMessageSource.class);
System.out.println(messageSource);
com.xq.controller.HelloWorld application = (com.xq.controller.HelloWorld) wac.getBean(com.xq.controller.HelloWorld.class);

clazz = application.getClass();
}
@Override
protected com.xq.controller.HelloWorld getNewApplication(HttpServletRequest request)
throws ServletException {
// TODO Auto-generated method stub
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession().getServletContext());
return (com.xq.controller.HelloWorld) wac.getBean(com.xq.controller.HelloWorld.class);
}
@Override
protected Class<? extends Application> getApplicationClass()
throws ClassNotFoundException {
// TODO Auto-generated method stub
return clazz;
}

}

WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession().getServletContext());return (com.xq.controller.HelloWorld) wac.getBean(com.xq.controller.HelloWorld.class);

这个是通过类去找bean.

在web。xml中

<servlet>
<servlet-name>HelloWorde</servlet-name>
<servlet-class>com.xq.vaadin.SimpleAddressBook</servlet-class>
<init-param>
<param-name>application</param-name>
<param-value>com.xq.vaadin.HelloWorld</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorde</servlet-name>
<url-pattern>/VAADIN2/*</url-pattern>
</servlet-mapping>

 

 

spring 中国际化,还有vaadin的页面配置:

<bean id="messageSource2" name="messageSource2" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="message-info"></property>
<property name="useCodeAsDefaultMessage" value="true"></property>
</bean>
<bean id="test" name="test" class="com.xq.controller.HelloWorld"></bean>

 

package com.xq.util;
import javax.servlet.ServletContext;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.vaadin.Application;
import com.vaadin.terminal.gwt.server.WebApplicationContext;
public class SpringContext {

private ApplicationContext context;

public void SpringContextHelper(Application application) {
ServletContext servletContext = ((WebApplicationContext) application.getContext()).getHttpSession().getServletContext();
context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
}

public Object getBean(final String beanRef) {
return context.getBean(beanRef);
}
public Object getBean(final Class class1){
return context.getBean(class1);
}
}

 

 

package com.xq.util;
import javax.servlet.ServletContext;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.vaadin.Application;
import com.vaadin.terminal.gwt.server.WebApplicationContext;
public class SpringContext {

private ApplicationContext context;

public void SpringContextHelper(Application application) {
ServletContext servletContext = ((WebApplicationContext) application.getContext()).getHttpSession().getServletContext();
context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
}

public Object getBean(final String beanRef) {
return context.getBean(beanRef);
}
public Object getBean(final Class class1){
return context.getBean(class1);
}
}

你可能感兴趣的:(学习)