Hi all,
I would like to use the TouchKit with a JEE6-Backend on a JBoss AS 7.
I set up the Project with vaadin-6.8.6 and vaadin-touchkit-agpl-2.1.3
Therefore I created an own Servlet that extends the TouchKitServlet. The Servlet Loads the Touchkit Application that sets The MainWindow base on a TouchKitWindow that sets a TabBar. The Tabs are base on the NavigationManager with Navigation-Views.
I also set the MainWindow to immediat so all changes will be send directly.
Problem is everything I do is only updated after a Page refresh. Anyone any Idea?
Also the Icons are not loaded and display a Broken Image.
All worked before I tried to Include CDI.
With the Defautl TouchkitServlet and the “new SomeObject()” instead of the CDI @Inject all worked…
I am thankfull for any Hints.
MyServlet:
public class TouchkitVaadinServlet extends TouchKitApplicationServlet {
private static final long serialVersionUID = 1L;
@Inject
Instance<VaadinMobileApplication> application;
@Override
protected Application getNewApplication(HttpServletRequest request)
throws ServletException {
if (!isSupportedBrowser(request)) {
Application app = getNewFallbackApplication(request);
if (app != null) {
return app;
}
}
return application.get();
}
@Override
protected Class<? extends Application> getApplicationClass()
throws ClassNotFoundException {
return VaadinMobileApplication.class;
}
}
Application:
@SessionScoped
public class VaadinMobileApplication extends TouchKitApplication {
private static final long serialVersionUID = 1L;
@Inject
private MainWindow mainWindow;
public VaadinMobileApplication() {
super();
}
@Override
public void init() {
setMainWindow(mainWindow);
}
@Override
public void onBrowserDetailsReady() {
WebBrowser browser = getBrowser();
if (!browser.isTouchDevice()) {
getMainWindow().showNotification("You use a non TouchEnabled Browser");
}
if (isSmallScreenDevice()) {
getMainWindow().showNotification("You seem to use a Smartphone");
} else {
getMainWindow().showNotification("You seem to use a Tablet");
}
mainWindow.createView();
}
public boolean isSmallScreenDevice() {
float viewPortWidth = getMainWindow().getWidth();
return viewPortWidth < 720;
}
}
MainWindow:
@SessionScoped
public class MainWindow extends TouchKitWindow {
private static final long serialVersionUID = 1L;
@Inject
private ShopUI shopUI;
@Inject
private TempUI tmp1;
@Inject
private TempUI tmp2;
public MainWindow() {
super();
setCaption("AC-Shop");
setWebAppCapable(true);
setPersistentSessionCookie(true);
setImmediate(true);
setCaption("Vaadin Mobile UI");
}
public void createView() {
Resource iconAC = new ClassResource("/icons/airplane.png", getApplication());
Resource iconCart = new ClassResource("/icons/shoppingcart.png", getApplication());
Resource iconCustomer = new ClassResource("/icons/businessman.png", getApplication());
TabBarView tabs = new TabBarView();
tabs.setImmediate(true);
tabs.addTab(shopUI, "Shop", iconAC);
tabs.addTab(tmp1, "Cart", iconCart);
tabs.addTab(tmp2, "Customer", iconCustomer);
setContent(tabs);
}
@Override
public void attach() {
super.attach();
}
}
The ShopNaviagtion:
@SessionScoped
public class ShopUI extends NavigationManager{
private static final long serialVersionUID = 939493231576117076L;
private ShopList comp;
public ShopUI() {
this.comp = new ShopList();
navigateTo(comp);
}
}
and finaly the ShopView:
public class ShopList extends NavigationView{
private static final long serialVersionUID = 9042912188426048359L;
private ShopContent content;
public ShopList() {
setCaption("Shop");
content = new ShopContent();
setContent(content);
}
@Override
public void attach() {
super.attach();
content.loadData();
}
private class ShopContent extends VerticalLayout {
private static final long serialVersionUID = 1L;
private VerticalComponentGroup shopList;
public ShopContent() {
shopList = new VerticalComponentGroup("Available AC");
addComponent(shopList);
}
public void loadData() {
shopList.removeAllComponents();
shopList.addComponent(getRow("AC-1", 1.1));
shopList.addComponent(getRow("AC-2", 5.5));
shopList.addComponent(getRow("AC-3", 8.8));
shopList.addComponent(getRow("AC-4", 9));
}
private GridLayout getRow(final String ac, double price) {
GridLayout grid = new GridLayout(3, 1);
grid.setWidth(100, UNITS_PERCENTAGE);
Label lblAc = new Label("AC: " + ac);
grid.addComponent(lblAc);
grid.addComponent(new Label("Price: " + String.valueOf(price)));
Button btnAdd = new Button("Add");
btnAdd.addListener(new ClickListener() {
private static final long serialVersionUID = 1L;
@Override
public void buttonClick(ClickEvent event) {
getApplication().getMainWindow().showNotification("Purchase of AC: " + ac);
}
});
grid.addComponent(btnAdd);
grid.setComponentAlignment(grid.getComponent(0, 0), Alignment.MIDDLE_LEFT);
grid.setComponentAlignment(grid.getComponent(1, 0), Alignment.MIDDLE_CENTER);
grid.setComponentAlignment(grid.getComponent(2, 0), Alignment.MIDDLE_RIGHT);
return grid;
}
}
}