Apache Wicket perguntas e respostas de entrevista
Pergunta 6. Dependency to start wicket.
<dependency>
<groupid>org.apache.wicket</groupid>
<artifactid>wicket</artifactid>
<version>1.4.17</version>
</dependency>
Wicket need SLF4J !
You have to include the slf4j logging implementation, otherwise Wicket will be failed to start.
Wicket need resource filter
Remember to add the resource filter, Wicket puts all files in same package folder, if you didnât define the resource filter to include everything â<include>*</include>â , âhtmlâ, âpropertiesâ or other resources files may failed to copy to the correct target folder.
Isto e util?
Adicionar comentario
Ver comentarios
Pergunta 7. A sample web application using apache wicket.
In Wicket, most stuffs are work by convention, you donât need to configure it. In this case, WebApplication returns a âHello.classâ as the default page, when Wicket see this âHello.classâ, it know the mark up âhtmlâ page should be âHello.htmlâ, and it should be able to find at the same package directory. This is why Wicket need you to put both âhtmlâ and âjavaâ class together.
File : WelcomeApplication.java â The main application entrance.
package com.withoutbook;
import org.apache.wicket.Page;
import org.apache.wicket.protocol.http.WebApplication;
import com.withoutbook.hello.Hello;
public class WelcomeApplication extends WebApplication {
@Override
public Class<? extends Page> getHomePage() {
return Hello.class; //return default page
}
}
File : Hello.java
package com.withoutbook.hello;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.WebPage;
public class Hello extends WebPage {
private static final long serialVersionUID = 1L;
public Hello(final PageParameters parameters) {
add(new Label("message", "Hello World, Wicket"));
}
}
File : Hello.html
<html>
<head>
<title>Wicket Hello World</title>
</head>
<body>
<h1>
<span wicket:id="message">message will be replace later</span>
</h1>
</body>
</html>
To make Wicket works, you need to register Wicket filters in your web.xml file.
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>Wicket Web Application</display-name>
<filter>
<filter-name>wicket.wicketTest</filter-name>
<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
<init-param>
<param-name>applicationClassName</param-name>
<param-value>com.withoutbook.WelcomeApplication</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>wicket.wicketTest</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
Isto e util?
Adicionar comentario
Ver comentarios
Pergunta 8. How to create a TextField in Apache-Wicket?
final TextField<String> username = new TextField<String>("username",
Model.of(""));
username.setRequired(true);
username.add(new UsernameValidator());
Isto e util?
Adicionar comentario
Ver comentarios
Pergunta 9. How to submit a form in apache-wicket?
Form<?> form = new Form<Void>("userForm") {
@Override
protected void onSubmit() {
final String usernameValue = username.getModelObject();
PageParameters pageParameters = new PageParameters();
pageParameters.add("username", usernameValue);
setResponsePage(SuccessPage.class, pageParameters);
}
};
Isto e util?
Adicionar comentario
Ver comentarios
Pergunta 10. Example of Username validation in apache-wicket.
import org.apache.wicket.validation.CompoundValidator;
import org.apache.wicket.validation.validator.PatternValidator;
import org.apache.wicket.validation.validator.StringValidator;
public class UsernameValidator extends CompoundValidator<String> {
private static final long serialVersionUID = 1L;
public UsernameValidator() {
add(StringValidator.lengthBetween(6, 15));
add(new PatternValidator("[a-z0-9_-]+"));
}
}
Isto e util?
Adicionar comentario
Ver comentarios
Mais uteis segundo os usuarios:
- What is Wicket Framework?
- What are Wicket Models?
- What is Base class for HTML pages?
- What are the Ways to create a page in wicket?
- How to integrate apache-wicket with Spring?