Skip to content

Commit

Permalink
#2838 implemented disable attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
tandraschko committed Oct 19, 2017
1 parent 68e4563 commit ee5cc12
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
Expand Up @@ -29,14 +29,29 @@ public class AutoUpdateListener implements ComponentSystemEventListener {

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

private final boolean disabled;

public AutoUpdateListener() {
this.disabled = false;
}

public AutoUpdateListener(boolean disabled) {
this.disabled = disabled;
}

@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);
if (disabled) {
clientIds.remove(clientId);
}
else {
if (!clientIds.contains(clientId)) {
clientIds.add(clientId);
}
}
}

Expand Down
Expand Up @@ -23,26 +23,38 @@
import javax.faces.event.PreRenderComponentEvent;
import javax.faces.view.facelets.FaceletContext;
import javax.faces.view.facelets.FaceletException;
import javax.faces.view.facelets.TagAttribute;
import javax.faces.view.facelets.TagConfig;
import javax.faces.view.facelets.TagHandler;

public class AutoUpdateTagHandler extends TagHandler {

private static final AutoUpdateListener LISTENER = new AutoUpdateListener();
private static final AutoUpdateListener LISTENER = new AutoUpdateListener(false);
private static final AutoUpdateListener LISTENER_DISABLED = new AutoUpdateListener(true);

private final TagAttribute disabledAttribute;

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

disabledAttribute = getAttribute("disabled");
}

@Override
public void apply(FaceletContext faceletContext, UIComponent parent) throws IOException, FacesException, FaceletException, ELException {

boolean disabled = false;
if (disabledAttribute != null) {
disabled = disabledAttribute.getBoolean(faceletContext);
}

// 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);
parent.subscribeToEvent(PostAddToViewEvent.class, disabled ? LISTENER_DISABLED : 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);
parent.subscribeToEvent(PreRenderComponentEvent.class, disabled ? LISTENER_DISABLED : LISTENER);
}
}
6 changes: 6 additions & 0 deletions src/main/resources-maven-jsf/standard-facelets-taglib.xml
Expand Up @@ -73,6 +73,12 @@
<handler-class>
org.primefaces.component.autoupdate.AutoUpdateTagHandler
</handler-class>
<attribute>
<description>If autoUpdate should be disabled. Default = false.</description>
<name>disabled</name>
<required>false</required>
<type>java.lang.Boolean</type>
</attribute>
</tag>

<tag>
Expand Down

0 comments on commit ee5cc12

Please sign in to comment.