Calling javascript from tree component

UI Components for JSF
tatun78
Posts: 22
Joined: 04 Jun 2009, 13:32

10 Jun 2009, 10:28

Hi, Its me again. I would like to call a javascript from <p:tree> tag to refresh the right frame whenever I click a node on the tree. Is there any option? If not then how could I ?

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

10 Jun 2009, 11:07

Yes there's a way but not built-in yet. For now after body is loaded you can do something like;

Code: Select all

yourtree.subscribe("labelClick", function(node) {
          //your code here
       });
And <t:tree widgetVar="yourtree" .../>

tatun78
Posts: 22
Joined: 04 Jun 2009, 13:32

10 Jun 2009, 12:35

Hi Cagatay. I could not get you. My tree.jsp is like this:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@ taglib uri="http://primefaces.prime.com.tr/ui" prefix="p"%>
<%@ taglib uri="primefaces-ui.tld" prefix="s" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<f:view>
<f:loadBundle basename="com.dms.res.caption" var="msg" />
<head>
<title></title>
<p:resources />
</head>
<body>
<style type="text/css">
.yui-skin-sam .yuimenuitemlabel {
color: #000000;
font: Arial;
font-size: 12px;
font-weight: BOLD;

}
</style>
<h:form>
<input type="button" value="Process" onclick="menu.show()"/>&nbsp;&nbsp;<img height="25" src="../images/refresh.gif" /><br><br>

<s:tree value="#{treeBean.model}" cache="false" toggleMode="async" nodeSelectListener="#{treeBean.onNodeSelect}" nodeExpandListener="#{treeBean.onNodeExpand}" nodeCollapseListener="#{treeBean.onNodeCollapse}" ></s:tree> </h:form>

</body>
</f:view>
</html>

please make me understand
yourtree.subscribe("labelClick", function(node) {
//your code here
});


Where I should write this??

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

10 Jun 2009, 13:03

You need to place it in a script like(ideally in <head></head> tags);

Code: Select all

<script type="text/javascript">
function ontreelabelclick() {
    yourtree.subscribe("labelClick", function(node) {
        //your code here
    });
}
</script>
And attach it after body loads, legacy way to do is;

<body onload="ontreelabelclick();">

sanass
Posts: 15
Joined: 10 Jun 2009, 14:55

10 Jun 2009, 15:02

Hi cagatay.. I have a tree component.[<p:tree> tag] I want to call a javascript each time I click on a treenode(just like a onclick method). How can I do this?

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

10 Jun 2009, 15:33

Please see the discussions above.

sanass
Posts: 15
Joined: 10 Jun 2009, 14:55

10 Jun 2009, 15:46

But when I placed the given code <body onload="ontreelabelclick();"> it gives an error saying yourtree as an undefined object. Please advice..

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

10 Jun 2009, 15:47

Do you have <p:tree widgetVar="yourtee"... ?

tatun78
Posts: 22
Joined: 04 Jun 2009, 13:32

11 Jun 2009, 08:25

Thanks Cagatay. This is working fine in Mozilla. However the javascript error "yourtree as an undefined object" is there when I am opening my page in IE6/IE7. Please let me know how to solve this problem. :?

tatun78
Posts: 22
Joined: 04 Jun 2009, 13:32

15 Jun 2009, 12:35

Hi....... I am waiting for your reply.
Calling a javascript applying your suggestion is working fine in Mozilla. However the javascript error "yourtree as an undefined object" is there when I am opening my page in IE6/IE7. Please let me know how to solve this problem.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Baidu [Spider] and 20 guests