Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Apache Wicket Interview Questions and Answers

Ques 21. 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 22. 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 23. 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 24. 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 25. 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
 

Most helpful rated by users:

©2024 WithoutBook