Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Thursday, September 12, 2013

PrimeFaces horizontal tree - expand all, collapse all

I'm working as a consultant on a project that is using PrimeFaces, namely the horizontal tree component.

It's a great tool, but took some custom javascript to make it fit our needs. As expected, the client requested an "Expand All" button. I was hoping I could use the PrimeFaces javascript object to call a pre-built function, but I didn't find any information on it.

I quickly threw this together. I won't do much explaining, because the code should explain itself. This should also work on the vertical tree, but you will have to modify the class names to match your tree's expand and collapse icons.

treeController.collapse = function() {
 // I wanted to keep the root expanded, but this part can be
 // removed or changed to select the tree div by ID
 var treeExcludingRoot = $(".ui-treenode-children-container").first();
 // find all of the minus icons, and trigger their onclick event
 $(".ui-tree-toggler.ui-icon-minus", treeExcludingRoot).click();
}

treeController.expand = function() {
 // this works the same way, but with the plus icon
 var treeExcludingRoot = $(".ui-treenode-children-container").first();
 $(".ui-tree-toggler.ui-icon-plus", treeExcludingRoot).click();
}

You could write it yourself, but why bother? Hope somebody gets to copy and paste it.

Thursday, June 13, 2013

Tomcat is ignoring changes to struts.xml, other config files and Java class files!

I was taking training on Struts 2, which involved importing some existing "Lab" projects into my Eclipse environment. Everything went smoothly the first time I ran the project, but after making updates and re-running the project, the server would not reflect any of my changes!

For hours, myself and a more senior developer banged our heads trying to figure out this problem. We installed a different version of Tomcat, cleaned the project and the working directory, cleared cache, etc. and nothing worked! From simple outputs to the console in class files, to adding or renaming actions in struts.xml, the project always executed as if it were the first run.

Per usual, the most troubling problem had the simplest solution. The person who originally created the project had the JRE imported from an unusual location. Upon import, I received errors saying java and javax could not be resolved. I hovered over an import statement, and used the "Fix project setup..." option to automatically add Eclipse's default JRE to the build path.

Though it properly added the JRE, it did not remove the old JRE location from the build path. Apparently this can cause some very mysterious behavior... As a last resort we checked the build path, and removed the bad JRE. Problem solved! Everything began functioning as expected.

Noobs using Eclipse Indigo: Right click on the project and select Build Path > Configure Build Path.... Under the Libraries tab, see if you have two JRE libraries. If so, delete the one with the little red X.