« Back to UI Guidelines

Using Yahoo UI in Liferay

Table of Contents [-]

As of Liferay 6, Liferay uses AlloyUI natively, which is built on top of YUI. For more information, see Alloy UI.

Introduction #

The Yahoo! User Interface (YUI) Library is a set of utilities and controls, written in JavaScript, for building richly interactive web applications using techniques such as DOM scripting, DHTML and AJAX. The YUI Library also includes several core CSS resources. All components in the YUI Library have been released as open source under a BSD license and are free for all uses.

To learn more, visit  http://developer.yahoo.com/yui/

Let us create a tree in our portlet . Do the following steps

  1. Download API for tree view control . You can download it from here http://sourceforge.net/project/downloading.php?group_id=165715&filename=yui_2.5.2.zip
  2. Unzip the downloaded zip file under webapps and you will get yui folder.
  3. Create a jsp page named yahoo-ui.jsp and it contains the following
<html>
<head>
<link type="text/css" rel="stylesheet"href="yui/build/treeview/assets/skins/sam/treeview.css"/>
<script src = "/yui/build/yahoo/yahoo-min.js" ></script> 
<script src = "/yui/build/event/event-min.js" ></script> 
<script src = "/yui/build/treeview/treeview-min.js" ></script> 
<script src = "/yui/build/yahoo.js" ></script>
<script type="text/javascript" src="/yui/build/yahoo-dom-event/ yahoo-dom-event.js"></script>
<script type="text/javascript" src="/yui/build/connection/connection-min.js"></script>
</head>

<script>
	function treeInit() {
	// Get the instance of tree	  
var tree = new YAHOO.widget.TreeView(document.getElementById("treeDiv1"));
	// Get the root instance of the tree
	  var root = tree.getRoot();
	 //Add a node (here the node name is First Generation) under root	 
var firstGeneration = new YAHOO.widget.TextNode("First Generation", root, false);
//Add a node(here the node name is first) under firstGeneration and so on.............

	  var first = new YAHOO.widget.TextNode("first", firstGeneration, false); 
	  var second = new YAHOO.widget.TextNode("second", firstGeneration, false); 
	  var third = new YAHOO.widget.TextNode("third", firstGeneration, false);
          var fourth = new YAHOO.widget.TextNode("fourth", firstGeneration, false); 
	  var secondGeneration = new YAHOO.widget.TextNode("Second Generation", root, false); 
	  var label1 = new YAHOO.widget.TextNode("label1", secondGeneration, false);
	  var label2 = new YAHOO.widget.TextNode("label2", secondGeneration, false); 
	  var label3 = new YAHOO.widget.TextNode("label3", secondGeneration, false); 
	  var label4 = new YAHOO.widget.TextNode("label4", secondGeneration, false);
	  var label41 = new YAHOO.widget.TextNode("label4-1", label4 , false);
          var label42 = new YAHOO.widget.TextNode("label4-2", label4 , false);
          var label43 = new YAHOO.widget.TextNode("label4-3", label4 , false);
  	  var label44 = new YAHOO.widget.TextNode("label4-4", label4 , false);
	  var label45 = new YAHOO.widget.TextNode("label4-1", label4 , false);
// Finally draw the tree	//
	  tree.draw();
	}
</script>
</body>
  1. Now create another jsp named view.jsp and it contains the folllowing
<%@ include file="/html/mpower/common/addressbook/yahoo-ui.jsp" %>

Here is the rest

<html>
<body class="yui-skin-sam" onLoad="treeInit()">
	<table cellpadding='2' cellspacing='2' width='98%' >
	<tbody >
		<tr>
			<td>
// Hereby we are mentioning where to show our tree//
			<span id="treeDiv1" ></span>
			</td>
		</tr>
	</tbody>
	</table>
</body>
</html>

N.B. Keep both yahoo-ui.jsp and view.jsp in the same folder

  1. Refresh the the page and you will see the tree
0 Attachments
35946 Views
Average (0 Votes)
The average rating is 0.0 stars out of 5.
Comments
Threaded Replies Author Date
Very good!!! I'll proved it. Thank's. Roberto Tellado January 27, 2010 5:49 AM
Hi I am new in liferay. If it is possible... M G May 2, 2010 10:57 PM
You have to add these two jsp files under, "... Saranya Sethurajan June 23, 2010 4:08 AM
if it is possible please let me know how and... ahmad abuoun October 5, 2011 6:58 AM
I cleaned up the wiki markup to show the code... Bob Fleischman October 7, 2011 7:16 AM
Replace : <link type="text/css"... Kurian Mathew January 23, 2012 4:56 AM

Very good!!! I'll proved it. Thank's.
Posted on 1/27/10 5:49 AM.
Hi

I am new in liferay.
If it is possible please let me know how and where can I add these two jsp files (view.jsp and yahoo-ui.jsp ) into ext (in eclipse) step by step. Thanks
Posted on 5/2/10 10:57 PM.
You have to add these two jsp files under,

" Plugins->portlets->yui-portlet->docroot->view.jsp,yahoo-ui.jsp "
Posted on 6/23/10 4:08 AM in reply to M G.
if it is possible please let me know how and where can I add these two jsp files without ide
Posted on 10/5/11 6:58 AM.
I cleaned up the wiki markup to show the code better. The tags were not working correctly.
Posted on 10/7/11 7:16 AM.
Replace : <link type="text/css" rel="stylesheet"href="yui/build/treeview/assets/skins/sam/treeview.css"/>

With :
<link type="text/css" rel="stylesheet"href="/yui/build/treeview/assets/skins/sam/treeview.css"/>
******­******************
The example will work fine
Posted on 1/23/12 4:56 AM.