Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tandraschko committed Oct 19, 2017
1 parent 2de2c4a commit 68e4563
Show file tree
Hide file tree
Showing 23 changed files with 1,896 additions and 1,968 deletions.
28 changes: 0 additions & 28 deletions src/main/java/org/primefaces/component/api/AutoUpdatable.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Copyright 2009-2017 PrimeTek.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.primefaces.component.autoupdate;

import java.util.ArrayList;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ComponentSystemEvent;
import javax.faces.event.ComponentSystemEventListener;

/**
* Registers components to auto update
*/
public class AutoUpdateListener implements ComponentSystemEventListener {

private static final String COMPONENTS = AutoUpdateListener.class.getName() + ".COMPONENTS";

@Override
public void processEvent(ComponentSystemEvent cse) throws AbortProcessingException {
FacesContext context = FacesContext.getCurrentInstance();
String clientId = ((UIComponent) cse.getSource()).getClientId(context);

ArrayList<String> clientIds = getOrCreateAutoUpdateComponentClientIds(context);
if (!clientIds.contains(clientId)) {
clientIds.add(clientId);
}
}

public static ArrayList<String> getOrCreateAutoUpdateComponentClientIds(FacesContext context) {
ArrayList<String> clientIds = getAutoUpdateComponentClientIds(context);
if (clientIds == null) {
clientIds = new ArrayList<String>();
context.getViewRoot().getAttributes().put(COMPONENTS, clientIds);
}
return clientIds;
}

public static ArrayList<String> getAutoUpdateComponentClientIds(FacesContext context) {
return (ArrayList<String>) context.getViewRoot().getAttributes().get(COMPONENTS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.primefaces.util;
package org.primefaces.component.autoupdate;

import java.util.ArrayList;
import javax.faces.context.FacesContext;
Expand All @@ -22,7 +22,7 @@
import javax.faces.event.PhaseListener;
import org.primefaces.context.RequestContext;

public class AutoUpdateComponentPhaseListener implements PhaseListener {
public class AutoUpdatePhaseListener implements PhaseListener {

@Override
public void afterPhase(PhaseEvent event) {
Expand All @@ -32,11 +32,11 @@ public void afterPhase(PhaseEvent event) {
@Override
public void beforePhase(PhaseEvent event) {
FacesContext context = event.getFacesContext();
if (RequestContext.getCurrentInstance(context).isIgnoreAutoUpdate()) {
if (!context.isPostback() || RequestContext.getCurrentInstance(context).isIgnoreAutoUpdate()) {
return;
}

ArrayList<String> clientIds = AutoUpdateComponentListener.getAutoUpdateComponentClientIds(context);
ArrayList<String> clientIds = AutoUpdateListener.getAutoUpdateComponentClientIds(context);
if (clientIds != null && !clientIds.isEmpty()) {
for (int i = 0; i < clientIds.size(); i++) {
String clientId = clientIds.get(i);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Copyright 2009-2017 PrimeTek.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.primefaces.component.autoupdate;

import java.io.IOException;
import javax.el.ELException;
import javax.faces.FacesException;
import javax.faces.component.UIComponent;
import javax.faces.event.PostAddToViewEvent;
import javax.faces.event.PreRenderComponentEvent;
import javax.faces.view.facelets.FaceletContext;
import javax.faces.view.facelets.FaceletException;
import javax.faces.view.facelets.TagConfig;
import javax.faces.view.facelets.TagHandler;

public class AutoUpdateTagHandler extends TagHandler {

private static final AutoUpdateListener LISTENER = new AutoUpdateListener();

public AutoUpdateTagHandler(TagConfig tagConfig) {
super(tagConfig);
}

@Override
public void apply(FaceletContext faceletContext, UIComponent parent) throws IOException, FacesException, FaceletException, ELException {
// PostAddToViewEvent should work for stateless views
// but fails for MyFaces ViewPooling
// and sometimes on postbacks as PostAddToViewEvent should actually ony be called once
parent.subscribeToEvent(PostAddToViewEvent.class, LISTENER);

// PreRenderComponentEvent should work for normal cases and MyFaces ViewPooling
// but likely fails for stateless view as we save the clientIds in the viewRoot
parent.subscribeToEvent(PreRenderComponentEvent.class, LISTENER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ public void encodeBegin(FacesContext context, UIComponent component) throws IOEx
Map<Object, Object> attrs = RequestContext.getCurrentInstance(context).getAttributes();
attrs.put(Constants.FRAGMENT_ID, clientId);

if (fragment.isAutoUpdate()) {
attrs.put(Constants.FRAGMENT_AUTO_RENDERED, true);
}

writer.startElement("div", component);
writer.writeAttribute("id", clientId, "id");
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/primefaces/context/RequestContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import org.primefaces.component.api.AutoUpdatable;
import org.primefaces.util.AjaxRequestBuilder;
import org.primefaces.util.CSVBuilder;
import org.primefaces.util.StringEncrypter;
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/org/primefaces/util/AjaxRequestBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,6 @@ private void addFragmentConfig() {
Object fragmentId = attrs.get(Constants.FRAGMENT_ID);
if (fragmentId != null) {
buffer.append(",fi:\"").append(fragmentId).append("\"");

if (attrs.containsKey(Constants.FRAGMENT_AUTO_RENDERED)) {
buffer.append(",fu:true");
}
}
}
}
85 changes: 0 additions & 85 deletions src/main/java/org/primefaces/util/AutoUpdateComponentListener.java

This file was deleted.

1 change: 0 additions & 1 deletion src/main/java/org/primefaces/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public static class RequestParams {
public static final String BARCODE_MAPPING = "primefaces.barcodeMapping";

public final static String FRAGMENT_ID = "primefaces.fragment";
public final static String FRAGMENT_AUTO_RENDERED = "primefaces.fragment.autorendered";

public static class DIALOG_FRAMEWORK {

Expand Down

0 comments on commit 68e4563

Please sign in to comment.