Skip to content
This repository has been archived by the owner on Dec 17, 2020. It is now read-only.

Commit

Permalink
Remove old Router from project (#433)
Browse files Browse the repository at this point in the history
* Remove old Router from project

related flow issue vaadin/flow#3826

* remove the unneeded servelet config and use extends Div instead of UI 

fix test failures

* Add javadoc for public class

* remove UI from javadoc and rename class name

add missing getMappingInfo() to each view in demo-web-site project
remove unnecessary servelet config.
  • Loading branch information
ZheSun88 authored Apr 9, 2018
1 parent 5169ce7 commit 0a57525
Show file tree
Hide file tree
Showing 21 changed files with 111 additions and 285 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.vaadin.flow.component.polymertemplate.Id;
import com.vaadin.flow.component.polymertemplate.PolymerTemplate;
import com.vaadin.flow.demo.googlesignin.component.SigninView.SigninModel;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.templatemodel.TemplateModel;

import elemental.json.JsonObject;
Expand All @@ -35,6 +36,7 @@
*/
@Tag("signin-page")
@HtmlImport("frontend://components/signin.html")
@Route("")
public class SigninView extends PolymerTemplate<SigninModel> {

@Id("login-info")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,27 @@
*/
package com.vaadin.flow.demo.minesweeper.component;

import javax.servlet.annotation.WebServlet;

import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.dependency.StyleSheet;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.demo.minesweeper.component.component.MinesweeperComponent;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.server.VaadinRequest;
import com.vaadin.flow.server.VaadinServlet;
import com.vaadin.flow.server.VaadinServletConfiguration;
import com.vaadin.flow.server.VaadinService;

/**
* UI which demonstrates how you can use the Flow {@link Component} API
* to create a Minesweeper game.
* View which demonstrates how you can use the Flow {@link Component} API to
* create a Minesweeper game.
*/
@Route("")
@StyleSheet("frontend://minesweeper.css")
public class MinesweeperUI extends UI {

public class MinesweeperView extends Div {
/**
* The main servlet for the application.
* Create Minesweeper view.
*/
@WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = MinesweeperUI.class, productionMode = false)
public static class Servlet extends VaadinServlet {

}
public MinesweeperView() {
VaadinRequest request = VaadinService.getCurrentRequest();

@Override
protected void init(VaadinRequest request) {
long seed = getParam(request, "seed", (int) System.currentTimeMillis());
double mineDensity = getParam(request, "mineDensity", 20) / 100.0;
int rows = getParam(request, "rows", 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,29 @@
*/
package com.vaadin.flow.demo.minesweeper.element;

import javax.servlet.annotation.WebServlet;

import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.dependency.StyleSheet;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.dom.Element;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.server.VaadinRequest;
import com.vaadin.flow.server.VaadinServlet;
import com.vaadin.flow.server.VaadinServletConfiguration;
import com.vaadin.flow.server.VaadinService;

/**
* UI which demonstrates how you can use the Flow {@link Element} API to
* View which demonstrates how you can use the Flow {@link Element} API to
* create a Minesweeper game.
*/
@Route("")
@StyleSheet("frontend://minesweeper.css")
public class MinesweeperUI extends UI {
public class MinesweeperView extends Div {

/**
* The main servlet for the application.
* Create Minesweeper view.
*/
@WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = MinesweeperUI.class, productionMode = false)
public static class Servlet extends VaadinServlet {
}

@Override
protected void init(VaadinRequest request) {
public MinesweeperView() {
long seed;
double mineDensity;
int rows, cols;
VaadinRequest request = VaadinService.getCurrentRequest();

String seedParam = request.getParameter("seed");
if (seedParam != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public MenuBar() {
private void init() {
setId("menu");
Map<Class<? extends RouterLayout>, List<RouteData>> routes = UI
.getCurrent().getRouter().get().getRoutesByParent();
.getCurrent().getRouter().getRoutesByParent();
List<Class<? extends RouterLayout>> parentLayouts = routes.keySet()
.stream().filter(parent -> !parent.equals(UI.class))
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
*/
@WebServlet(urlPatterns = "/*", name = "static-menu", asyncSupported = true, initParams = {
@WebInitParam(name = Constants.I18N_PROVIDER, value = "com.vaadin.flow.demo.staticmenu.Lang") })
@VaadinServletConfiguration(usingNewRouting = true, productionMode = false)
@VaadinServletConfiguration(productionMode = false)
public class ApplicationServlet extends VaadinServlet {
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private void save() {
BlogsService.getInstance().saveItem(record);
// TODO: Update after #2702 implemented
UI ui = UI.getCurrent();
ui.navigate(ui.getRouter().get().getUrl(BlogList.class));
ui.navigate(ui.getRouter().getUrl(BlogList.class));
} else {
binder.validate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public BlogList() {
// TODO: Update after #2702 implemented
UI ui = UI.getCurrent();
addBlogPost = new Button("Add Blog Post", buttonClickEvent -> ui
.navigate(ui.getRouter().get().getUrl(BlogCreator.class)));
.navigate(ui.getRouter().getUrl(BlogCreator.class)));
add(addBlogPost);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,19 @@
*/
package com.vaadin.flow.demo.textfieldcomponent;

import javax.servlet.annotation.WebServlet;

import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.server.VaadinRequest;
import com.vaadin.flow.server.VaadinServlet;
import com.vaadin.flow.server.VaadinServletConfiguration;
import com.vaadin.flow.router.Route;

/**
* UI which demonstrates how a text field component can be used.
* View which demonstrates how a text field component can be used.
*/
public class TextFieldUI extends UI {
@Route("")
public class TextFieldView extends Div {

/**
* The main servlet for the application.
* Create view for demonstrating a text field.
*/
@WebServlet(urlPatterns = "/*", name = "UIServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = TextFieldUI.class, productionMode = false)
public static class Servlet extends VaadinServlet {
}

@Override
protected void init(VaadinRequest request) {
public TextFieldView() {
TextField tf = new TextField("Enter your age");
tf.addChangeListener(event -> {
int age;
Expand All @@ -49,6 +39,7 @@ protected void init(VaadinRequest request) {

Div message = new Div();
message.setText(getAgeMessage(age));
message.setId("message");
add(message);
});
add(tf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.vaadin.flow.demo.textfieldcomponent;

import java.util.List;

import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.By;
Expand All @@ -30,17 +32,14 @@ public void basicFunctionality() {
open();
WebElement input = findElement(By.xpath("//input"));
changeInput(input, "14");

WebElement div = findElement(By.xpath("//body/div[3]"));
Assert.assertEquals("Oh my, 14 is so young!", div.getText());

changeInput(input, "44");
div = findElement(By.xpath("//body/div[4]"));
Assert.assertEquals("Gosh, 44 is so old!", div.getText());

changeInput(input, "Foo");
div = findElement(By.xpath("//body/div[5]"));
Assert.assertEquals("That's not even a real age!", div.getText());

List<WebElement> divs = findElements(By.id("message"));
Assert.assertEquals("Oh my, 14 is so young!", divs.get(0).getText());
Assert.assertEquals("Gosh, 44 is so old!", divs.get(1).getText());
Assert.assertEquals("That's not even a real age!",
divs.get(2).getText());
}

private void changeInput(WebElement input, String string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,19 @@
*/
package com.vaadin.flow.demo.textfieldcomposite;

import javax.servlet.annotation.WebServlet;

import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.server.VaadinRequest;
import com.vaadin.flow.server.VaadinServlet;
import com.vaadin.flow.server.VaadinServletConfiguration;
import com.vaadin.flow.router.Route;

/**
* UI which demonstrates how a text field component can be used.
* View which demonstrates how a text field component can be used.
*/
public class TextFieldUI extends UI {
@Route("")
public class TextFieldView extends Div {

/**
* The main servlet for the application.
* Create view for demonstrates a text field.
*/
@WebServlet(urlPatterns = "/*", name = "UIServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = TextFieldUI.class, productionMode = false)
public static class Servlet extends VaadinServlet {
}

@Override
protected void init(VaadinRequest request) {
public TextFieldView() {
TextField tf = new TextField("Enter your age");
tf.addChangeListener(event -> {
int age;
Expand All @@ -49,6 +39,7 @@ protected void init(VaadinRequest request) {

Div message = new Div();
message.setText(getAgeMessage(age));
message.setId("message");
add(message);
});
add(tf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.vaadin.flow.demo.component.textfield;

import java.util.List;

import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.By;
Expand All @@ -30,13 +32,12 @@ public void basicFunctionality() {
open();
WebElement input = findElement(By.xpath("//input"));
changeInput(input, "14");
changeInput(input, "44");

WebElement div = findElement(By.xpath("//body/div[3]"));
Assert.assertEquals("Oh my, 14 is so young!", div.getText());
List<WebElement> divs = findElements(By.id("message"));
Assert.assertEquals("Oh my, 14 is so young!", divs.get(0).getText());

changeInput(input, "44");
div = findElement(By.xpath("//body/div[4]"));
Assert.assertEquals("Gosh, 44 is so old!", div.getText());
Assert.assertEquals("Gosh, 44 is so old!", divs.get(1).getText());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@
package com.vaadin.flow.demo.website;

import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.router.Route;

/**
* The static about view.
*
* @since
* @author Vaadin Ltd
*/
@Route(value = "about", layout = MainLayout.class)
public final class AboutView extends SimpleView {
/**
* Creates as new view.
*/
public AboutView() {
add(getMappingInfo(SiteRouterConfigurator.MAPPING_ABOUT));
add(super.getMappingInfo("about"));
Div div = new Div();
div.setText("This is the about page");
div.setClassName("content");
Expand Down
Loading

0 comments on commit 0a57525

Please sign in to comment.