Java tutorial
/** * This file is part of mycollab-web. * * mycollab-web is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * mycollab-web is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with mycollab-web. If not, see <http://www.gnu.org/licenses/>. */ package com.esofthead.mycollab.vaadin.web.ui; import com.esofthead.mycollab.common.UrlEncodeDecoder; import com.esofthead.mycollab.common.json.QueryAnalyzer; import com.esofthead.mycollab.core.db.query.SearchFieldInfo; import com.esofthead.mycollab.core.utils.StringUtils; import com.esofthead.mycollab.eventmanager.ApplicationEventListener; import com.esofthead.mycollab.shell.events.ShellEvent; import com.google.common.eventbus.Subscribe; import com.vaadin.server.Page; import java.util.List; /** * @author MyCollab Ltd * @since 5.3.2 */ public class QueryParamHandler { public static ApplicationEventListener<ShellEvent.AddQueryParam> queryParamHandler() { return new ApplicationEventListener<ShellEvent.AddQueryParam>() { @Subscribe @Override public void handle(ShellEvent.AddQueryParam event) { List<SearchFieldInfo> searchFieldInfos = (List<SearchFieldInfo>) event.getData(); String query = QueryAnalyzer.toQueryParams(searchFieldInfos); String fragment = Page.getCurrent().getUriFragment(); int index = fragment.indexOf("?"); if (index > 0) { fragment = fragment.substring(0, index); } if (StringUtils.isNotBlank(query)) { fragment += "?" + UrlEncodeDecoder.encode(query); Page.getCurrent().setUriFragment(fragment, false); } } }; } }