Skip to content

Instantly share code, notes, and snippets.

@jyeary
Last active March 25, 2016 22:21
Show Gist options
  • Save jyeary/19a236c0001a4fea0ecc to your computer and use it in GitHub Desktop.
Save jyeary/19a236c0001a4fea0ecc to your computer and use it in GitHub Desktop.
An implementation of TreeSelectionChangeListener for RichFaces 4.x
/*
* Copyright 2016 John Yeary <[email protected]>.
*
* 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 com.bluelotussoftware.example.jsf.richfaces;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
import org.richfaces.component.UITree;
import org.richfaces.event.TreeSelectionChangeEvent;
import org.richfaces.event.TreeSelectionChangeListener;
import org.richfaces.model.TreeNode;
/**
*
* @author John Yeary <[email protected]>
* @version 1.0
*/
public class TreeSelectionChangeListenerImpl implements Serializable, TreeSelectionChangeListener {
private static final long serialVersionUID = 6459662437272882270L;
public TreeSelectionChangeListenerImpl() {
}
@Override
public void processTreeSelectionChange(TreeSelectionChangeEvent event) throws AbortProcessingException {
List<Object> selection = new ArrayList<>(event.getNewSelection());
Object currentSelectionKey = selection.get(0);
UITree tree = (UITree) event.getSource();
Object storedKey = tree.getRowKey();
tree.setRowKey(currentSelectionKey);
TreeNode selectedNode = (TreeNode) tree.getRowData();
// EXAMPLE IMPLEMENTATION
FacesContext.getCurrentInstance().addMessage(event.getComponent().getClientId(FacesContext.getCurrentInstance()),
new FacesMessage("TreeSelectionChangeEvent (" + selectedNode + ") : FIRED"));
// ADD YOUR CODE HERE
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment