Skip to content

Latest commit

 

History

History
74 lines (66 loc) · 1.73 KB

redirect.md

File metadata and controls

74 lines (66 loc) · 1.73 KB

Html: index.html

<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>Form</title>
	<style>
		li {list-style-type: none;}
	</style>
</head>
<body>
	<div>Teste Redirect</div>
	<button type="button" name="redirect" id="redirect">Redirect</button>
	<button type="button" name="redirectAjax" id="redirectAjax" href="register.html" appendTo="body" empty changeURL keepViewId>Redirect With AJAX</button>
</body>
</html>

Html: register.html

<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>Form</title>
	<style>
		li {list-style-type: none;}
	</style>
</head>
<body>
	<label for="name">Name</label>: <input type="text" name="name" id="name"/>
	<div>
		<button type="button" name="alertName" id="alertName">Alert Name</button>
	</div>
</body>
</html>

Java: IndexController.java

@Page(name = "index", path = "index.html")
public class IndexController extends Window {
	public void init(JRenderContext context) {
		document.getElementById("redirect").addEventListener(Events.CLICK, new FunctionHandle(new SimpleFunction() {
			public void init(JRenderContext context) {
				location.href(RegisterController.class);
			}
		}));
	}
}

Java: RegisterController.java

@Page(name = "register", path = "register.html", ajaxSelector = "body")
public class RegisterController extends Window {
	public void init(JRenderContext context) {
		final InputTextElement<String> inputText = document.getElementById("name", InputTextElement.class, String.class);

		Element button = document.getElementById("alertName");

		button.addEventListener(Events.CLICK, new FunctionHandle(new SimpleFunction() {
			@ForceSync
			public void init(JRenderContext context) {
				alert("Name: " + inputText.value());
			}
		}));
	}
}