Prepare Interview

Exams Attended

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Apache Wicket Interview Questions and Answers

Experienced / Expert level questions & answers

Ques 1. How to create Select Option as menu wise in apache-wicket?

//Java 
import org.apache.wicket.extensions.markup.html.form.select.Select;
import org.apache.wicket.extensions.markup.html.form.select.SelectOption;
...
        //variable to hold the selected value from dropdown box,
        //and also make "jQuery" selected by default
        private String selected = "jQuery";
 
Select languages = new Select("languages", new PropertyModel<String>(this, "selected"));
form.add(languages);
languages.add(new SelectOption<String>("framework1", new Model<String>("Wicket")));
languages.add(new SelectOption<String>("framework2", new Model<String>("Spring MVC")));
languages.add(new SelectOption<String>("framework3", new Model<String>("JSF 2.0")));
languages.add(new SelectOption<String>("Script1", new Model<String>("jQuery")));
languages.add(new SelectOption<String>("Script2", new Model<String>("prototype")));
 
//HTML for dropdown box
<select wicket:id="languages">
<optgroup label="Frameworks">
<option wicket:id="framework1" >Wicket (1.4.7)</option>
<option wicket:id="framework2" >Spring MVC (3.0)</option>
<option wicket:id="framework3" >JSF (2.0)</option>
</optgroup>
<optgroup label="JavaScript">
<option wicket:id="Script1" >jQuery (1.6.1)</option>
<option wicket:id="Script2" >prototype (1.7)</option>
</optgroup>
</select>

Is it helpful? Add Comment View Comments
 

Ques 2. What is Pallet component in apache-wicket?

Wicket extension comes with a special “Palette” component, which render two select boxes, and allow user to move items from one select box into another.

//Java
import org.apache.wicket.extensions.markup.html.form.palette.Palette;
 
final Palette<Hosting> palette = new Palette<Hosting>("palette",
new ListModel<Hosting>(selected),
new CollectionModel<Hosting>(listHosting),
renderer, 10, true);
 
 
//HTML
<span wicket:id="palette"></span>

Is it helpful? Add Comment View Comments
 

Ques 3. How to create custom validator in apache-wicket?

See summary steps to create a custom validator :

1. Implements IValidator.

import org.apache.wicket.validation.IValidator;
 
public class StrongPasswordValidator implements IValidator<String>{
...
}

2. Override validate(IValidatable validatable).

public class StrongPasswordValidator implements IValidator<String>{
...
@Override
public void validate(IValidatable<String> validatable) {
 
//get input from attached component
final String field = validatable.getValue();
 
}
}

3. Attached custom validator to form component.

public class CustomValidatorPage extends WebPage {
 
public CustomValidatorPage(final PageParameters parameters) {
 
     final PasswordTextField password = new PasswordTextField("password",Model.of(""));
//attached custom validator to password field
password.add(new StrongPasswordValidator());
 
//...
}
 
}

Is it helpful? Add Comment View Comments
 

Ques 4. How to integrate apache-wicket with Spring?

Override Wicket application init() method with this “addComponentInstantiationListener(new SpringComponentInjector(this));“.

File : Wicket application class

package com.withoutbook;
 
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;
import com.withoutbook.user.SimplePage;
 
public class WicketApplication extends WebApplication {
 
@Override
public Class<SimplePage> getHomePage() {
 
return SimplePage.class; // return default page
}
 
@Override
protected void init() {
 
super.init();
addComponentInstantiationListener(new SpringComponentInjector(this));
 
}
 
}
Now, you can inject Spring bean into Wicket component via @SpringBean.

Is it helpful? Add Comment View Comments
 

Ques 5. How to get ServletContext in apache-wicket application?

Yes, you can get the ServletContext class via Wicket’s WebApplication class like this :

import javax.servlet.ServletContext;
import org.apache.wicket.Page;
import org.apache.wicket.protocol.http.WebApplication;
import com.withoutbook.hello.Hello;
 
public class CustomApplication extends WebApplication {
 
@Override
public Class<? extends Page> getHomePage() {
 
ServletContext servletContext = WebApplication.get().getServletContext();
return Hello.class; //return default page
 
}
 
}

Is it helpful? Add Comment View Comments
 

Ques 6. How to keep file validation in apache-wicket if no file has been selected?

To fix it, just override the validateOnNullValue() method like this :

FileUploadField fileUpload = new FileUploadField("fileupload",new Model<FileUpload>());
 
fileUpload .add(new AbstractValidator() { 
 
       public boolean validateOnNullValue(){
       return true;
}
 
protected void onValidate(IValidatable validatable) { 
FileUpload fileUpload = (FileUpload) validatable.getValue();
}
 
    protected String resourceKey() {
   return "yourErrorKey";
}
 
});
Now, when no file is selected, and submit button is clicked, validation will be performed.

Is it helpful? Add Comment View Comments
 

Ques 7. How to create 404 error page?

<filter-mapping>
<filter-name>wicket.wicketTest</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<error-page>
<error-code>404</error-code>
<location>/error404</location>
</error-page>
public class WicketApplication extends WebApplication {
 
@Override
protected void init() {
 
mount(new QueryStringUrlCodingStrategy("error404",ErrorPage404.class));
 
}
 
}

Is it helpful? Add Comment View Comments
 

Most helpful rated by users:

Related interview subjects

Core Java interview questions and answers - Total 306 questions
Tomcat interview questions and answers - Total 16 questions
Apache Wicket interview questions and answers - Total 26 questions
Java Applet interview questions and answers - Total 29 questions
JAXB interview questions and answers - Total 18 questions
JMS interview questions and answers - Total 64 questions
Log4j interview questions and answers - Total 35 questions
Struts interview questions and answers - Total 84 questions
RMI interview questions and answers - Total 31 questions
Apache Camel interview questions and answers - Total 20 questions
JDBC interview questions and answers - Total 27 questions
Java 11 interview questions and answers - Total 24 questions
JPA interview questions and answers - Total 41 questions
EJB interview questions and answers - Total 80 questions
GWT interview questions and answers - Total 27 questions
Kotlin interview questions and answers - Total 30 questions
Glassfish interview questions and answers - Total 8 questions
Google Gson interview questions and answers - Total 8 questions
JSP interview questions and answers - Total 49 questions
J2EE interview questions and answers - Total 25 questions
Apache Tapestry interview questions and answers - Total 9 questions
Java Swing interview questions and answers - Total 27 questions
Java Mail interview questions and answers - Total 27 questions
Hibernate interview questions and answers - Total 52 questions
JSF interview questions and answers - Total 24 questions
Java 8 interview questions and answers - Total 30 questions
Java 15 interview questions and answers - Total 16 questions
JBoss interview questions and answers - Total 14 questions
Web Services interview questions and answers - Total 10 questions
RichFaces interview questions and answers - Total 26 questions
Servlets interview questions and answers - Total 34 questions
Java Beans interview questions and answers - Total 57 questions
Spring Boot interview questions and answers - Total 50 questions
JUnit interview questions and answers - Total 24 questions
Spring Framework interview questions and answers - Total 53 questions
Java Design Patterns interview questions and answers - Total 15 questions
©2023 WithoutBook