Overriding existing components style/css

Reading Time: < 1 minute
<window title="Application Window" border="normal" width="100%"
	height="100%" apply="com.tugrulaslan.controller.IndexController">
	<!-- Listbox Header -->
	color: green !important;
	<!-- Listbox Cell -->
	color: red !important;
	<!-- Groupbox Header -->
	color: blue !important;
	<!-- Label -->
	color: yellow !important;



Spring ZKoss Customized Login, Logout, Authorization and Authentication

Reading Time: 2 minutes


public class CustomAuthenticationFilter extends
		UsernamePasswordAuthenticationFilter {

	private xxService xService;
	static final Logger logger = Logger.getLogger(CustomAuthenticationFilter.class);


	public Authentication attemptAuthentication(HttpServletRequest request,
			HttpServletResponse response) throws AuthenticationException {

		String username = request.getParameter(getUsernameParameter());
		String password = request.getParameter(getPasswordParameter());
		String server = request.getParameter("server");
		if(username.trim().length() == 0 || password.trim().length() == 0){
			logger.error("Error empty credentials entered " + username + password + server);
			throw new BadCredentialsException("Error empty credentials entered!");
		return logonToBO(request, response, username, password, server);
	public Authentication logonToBO(HttpServletRequest request, HttpServletResponse response, String username, String password, String server){
		List<GrantedAuthority> authorities = collectAuthorities(username, password, server);
		UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password, authorities);		
		if(xService.checkUserEnterpriseLogOn(username, password,server)){
			logger.debug("Access granted " + username+ password + server + token);
			return token;
			throw new BadCredentialsException("Error wrong credentials entered!");
	public List<GrantedAuthority> collectAuthorities(String username, String password, String server){
		List<GrantedAuthority> auths = new ArrayList<GrantedAuthority>();
		String userAuth = xService.acquireUserAuthorityGroup(username, password, server);

			auths.add(new GrantedAuthorityImpl("ROLE_USER"));
		if(userAuth.equals("") || userAuth == ""){
			logger.error("Unauthorized login " + username);
			throw new BadCredentialsException("You aren't authorized beyond this point!");
		return auths;


public class CustomAuthenticationProvider implements AuthenticationProvider{

	public Authentication authenticate(Authentication authentication)
			throws AuthenticationException {

		return authentication;

	public boolean supports(Class<?> arg0) {
		return true;


        private XXService XService;

	public void logout(HttpServletRequest request,
			HttpServletResponse response, Authentication authentication) {

		//log out of BO Server
		//return the values and log off from spring security as well
		super.logout(request, response, authentication);


<beans:beans xmlns="http://www.springframework.org/schema/security"
	xsi:schemaLocation="http://www.zkoss.org/2008/zkspring/core http://www.zkoss.org/2008/zkspring/core/zkspring-core.xsd
		http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

	<http auto-config="false" entry-point-ref="loginUrlAuthenticationEntryPoint">

		<!-- ZK au has to be accessed anonymously -->
		<intercept-url pattern="/zkau/**" access="IS_AUTHENTICATED_ANONYMOUSLY"
			requires-channel="any" />

		<!-- allowing access to css resources -->
		<intercept-url pattern="/css/**" access="IS_AUTHENTICATED_ANONYMOUSLY"
			requires-channel="any" />

		<!-- allowing access to images resources -->
		<intercept-url pattern="/images/**" access="IS_AUTHENTICATED_ANONYMOUSLY"
			requires-channel="any" />

		<!-- allowing access to layout resources -->
		<intercept-url pattern="/layout/**" access="IS_AUTHENTICATED_ANONYMOUSLY"
			requires-channel="any" />

		<!-- allowing access to login page -->
		<intercept-url pattern="/login.zul" access="IS_AUTHENTICATED_ANONYMOUSLY" />
		<intercept-url pattern="/sectest.zul" access="IS_AUTHENTICATED_ANONYMOUSLY" />

		<!-- After defining other resources secure all pages and links -->
		<intercept-url pattern="/**" access="ROLE_USER" />

		<!-- Custom Login Filter -->
		<custom-filter ref="customAuthenticationFilter"
			position="FORM_LOGIN_FILTER" />

		<!-- Custom Logout Filter -->
		<custom-filter ref="customLogoutFilter" position="LOGOUT_FILTER" />

	<!-- Custom Authentication Filter -->
	<beans:bean id="customAuthenticationFilter"
		<beans:property name="authenticationManager" ref="authenticationManager" />
		<beans:property name="authenticationFailureHandler"
			ref="failureHandler" />
		<beans:property name="authenticationSuccessHandler"
			ref="successHandler" />

	<!-- Custom Authentication Filter -->
	<authentication-manager alias="authenticationManager">
		<authentication-provider ref="customAuthenticationProvider" />

	<!-- Custom Authentication Provider For details check the regarding class -->
	<beans:bean id="customAuthenticationProvider"
		class="com.tugrulaslan.security.CustomAuthenticationProvider" />

	<!-- Successful login handler -->
	<beans:bean id="successHandler"
		<beans:property name="defaultTargetUrl" value="/index.zul" />

	<!-- Failure login handler -->
	<beans:bean id="failureHandler"
		<beans:property name="defaultFailureUrl" value="/login.zul?login_error=1" />

	<!-- Custom Logout Handler -->
	<beans:bean id="customLogoutHandler" class="com.tugrulaslan.security.CustomLogoutHandler" />
	<beans:bean id="customLogoutFilter"
		<beans:constructor-arg value="/login.zul" />
				<beans:ref bean="customLogoutHandler" />
		<beans:property name="filterProcessesUrl" value="/j_spring_security_logout" />

	<!-- Access Denied Handler -->
	<beans:bean id="accessDeniedHandler"
		<beans:property name="errorPage" value="/accessDenied.zul" />

	<!-- Customized Login Entry Point -->
	<beans:bean id="loginUrlAuthenticationEntryPoint" scope="prototype"
		<beans:property name="loginFormUrl" value="/login.zul" />



<?page title="Login" contentType="text/html;charset=UTF-8"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
	<div style="width: 700px; margin-left: auto; margin-right: auto;">
		<div height="90px" width="600px"
			style="margin-left: auto; margin-right: auto;">

			<label value="Login page"
				style="font-size:16px; font-weight:bold; color:red" />
		<window title="User Login Screen" border="normal"
			<html:form id="loginForm" name="loginForm"
				action="j_spring_security_check" method="POST"
							<label value="Username" />
							<textbox id="username" name="j_username" width="162px" />
							<label value="Password" />
							<textbox id="password" type="password"
								name="j_password" width="162px" />
							<label value="Server" />
							<combobox id="server" name="server"
								readonly="true" onCreate="self.setSelectedIndex(0)">
									<comboitem value="SERVER 1"
									label="SERVER 1" />
									<comboitem value="SERVER 2"
									label="SERVER 2" />									
							<label />

							<button id="login" type="submit"
								label="Giris" />

				<html style="color:red"
					if="${not empty param.login_error}">
					<!-- Here spring failure messages printed -->

Getting selected items in listbox ZK

Reading Time: < 1 minute

In one of my project I really needed one of piece of this code and dwelled on that for a long while. I asked for assistance from a senior and he showed me how to, and I would like to share this piece of helpful code with you. In controller class I did not create a simple arraylist for the listbox model just to give you the structure you may implement this code in your project. Normally for one lastly selected item you can use listbox.getSelectedItem.getValue() and acquire the selected item. How about when we have more than one selected items, that is the tricky point

The trick I learnt was that there was an iterator in the listbox, and I saw that I could easily collect the selected items. You will see how I achieved that thanks to the Senior.


public class BulkAuthController extends SelectorComposer<Component> {

Listbox universeListbox;

//I have this simple array list to collect the selected items on listbox not mandatory
private ArrayList<String> selectedUniverseListboxItems = new ArrayList<String>();

//here is the trick.
public void collectSelectedItems() {
		Iterator<Listitem> iterator = universeListbox.getSelectedItems()
		while (iterator.hasNext()) {
			Listitem listitem = (Listitem) iterator.next();


Zul Page

<?page title="Listbox Test" contentType="text/html;charset=UTF-8"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?>
<zk xmlns:h="http://www.w3.org/1999/xhtml"

	<window id="listboxSample" title="Listbox Test" border="normal"
		width="900px" apply="com.tugrulaslan.controller.ListboxTestController">

					<listbox id="universeListbox"
						model="${$composer.userUniverseList()}" multiple="true"
						checkmark="true" height="500px">
						<template name="model">
								<listcell label="${each}"

Using html elements in ZK

Reading Time: < 1 minute

Well today I had to face this situation since I am a newbie in ZK Framework. In a single line in my code I had to leave a new space between two different components I found the solution first of all we need to add the ZK html namespace in our code and with the namespace we can use zk specialized html elements

<zk xmlns:h="http://www.w3.org/1999/xhtml" xmlns:zk="http://www.zkoss.org/2005/zk">
	<window  title="ZK HTML Elements" width="300px"
		<label value="First element"/>
<h:br />
		<label value="Second Element" />
<h:br />
<h:p>Another<h:br /> break <h:br /> example </h:p>

Instant copy while typing in a textbox – ZK

Reading Time: < 1 minute

I have been looking for the exact thing online and tried entire week how to copy instant typing to another textbox or label in zk, and finally I have come to the end of making one on my own. Normally you can do the same in zul but what I really needed in work project is with the controller. The below evaluate the code


<?page title="Instant Copy" contentType="text/html;charset=UTF-8"?>
	<window title="Instant Copy"
		apply="com.tugrulaslan.controller.InstantController" border="normal"
					<label value="Source" />
					<textbox id="dataTXT" />
					<label value="Instant Copy" />
					<textbox id="copyTXT" readonly="true" />


package com.akbank.controller;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import org.zkoss.zhtml.Messagebox;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Execution;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.Session;
import org.zkoss.zk.ui.Sessions;
import org.zkoss.zk.ui.metainfo.ComponentInfo;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.select.annotation.Listen;
import org.zkoss.zk.ui.select.annotation.VariableResolver;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zk.ui.select.annotation.WireVariable;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zul.Button;
import org.zkoss.zul.Label;
import org.zkoss.zul.ListModelList;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.SimpleListModel;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Window;
import org.zkoss.zk.ui.event.*;

public class InstantController extends SelectorComposer<Component> {

	Textbox dataTXT;

	Textbox copyTXT;

	@Listen("onChanging = #dataTXT")
	public void butttonnn(InputEvent inputEvent){

Adding zk archetype to maven in eclipse

Reading Time: < 1 minute

on eclipse or sts click on window > preferences

and  on the left pane menu go to Maven and expand the menu choose Archetypes here click on add remote catalog and type in

Catalog file: http://mavensync.zkoss.org/maven2/

Description: zk

click on okay. When you create a new maven project from the catalog choose zk and select your favorite zk maven project