Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Apache Wicket Interview Questions and Answers

Ques 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.

Is it helpful? Add Comment View Comments
 

Ques 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>

Is it helpful? Add Comment View Comments
 

Ques 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());

Is it helpful? Add Comment View Comments
 

Ques 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);
 
}
 
};

Is it helpful? Add Comment View Comments
 

Ques 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_-]+"));
 
}
}

Is it helpful? Add Comment View Comments
 

Most helpful rated by users:

©2024 WithoutBook