问题
I'm trying to display a single selection treeview where you're supposed to select which folder a new item will go under with Primefaces 3.3.1/JSF 2.0. So far, I have populated the tree with folders and subfolders:
But, when I try to select a folder: nothing happens. My .xhtml page looks like this:
<h:form id="createSiteForm">
<label>Under vilken mapp ska sidan ligga under: </label><br />
<p:tree id="treeSingle" value="#{siteBean.root}" var="node"
selectionMode="single"
selection="#{siteBean.selectedNode}" dynamic="true" cache="false">
<p:treeNode>
<h:outputText value="#{node}" />
</p:treeNode>
</p:tree>
</h:form>
And my managed bean:
@ManagedBean(name = "siteBean")
@RequestScoped
public class SiteBean implements Serializable {
private TreeNode root;
private TreeNode selectedNode;
public SiteBean(){
this.loadTreeNodes();
}
@SuppressWarnings("rawtypes")
public void loadTreeNodes(){
try {
WebDB db = new WebDB();
List<Folder> folders = db.getRootFolders();
root = new DefaultTreeNode("Root", null);
boolean first = true;
db = null;
for (Iterator fi = folders.iterator(); fi.hasNext();){
Folder folder = (Folder) fi.next();
TreeNode node = new DefaultTreeNode(folder.getName(), root);
if(first){
node.setSelected(true);
selectedNode = node;
first = false;
}
this.findNodeChildren(folder.getId(), node);
}
} catch (DatabaseException e) {
e.printStackTrace();
}
}
@SuppressWarnings("rawtypes")
private void findNodeChildren(Long id, TreeNode parent){
try {
WebDB db = new WebDB();
List<Folder> fChildren = db.getFolderChildren(id);
db = null;
if(fChildren != null && fChildren.size() > 0){
for (Iterator fi = fChildren.iterator(); fi.hasNext();){
Folder folder = (Folder) fi.next();
TreeNode node = new DefaultTreeNode(folder.getName(), parent);
this.findNodeChildren(folder.getId(), node);
}
}
} catch (DatabaseException e) {
e.printStackTrace();
}
}
public TreeNode getRoot() {
return root;
}
public TreeNode getSelectedNode() {
return selectedNode;
}
public void setSelectedNode(TreeNode selectedNode) {
this.selectedNode = selectedNode;
}
}
And I get this strange jQuery error: Uncaught TypeError: Cannot call method 'remove' of null in primefaces.js?ln=primefaces. I can't find any information about this error :S
回答1:
And I get this strange jQuery error: Uncaught TypeError: Cannot call method 'remove' of null in primefaces.js?ln=primefaces.
Those kind of jQuery errors are typically caused by having duplicate different versioned jQuery JS files loaded by the webapp. PrimeFaces as being a jQuery-based JSF component library already automatically loads jQuery by itself. This problem suggests that you're for some reason manually loading another jQuery JS file yourself on top of PrimeFaces one via <script>/<h:outputScript>. If you remove them, then this error should disappear.
If you happen to have a page wherein you'd like to use some jQuery, but the page itself doesn't utilize any PrimeFaces component and thus doesn't necessarily have PrimeFaces-bundled jQuery automatically loaded, then you can always explicitly load it yourself by simply adding the following line:
<h:outputScript library="primefaces" name="jquery/jquery.js" target="head" />
This will explicitly load the PrimeFaces library-bundled jQuery file. Note: the target="head" can be omitted when it's already inside the <h:head>. Otherwise, e.g. when inside <h:body> or <ui:define> of a template client, it would be automatically relocated to head. Another note: you can safely use this line in a page which actually requires PrimeFaces-bundled jQuery. It won't end up in a duplciate load.
来源:https://stackoverflow.com/questions/18079245/uncaught-typeerror-cannot-call-method-remove-of-null-in-primefaces-jsln-prim