/*
* (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and contributors.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser General Public License
* (LGPL) version 2.1 which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-2.1.html
*
* This library 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
* Lesser General Public License for more details.
*
* Contributors:
* Anahide Tchertchian
*/
package org.nuxeo.ecm.platform.forms.layout.facelets;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;
/**
* Phase listener that empties the map of widget ids generated by the layout
* system to avoid duplicate when process of facelet handlers is done twice.
* <p>
* Process is done twice on ajax requests, when performing phase restore and
* then phase render response => empty the map before rendering response.
*
* @since 6.0
*/
public class LayoutPhaseListener implements PhaseListener {
private static final long serialVersionUID = 1L;
@Override
public PhaseId getPhaseId() {
return PhaseId.RENDER_RESPONSE;
}
@Override
public void beforePhase(PhaseEvent event) {
FacesContext context = event.getFacesContext();
Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
requestMap.remove(FaceletHandlerHelper.LAYOUT_ID_COUNTERS);
}
@Override
public void afterPhase(PhaseEvent event) {
}
}