<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2894230897541710318</id><updated>2024-10-24T16:48:27.067-07:00</updated><title type='text'>Icefaces extentions and examples</title><subtitle type='html'>Tutorials, tip, custom components and examples for jsf and icefaces</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://icefacesextentionsandexamples.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2894230897541710318/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://icefacesextentionsandexamples.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/03730825366007127346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2894230897541710318.post-1540701979847122823</id><published>2010-08-11T01:03:00.005-07:00</published><updated>2010-08-11T01:03:58.454-07:00</updated><title type='text'>how to create custom loop jsf component: source code and example</title><content type='html'>
&lt;b&gt;Explanation&lt;/b&gt;&lt;br /&gt;
	We know ui:repeat tag. Generally it loop on inner tags.  
	Real application need more features. 
	&lt;br /&gt; 
	Just few examples: paging, need for &quot;index&quot;, different styles for odd item. 
	&lt;br /&gt; 
	This simple yet important features are difficult to implement with &quot;ui:repeat&quot; tag 
	&lt;br /&gt; 
	So instead of ui:repeat, use custom &quot;loop&quot; component. 
	&lt;br /&gt; 
	Pros: every programmer, even not-jsf, can understand it.  
	CSS is transparent: what you see is what you get. 
	&lt;br /&gt; 
	Customization is simple too.  
	&lt;br /&gt; 
	Here is explanation and source code for &#39;loop&#39; component 
&lt;br /&gt;
&lt;br /&gt; 
New to Java, JSF, Icefaces? Here is some links to start with:  
&lt;br /&gt;
&lt;a href=&quot;http://jsf-icefaces-java-gettingstarted.blogspot.com/2010/06/why-and-when-use-icefaces.html&quot;&gt;Why and when use ICEFACES?&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://jsf-icefaces-java-gettingstarted.blogspot.com/2010/06/first-steps-with-jsf-and-java.html&quot;&gt;First steps with jsf and java&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://jsf-icefaces-java-gettingstarted.blogspot.com/2010/07/icefaces-without-icefaces.html&quot;&gt;icefaces without icefaces&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
	&lt;b&gt;Step 1.&lt;/b&gt; Create java class for component 
&lt;br /&gt;&lt;b&gt;null&lt;/b&gt;
&lt;pre name=&quot;code&quot; class=&quot;java&quot;&gt;
package com.alternative.iceext.loop;

import java.io.IOException;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;

import com.icesoft.faces.component.panelseries.PanelSeries;

public class Loop extends PanelSeries {
	public static final String COMPONENT_TYPE = &amp;quot;com.alternative.iceext.loop.Loop&amp;quot;;

	public static final String RENDERER_TYPE = &amp;quot;com.alternative.iceext.loop.LoopRenderer&amp;quot;;

	public final static String COMPONENT_FAMILY = &amp;quot;com.alternative.iceext.loop&amp;quot;;

	public String getFamily() {
		return COMPONENT_FAMILY;
	}

	public String getRendererType() {
		return RENDERER_TYPE;
	}

	String varMod;

	int modValueInt = 2;

	String modValue;

	String rowIndexVar;
	
	
	public void encodeBegin(FacesContext context) throws IOException {
		super.encodeBegin(context);
	}
	public void encodeEnd(FacesContext context) throws IOException {
		super.encodeEnd(context);
	}

	public String getRowIndexVar() {
		if (rowIndexVar == null) {
			rowIndexVar = &amp;quot;rowIndex&amp;quot;;
		}
		return rowIndexVar;
	}

	public void setRowIndexVar(String rowIndexVar) {
		this.rowIndexVar = rowIndexVar;
	}

	public String getModValue() {
		return modValue;
	}

	public void setModValue(String modValue) {
		this.modValue = modValue;
		if (modValue != null) {
			try {
				modValueInt = 2;
				modValueInt = Integer.parseInt(modValue);
			} catch (Exception e) {

			}
		}
	}

	public String getVarMod() {
		if (varMod == null) {
			varMod = &amp;quot;rowMod&amp;quot;;
		}
		return varMod;
	}

	public void setVarMod(String varMod) {
		this.varMod = varMod;

	}

	public void setRowIndex(int rowIndex) {
		super.setRowIndex(rowIndex);
		int modValue = rowIndex % modValueInt;
		FacesContext.getCurrentInstance().getExternalContext().getRequestMap()
				.put(getVarMod(), modValue);
		FacesContext.getCurrentInstance().getExternalContext().getRequestMap()
				.put(getRowIndexVar(), rowIndex);
	}
	
	public void forceRefresh() {
		savedChildren.clear();
	}

	public void recurseForcedRefresh() { 
		recurseForcedRefresh(this);
	}
	
	private void recurseForcedRefresh(UIComponent comp) { 
	 &amp;nbsp; &amp;nbsp;if (comp instanceof Loop) {
	 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;((Loop)comp).forceRefresh(); 
	 &amp;nbsp; &amp;nbsp;}
	 &amp;nbsp; &amp;nbsp;java.util.Iterator kids = comp.getFacetsAndChildren(); 
	 &amp;nbsp; &amp;nbsp;while(kids.hasNext()) {
	 &amp;nbsp; &amp;nbsp;	recurseForcedRefresh((UIComponent)kids.next()); 
	 &amp;nbsp; &amp;nbsp;}
	 &amp;nbsp; &amp;nbsp;	
	} 

}
&lt;/pre&gt;
&lt;br /&gt;
	&lt;b&gt;Step 2.&lt;/b&gt;Create java class for renderer 
&lt;br /&gt;&lt;b&gt;null&lt;/b&gt;
&lt;pre name=&quot;code&quot; class=&quot;java&quot;&gt;
package com.alternative.iceext.loop;

import java.io.IOException;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;

import com.icesoft.faces.component.panelseries.PanelSeries;

public class Loop extends PanelSeries {
	public static final String COMPONENT_TYPE = &amp;quot;com.alternative.iceext.loop.Loop&amp;quot;;

	public static final String RENDERER_TYPE = &amp;quot;com.alternative.iceext.loop.LoopRenderer&amp;quot;;

	public final static String COMPONENT_FAMILY = &amp;quot;com.alternative.iceext.loop&amp;quot;;

	public String getFamily() {
		return COMPONENT_FAMILY;
	}

	public String getRendererType() {
		return RENDERER_TYPE;
	}

	String varMod;

	int modValueInt = 2;

	String modValue;

	String rowIndexVar;
	
	
	public void encodeBegin(FacesContext context) throws IOException {
		super.encodeBegin(context);
	}
	public void encodeEnd(FacesContext context) throws IOException {
		super.encodeEnd(context);
	}

	public String getRowIndexVar() {
		if (rowIndexVar == null) {
			rowIndexVar = &amp;quot;rowIndex&amp;quot;;
		}
		return rowIndexVar;
	}

	public void setRowIndexVar(String rowIndexVar) {
		this.rowIndexVar = rowIndexVar;
	}

	public String getModValue() {
		return modValue;
	}

	public void setModValue(String modValue) {
		this.modValue = modValue;
		if (modValue != null) {
			try {
				modValueInt = 2;
				modValueInt = Integer.parseInt(modValue);
			} catch (Exception e) {

			}
		}
	}

	public String getVarMod() {
		if (varMod == null) {
			varMod = &amp;quot;rowMod&amp;quot;;
		}
		return varMod;
	}

	public void setVarMod(String varMod) {
		this.varMod = varMod;

	}

	public void setRowIndex(int rowIndex) {
		super.setRowIndex(rowIndex);
		int modValue = rowIndex % modValueInt;
		FacesContext.getCurrentInstance().getExternalContext().getRequestMap()
				.put(getVarMod(), modValue);
		FacesContext.getCurrentInstance().getExternalContext().getRequestMap()
				.put(getRowIndexVar(), rowIndex);
	}
	
	public void forceRefresh() {
		savedChildren.clear();
	}

	public void recurseForcedRefresh() { 
		recurseForcedRefresh(this);
	}
	
	private void recurseForcedRefresh(UIComponent comp) { 
	 &amp;nbsp; &amp;nbsp;if (comp instanceof Loop) {
	 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;((Loop)comp).forceRefresh(); 
	 &amp;nbsp; &amp;nbsp;}
	 &amp;nbsp; &amp;nbsp;java.util.Iterator kids = comp.getFacetsAndChildren(); 
	 &amp;nbsp; &amp;nbsp;while(kids.hasNext()) {
	 &amp;nbsp; &amp;nbsp;	recurseForcedRefresh((UIComponent)kids.next()); 
	 &amp;nbsp; &amp;nbsp;}
	 &amp;nbsp; &amp;nbsp;	
	} 

}
&lt;/pre&gt;
&lt;br /&gt;
	&lt;b&gt;Step 3.&lt;/b&gt; Define components in faces-config.xml 
&lt;br /&gt;&lt;b&gt;null&lt;/b&gt;
&lt;pre name=&quot;code&quot; class=&quot;xml&quot;&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;

&amp;lt;faces-config xmlns=&amp;quot;http://java.sun.com/xml/ns/javaee&amp;quot;
	xmlns:xsi=&amp;quot;http://www.w3.org/2001/XMLSchema-instance&amp;quot;
	xsi:schemaLocation=&amp;quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd&amp;quot;
	version=&amp;quot;1.2&amp;quot;&amp;gt;
	&amp;lt;application&amp;gt;
		&amp;lt;view-handler&amp;gt;com.icesoft.faces.facelets.D2DFaceletViewHandler&amp;lt;/view-handler&amp;gt;
	&amp;lt;/application&amp;gt;
	&amp;lt;component&amp;gt;
		&amp;lt;component-type&amp;gt;com.alternative.iceext.loop.Loop&amp;lt;/component-type&amp;gt;
		&amp;lt;component-class&amp;gt;com.alternative.iceext.loop.Loop&amp;lt;/component-class&amp;gt;
	&amp;lt;/component&amp;gt;
	&amp;lt;component&amp;gt;
		&amp;lt;component-type&amp;gt;com.alternative.iceext.tags.Tr&amp;lt;/component-type&amp;gt;
		&amp;lt;component-class&amp;gt;com.alternative.iceext.tags.Tr&amp;lt;/component-class&amp;gt;
	&amp;lt;/component&amp;gt;
	&amp;lt;managed-bean&amp;gt;
		&amp;lt;managed-bean-name&amp;gt;testLoops&amp;lt;/managed-bean-name&amp;gt;
		&amp;lt;managed-bean-class&amp;gt;com.alternative.beans.TestLoops&amp;lt;/managed-bean-class&amp;gt;
		&amp;lt;managed-bean-scope&amp;gt;session&amp;lt;/managed-bean-scope&amp;gt;
	&amp;lt;/managed-bean&amp;gt;
	&amp;lt;render-kit&amp;gt;
		&amp;lt;renderer&amp;gt;
			&amp;lt;component-family&amp;gt;com.alternative.iceext.tags&amp;lt;/component-family&amp;gt;
			&amp;lt;renderer-type&amp;gt;com.alternative.iceext.tags.TrRenderer&amp;lt;/renderer-type&amp;gt;
			&amp;lt;renderer-class&amp;gt;com.alternative.iceext.tags.TrRenderer&amp;lt;/renderer-class&amp;gt;
		&amp;lt;/renderer&amp;gt;
		&amp;lt;renderer&amp;gt;
			&amp;lt;component-family&amp;gt;com.alternative.iceext.loop&amp;lt;/component-family&amp;gt;
			&amp;lt;renderer-type&amp;gt;com.alternative.iceext.loop.LoopRenderer&amp;lt;/renderer-type&amp;gt;
			&amp;lt;renderer-class&amp;gt;com.alternative.iceext.loop.LoopRenderer&amp;lt;/renderer-class&amp;gt;
		&amp;lt;/renderer&amp;gt;
	&amp;lt;/render-kit&amp;gt;
&amp;lt;/faces-config&amp;gt;
&lt;/pre&gt;
&lt;br /&gt;
	&lt;b&gt;Step 4.&lt;/b&gt; Define tag library in META-INF directory in you source code, or  place you choose. 
&lt;br /&gt;&lt;b&gt;null&lt;/b&gt;
&lt;pre name=&quot;code&quot; class=&quot;xml&quot;&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;
&amp;lt;!DOCTYPE taglib PUBLIC
 &amp;nbsp;&amp;quot;-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN&amp;quot;
 &amp;nbsp;&amp;quot;http://java.sun.com/dtd//web-jsptaglibrary_1_2.dtd&amp;quot;&amp;gt;

&amp;lt;taglib&amp;gt;

 &amp;nbsp;&amp;lt;tlib-version&amp;gt;1.8.0&amp;lt;/tlib-version&amp;gt;
 &amp;nbsp;&amp;lt;jsp-version&amp;gt;1.2&amp;lt;/jsp-version&amp;gt;
 &amp;nbsp;&amp;lt;short-name&amp;gt;iceext&amp;lt;/short-name&amp;gt;
 &amp;nbsp;&amp;lt;uri&amp;gt;http://alternative.com/iceext/component&amp;lt;/uri&amp;gt;
 &amp;nbsp;&amp;lt;display-name&amp;gt;ICEfaces Extention&amp;lt;/display-name&amp;gt;

 &amp;nbsp;&amp;lt;tag&amp;gt;
 &amp;nbsp; &amp;nbsp;&amp;lt;name&amp;gt;loop&amp;lt;/name&amp;gt;
 &amp;nbsp; &amp;nbsp;&amp;lt;tag-class&amp;gt;&amp;lt;/tag-class&amp;gt;
 &amp;nbsp; &amp;nbsp;&amp;lt;body-content&amp;gt;empty&amp;lt;/body-content&amp;gt;
	&amp;lt;attribute&amp;gt;
		&amp;lt;name&amp;gt;id&amp;lt;/name&amp;gt;
		&amp;lt;required&amp;gt;false&amp;lt;/required&amp;gt;
		&amp;lt;rtexprvalue&amp;gt;false&amp;lt;/rtexprvalue&amp;gt;
	&amp;lt;/attribute&amp;gt;
	&amp;lt;attribute&amp;gt;
		&amp;lt;name&amp;gt;value&amp;lt;/name&amp;gt;
		&amp;lt;required&amp;gt;false&amp;lt;/required&amp;gt;
		&amp;lt;rtexprvalue&amp;gt;false&amp;lt;/rtexprvalue&amp;gt;
	&amp;lt;/attribute&amp;gt;
	&amp;lt;attribute&amp;gt;
		&amp;lt;name&amp;gt;var&amp;lt;/name&amp;gt;
		&amp;lt;required&amp;gt;false&amp;lt;/required&amp;gt;
		&amp;lt;rtexprvalue&amp;gt;false&amp;lt;/rtexprvalue&amp;gt;
	&amp;lt;/attribute&amp;gt;
	&amp;lt;attribute&amp;gt;
		&amp;lt;name&amp;gt;varMod&amp;lt;/name&amp;gt;
		&amp;lt;required&amp;gt;false&amp;lt;/required&amp;gt;
		&amp;lt;rtexprvalue&amp;gt;false&amp;lt;/rtexprvalue&amp;gt;
	&amp;lt;/attribute&amp;gt;
	&amp;lt;attribute&amp;gt;
		&amp;lt;name&amp;gt;modValue&amp;lt;/name&amp;gt;
		&amp;lt;required&amp;gt;false&amp;lt;/required&amp;gt;
		&amp;lt;rtexprvalue&amp;gt;false&amp;lt;/rtexprvalue&amp;gt;
	&amp;lt;/attribute&amp;gt;
	&amp;lt;attribute&amp;gt;
		&amp;lt;name&amp;gt;rowIndexVar&amp;lt;/name&amp;gt;
		&amp;lt;required&amp;gt;false&amp;lt;/required&amp;gt;
		&amp;lt;rtexprvalue&amp;gt;false&amp;lt;/rtexprvalue&amp;gt;
	&amp;lt;/attribute&amp;gt;
 &amp;nbsp;&amp;lt;/tag&amp;gt;
 &amp;nbsp;&amp;lt;tag&amp;gt;
 &amp;nbsp; &amp;nbsp;&amp;lt;name&amp;gt;tr&amp;lt;/name&amp;gt;
 &amp;nbsp; &amp;nbsp;&amp;lt;tag-class&amp;gt;&amp;lt;/tag-class&amp;gt;
 &amp;nbsp; &amp;nbsp;&amp;lt;body-content&amp;gt;empty&amp;lt;/body-content&amp;gt;
	&amp;lt;attribute&amp;gt;
		&amp;lt;name&amp;gt;id&amp;lt;/name&amp;gt;
		&amp;lt;required&amp;gt;false&amp;lt;/required&amp;gt;
		&amp;lt;rtexprvalue&amp;gt;false&amp;lt;/rtexprvalue&amp;gt;
	&amp;lt;/attribute&amp;gt;
	&amp;lt;attribute&amp;gt;
		&amp;lt;name&amp;gt;disabled&amp;lt;/name&amp;gt;
		&amp;lt;required&amp;gt;false&amp;lt;/required&amp;gt;
		&amp;lt;rtexprvalue&amp;gt;false&amp;lt;/rtexprvalue&amp;gt;
	&amp;lt;/attribute&amp;gt;
	&amp;lt;attribute&amp;gt;
		&amp;lt;name&amp;gt;rendered&amp;lt;/name&amp;gt;
		&amp;lt;required&amp;gt;false&amp;lt;/required&amp;gt;
		&amp;lt;rtexprvalue&amp;gt;false&amp;lt;/rtexprvalue&amp;gt;
	&amp;lt;/attribute&amp;gt;
 &amp;nbsp;&amp;lt;/tag&amp;gt;
&amp;lt;/taglib&amp;gt;
 &amp;nbsp;
&lt;/pre&gt;
&lt;br /&gt;
	This is simple example how to use it.  
&lt;br /&gt;&lt;b&gt;fragment from LoopComponentSourceCode.jspx&lt;/b&gt;
&lt;pre name=&quot;code&quot; class=&quot;xml&quot;&gt;
	&amp;lt;table&amp;gt; 
		&amp;lt;caption&amp;gt;Loop component source code&amp;lt;/caption&amp;gt; 
		&amp;lt;tr&amp;gt; 
			&amp;lt;td&amp;gt;Name&amp;lt;/td&amp;gt; 
			&amp;lt;td&amp;gt;Phone&amp;lt;/td&amp;gt; 
			&amp;lt;td&amp;gt;Index&amp;lt;/td&amp;gt; 
		&amp;lt;/tr&amp;gt; 
		&amp;lt;iceext:loop value=&amp;quot;#{loopComponentSourceCodeBean.rows}&amp;quot; var=&amp;quot;row&amp;quot; indexVar=&amp;quot;rowIndexVar&amp;quot; &amp;gt; 
			&amp;lt;tr&amp;gt; 
				&amp;lt;td&amp;gt;&amp;lt;ice:outputText value=&amp;quot;#{row.name}&amp;quot; /&amp;gt;&amp;lt;/td&amp;gt; 
				&amp;lt;td&amp;gt;&amp;lt;ice:outputText value=&amp;quot;#{row.phone}&amp;quot; /&amp;gt;&amp;lt;/td&amp;gt; 
				&amp;lt;td&amp;gt;&amp;lt;ice:outputText value=&amp;quot;#{index}&amp;quot; /&amp;gt;&amp;lt;/td&amp;gt; 
			&amp;lt;/tr&amp;gt; 
		&amp;lt;/iceext:loop&amp;gt; 
	&amp;lt;/table&amp;gt; 
&lt;/pre&gt;
&lt;br /&gt;
This is main entry point. Its referenced by &#39;loopComponentSourceCodeBean&#39; from faces-config.xml 
&lt;br /&gt;&lt;b&gt;com.gpost.jsfexamples.loopComponentSourceCode.LoopComponentSourceCodeBean&lt;/b&gt;
&lt;pre name=&quot;code&quot; class=&quot;java&quot;&gt;
package com.gpost.jsfexamples.loopComponentSourceCode;

import java.util.ArrayList;
import java.util.List;

import com.gpost.jsfexamples.tableWithDeleteOnClick.ManWithPhone;

/*
* Java class for example &#39;Loop component source code&#39;
* referenced as &#39;loopComponentSourceCodeBean&#39; from faces-config.xml, 
* used in &#39;LoopComponentSourceCode.jspx&#39;
*/
public class LoopComponentSourceCodeBean{

	List&amp;lt;ManWithPhone&amp;gt; rows = null;
	
	public List&amp;lt;ManWithPhone&amp;gt; getRows() {
		if (rows == null) {
			rows = new ArrayList&amp;lt;ManWithPhone&amp;gt;();
			// create same sample data...
			rows.add(new ManWithPhone(&amp;quot;Gary&amp;quot;, &amp;quot;1234-6767&amp;quot;));
			rows.add(new ManWithPhone(&amp;quot;Bob&amp;quot;, &amp;quot;5678-4553&amp;quot;));
			rows.add(new ManWithPhone(&amp;quot;John&amp;quot;, &amp;quot;5698-4333&amp;quot;));
		}
		return rows;
	}



} // end of class
&lt;/pre&gt;
&lt;br /&gt;
This class defines data in &#39;row&#39;.  
&lt;br /&gt;&lt;b&gt;com.gpost.jsfexamples.loopComponentSourceCode.ManWithPhone&lt;/b&gt;
&lt;pre name=&quot;code&quot; class=&quot;java&quot;&gt;
package com.gpost.jsfexamples.loopComponentSourceCode;

public class ManWithPhone {
	public ManWithPhone(String name, String phone) {
		super();
		this.name = name;
		this.phone = phone;
	}

	String name;
	
	String phone;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;b&gt;part of faces-config.xml&lt;/b&gt;
&lt;pre name=&quot;code&quot; class=&quot;xml&quot;&gt;
&amp;lt;managed-bean&amp;gt;
 &amp;lt;managed-bean-name&amp;gt;loopComponentSourceCodeBean&amp;lt;/managed-bean-name&amp;gt;
 &amp;lt;managed-bean-class&amp;gt;com.gpost.jsfexamples.loopComponentSourceCode.LoopComponentSourceCodeBean&amp;lt;/managed-bean-class&amp;gt;
 &amp;lt;managed-bean-scope&amp;gt;session&amp;lt;/managed-bean-scope&amp;gt;

&amp;lt;/managed-bean&amp;gt;
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;conclusion&lt;/b&gt;&lt;br /&gt;
As we saw in this example, you can create custom loop component and then use it with simple html/css, then 
add some binding to your java beans and you get very flexible, easily customizable layout 
with more features like paging, indexing, and mod variables. 
&lt;br /&gt;
</content><link rel='replies' type='application/atom+xml' href='http://icefacesextentionsandexamples.blogspot.com/feeds/1540701979847122823/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://icefacesextentionsandexamples.blogspot.com/2010/08/how-to-create-custom-loop-jsf-component.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2894230897541710318/posts/default/1540701979847122823'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2894230897541710318/posts/default/1540701979847122823'/><link rel='alternate' type='text/html' href='http://icefacesextentionsandexamples.blogspot.com/2010/08/how-to-create-custom-loop-jsf-component.html' title='how to create custom loop jsf component: source code and example'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/03730825366007127346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2894230897541710318.post-3809658775895793625</id><published>2010-08-11T01:03:00.003-07:00</published><updated>2010-08-11T01:03:55.125-07:00</updated><title type='text'>Getting started with custom loop component</title><content type='html'>
&lt;b&gt;Explanation&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt; 
New to Java, JSF, Icefaces? Here is some links to start with:  
&lt;br /&gt;
&lt;a href=&quot;http://jsf-icefaces-java-gettingstarted.blogspot.com/2010/06/why-and-when-use-icefaces.html&quot;&gt;Why and when use ICEFACES?&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://jsf-icefaces-java-gettingstarted.blogspot.com/2010/06/first-steps-with-jsf-and-java.html&quot;&gt;First steps with jsf and java&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://jsf-icefaces-java-gettingstarted.blogspot.com/2010/07/icefaces-without-icefaces.html&quot;&gt;icefaces without icefaces&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
	We know ui:repeat tag. Generally it loop on inner tags.  
	Real application need more features. 
	&lt;br /&gt; 
	Just few examples: paging, need for &quot;index&quot;, different styles for odd item. 
	&lt;br /&gt; 
	This simple yet important features are difficult to implement with &quot;ui:repeat&quot; tag 
	&lt;br /&gt; 
	So instead of ui:repeat, use custom &quot;loop&quot; component. 
	&lt;br /&gt; 
	Pros: every programmer, even not-jsf, can understand it.  
	CSS is transparent: what you see is what you get. 
	&lt;br /&gt; 
	Customization is simple too.  
	&lt;br /&gt; 
	Use you favorite HTML editor, or JSF editor together with CSS tools 
	to customize every aspect of this example, its easy! 
&lt;br /&gt;&lt;b&gt;fragment from LoopGettingStarted.jspx&lt;/b&gt;
&lt;pre name=&quot;code&quot; class=&quot;xml&quot;&gt;
	&amp;lt;table&amp;gt; 
		&amp;lt;caption&amp;gt;Loop getting started&amp;lt;/caption&amp;gt; 
		&amp;lt;tr&amp;gt; 
			&amp;lt;td&amp;gt;Name&amp;lt;/td&amp;gt; 
			&amp;lt;td&amp;gt;Phone&amp;lt;/td&amp;gt; 
			&amp;lt;td&amp;gt;Index&amp;lt;/td&amp;gt; 
		&amp;lt;/tr&amp;gt; 
		&amp;lt;iceext:loop value=&amp;quot;#{loopGettingStartedBean.rows}&amp;quot; var=&amp;quot;row&amp;quot; rowIndexVar=&amp;quot;rowIndexVar&amp;quot; &amp;gt; 
			&amp;lt;tr&amp;gt; 
				&amp;lt;td&amp;gt;&amp;lt;ice:outputText value=&amp;quot;#{row.name}&amp;quot; /&amp;gt;&amp;lt;/td&amp;gt; 
				&amp;lt;td&amp;gt;&amp;lt;ice:outputText value=&amp;quot;#{row.phone}&amp;quot; /&amp;gt;&amp;lt;/td&amp;gt; 
				&amp;lt;td&amp;gt;&amp;lt;ice:outputText value=&amp;quot;#{rowIndexVar}&amp;quot; /&amp;gt;&amp;lt;/td&amp;gt; 
			&amp;lt;/tr&amp;gt; 
		&amp;lt;/iceext:loop&amp;gt; 
	&amp;lt;/table&amp;gt; 
&lt;/pre&gt;
&lt;br /&gt;
This is main entry point. Its referenced by &#39;loopGettingStartedBean&#39; from faces-config.xml 
&lt;br /&gt;&lt;b&gt;com.gpost.jsfexamples.loopGettingStarted.LoopGettingStartedBean&lt;/b&gt;
&lt;pre name=&quot;code&quot; class=&quot;java&quot;&gt;
package com.gpost.jsfexamples.loopGettingStarted;

import java.util.ArrayList;
import java.util.List;



/*
* Java class for example &#39;Loop getting started&#39;
* referenced as &#39;loopGettingStartedBean&#39; from faces-config.xml, 
* used in &#39;LoopGettingStarted.jspx&#39;
*/
public class LoopGettingStartedBean{

	List&amp;lt;ManWithPhone&amp;gt; rows = null;
	
	public List&amp;lt;ManWithPhone&amp;gt; getRows() {
		if (rows == null) {
			rows = new ArrayList&amp;lt;ManWithPhone&amp;gt;();
			// create same sample data...
			rows.add(new ManWithPhone(&amp;quot;Gary&amp;quot;, &amp;quot;1234-6767&amp;quot;));
			rows.add(new ManWithPhone(&amp;quot;Bob&amp;quot;, &amp;quot;5678-4553&amp;quot;));
			rows.add(new ManWithPhone(&amp;quot;John&amp;quot;, &amp;quot;5698-4333&amp;quot;));
		}
		return rows;
	}



} // end of class
&lt;/pre&gt;
&lt;br /&gt;
This class defines data in &#39;row&#39;.  
&lt;br /&gt;&lt;b&gt;com.gpost.jsfexamples.loopGettingStarted.ManWithPhone&lt;/b&gt;
&lt;pre name=&quot;code&quot; class=&quot;java&quot;&gt;
package com.gpost.jsfexamples.loopGettingStarted;

public class ManWithPhone {
	public ManWithPhone(String name, String phone) {
		super();
		this.name = name;
		this.phone = phone;
	}

	String name;
	
	String phone;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;b&gt;part of faces-config.xml&lt;/b&gt;
&lt;pre name=&quot;code&quot; class=&quot;xml&quot;&gt;
&amp;lt;managed-bean&amp;gt;
 &amp;lt;managed-bean-name&amp;gt;loopGettingStartedBean&amp;lt;/managed-bean-name&amp;gt;
 &amp;lt;managed-bean-class&amp;gt;com.gpost.jsfexamples.loopGettingStarted.LoopGettingStartedBean&amp;lt;/managed-bean-class&amp;gt;
 &amp;lt;managed-bean-scope&amp;gt;session&amp;lt;/managed-bean-scope&amp;gt;

&amp;lt;/managed-bean&amp;gt;
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;conclusion&lt;/b&gt;&lt;br /&gt;
As we saw in this example, you can use loop with simple html/css, then 
add some binding to your java beans and you get very flexible, easily customizable layout 
with more features like paging, indexing, and mod variables. 
&lt;br /&gt;
</content><link rel='replies' type='application/atom+xml' href='http://icefacesextentionsandexamples.blogspot.com/feeds/3809658775895793625/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://icefacesextentionsandexamples.blogspot.com/2010/08/getting-started-with-custom-loop.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2894230897541710318/posts/default/3809658775895793625'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2894230897541710318/posts/default/3809658775895793625'/><link rel='alternate' type='text/html' href='http://icefacesextentionsandexamples.blogspot.com/2010/08/getting-started-with-custom-loop.html' title='Getting started with custom loop component'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/03730825366007127346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2894230897541710318.post-8327559658291067244</id><published>2010-08-11T01:03:00.001-07:00</published><updated>2010-08-11T01:03:51.980-07:00</updated><title type='text'>Example for custom loop jsf component with zebra style and index</title><content type='html'>
&lt;b&gt;Explanation&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt; 
New to Java, JSF, Icefaces? Here is some links to start with:  
&lt;br /&gt;
&lt;a href=&quot;http://jsf-icefaces-java-gettingstarted.blogspot.com/2010/06/why-and-when-use-icefaces.html&quot;&gt;Why and when use ICEFACES?&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://jsf-icefaces-java-gettingstarted.blogspot.com/2010/06/first-steps-with-jsf-and-java.html&quot;&gt;First steps with jsf and java&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://jsf-icefaces-java-gettingstarted.blogspot.com/2010/07/icefaces-without-icefaces.html&quot;&gt;icefaces without icefaces&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
	Table and other controls are better when inner components 
	displayed in different styles, on &#39;mod&#39; style or &#39;zebra style&#39; 
	Lets see how to do it without complexity, compact and easy way. 
	 
	 
	&lt;br /&gt; 
	This simple yet important features are difficult to implement with &quot;ui:repeat&quot; tag 
	&lt;br /&gt; 
	Instead of ui:repeat, use custom &quot;loop&quot; component. 
	&lt;br /&gt; 
	Pros: every programmer, even not-jsf, can understand it.  
	CSS is transparent: what you see is what you get. 
	&lt;br /&gt; 
	Customization is simple too.  
	&lt;br /&gt; 
	Use you favorite HTML editor, or JSF editor together with CSS tools 
	to customize every aspect of this example, its easy! 
&lt;br /&gt;&lt;b&gt;fragment from LoopWithZebraStyleAndIndex.jspx&lt;/b&gt;
&lt;pre name=&quot;code&quot; class=&quot;xml&quot;&gt;
	 &amp;lt;style&amp;gt; 
	 .zebraStyle0 { 
	 	background-color: gray; 
	 } 
	 .zebraStyle1 { 
	 	background-color: blue; 
	 } 
	 .zebraStyle2 { 
	 	background-color: navy; 
	 } 
	 &amp;lt;/style&amp;gt; 
	&amp;lt;table&amp;gt; 
		&amp;lt;caption&amp;gt;Loop with zebra style and index&amp;lt;/caption&amp;gt; 
		&amp;lt;tr&amp;gt; 
			&amp;lt;td&amp;gt;Name&amp;lt;/td&amp;gt; 
			&amp;lt;td&amp;gt;Phone&amp;lt;/td&amp;gt; 
			&amp;lt;td&amp;gt;Index&amp;lt;/td&amp;gt; 
		&amp;lt;/tr&amp;gt; 
		&amp;lt;iceext:loop value=&amp;quot;#{loopWithZebraStyleAndIndexBean.rows}&amp;quot; var=&amp;quot;row&amp;quot; rowIndexVar=&amp;quot;rowIndexVar&amp;quot; varMod=&amp;quot;mod3&amp;quot; modValue=&amp;quot;3&amp;quot;&amp;gt; 
			&amp;lt;tr class=&amp;quot;zebraStyle#{mod3}&amp;quot;&amp;gt; 
				&amp;lt;td&amp;gt;&amp;lt;ice:outputText value=&amp;quot;#{row.name}&amp;quot; /&amp;gt;&amp;lt;/td&amp;gt; 
				&amp;lt;td&amp;gt;&amp;lt;ice:outputText value=&amp;quot;#{row.phone}&amp;quot; /&amp;gt;&amp;lt;/td&amp;gt; 
				&amp;lt;td&amp;gt;&amp;lt;ice:outputText value=&amp;quot;#{rowIndexVar}&amp;quot; /&amp;gt;&amp;lt;/td&amp;gt; 
			&amp;lt;/tr&amp;gt; 
		&amp;lt;/iceext:loop&amp;gt; 
	&amp;lt;/table&amp;gt; 
&lt;/pre&gt;
&lt;br /&gt;
This is main entry point. Its referenced by &#39;loopWithZebraStyleAndIndexBean&#39; from faces-config.xml 
&lt;br /&gt;&lt;b&gt;com.gpost.jsfexamples.loopWithZebraStyleAndIndex.LoopWithZebraStyleAndIndexBean&lt;/b&gt;
&lt;pre name=&quot;code&quot; class=&quot;java&quot;&gt;
package com.gpost.jsfexamples.loopWithZebraStyleAndIndex;

import java.util.ArrayList;
import java.util.List;


/*
* Java class for example &#39;Loop with zebra style and index&#39;
* referenced as &#39;loopWithZebraStyleAndIndexBean&#39; from faces-config.xml, 
* used in &#39;LoopWithZebraStyleAndIndex.jspx&#39;
*/
public class LoopWithZebraStyleAndIndexBean{

	List&amp;lt;ManWithPhone&amp;gt; rows = null;
	
	public List&amp;lt;ManWithPhone&amp;gt; getRows() {
		if (rows == null) {
			rows = new ArrayList&amp;lt;ManWithPhone&amp;gt;();
			// create same sample data...
			rows.add(new ManWithPhone(&amp;quot;Gary&amp;quot;, &amp;quot;1234-6767&amp;quot;));
			rows.add(new ManWithPhone(&amp;quot;Bob&amp;quot;, &amp;quot;5678-4553&amp;quot;));
			rows.add(new ManWithPhone(&amp;quot;John&amp;quot;, &amp;quot;5698-4333&amp;quot;));
			rows.add(new ManWithPhone(&amp;quot;John1&amp;quot;, &amp;quot;5698-4333&amp;quot;));
			rows.add(new ManWithPhone(&amp;quot;John2&amp;quot;, &amp;quot;5698-4333&amp;quot;));
			rows.add(new ManWithPhone(&amp;quot;John3&amp;quot;, &amp;quot;5698-4333&amp;quot;));
			rows.add(new ManWithPhone(&amp;quot;John4&amp;quot;, &amp;quot;5698-4333&amp;quot;));
		}
		return rows;
	}



} // end of class
&lt;/pre&gt;
&lt;br /&gt;
This class defines data in &#39;row&#39;.  
&lt;br /&gt;&lt;b&gt;com.gpost.jsfexamples.loopWithZebraStyleAndIndex.ManWithPhone&lt;/b&gt;
&lt;pre name=&quot;code&quot; class=&quot;java&quot;&gt;
package com.gpost.jsfexamples.loopWithZebraStyleAndIndex;

public class ManWithPhone {
	public ManWithPhone(String name, String phone) {
		super();
		this.name = name;
		this.phone = phone;
	}

	String name;
	
	String phone;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;b&gt;part of faces-config.xml&lt;/b&gt;
&lt;pre name=&quot;code&quot; class=&quot;xml&quot;&gt;
&amp;lt;managed-bean&amp;gt;
 &amp;lt;managed-bean-name&amp;gt;loopWithZebraStyleAndIndexBean&amp;lt;/managed-bean-name&amp;gt;
 &amp;lt;managed-bean-class&amp;gt;com.gpost.jsfexamples.loopWithZebraStyleAndIndex.LoopWithZebraStyleAndIndexBean&amp;lt;/managed-bean-class&amp;gt;
 &amp;lt;managed-bean-scope&amp;gt;session&amp;lt;/managed-bean-scope&amp;gt;

&amp;lt;/managed-bean&amp;gt;
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;conclusion&lt;/b&gt;&lt;br /&gt;
As we saw in this example, you can use loop with simple html/css, then 
add some binding to your java beans and you get very flexible, easily customizable layout 
with more features like paging, indexing, and mod variables. 
&lt;br /&gt;
</content><link rel='replies' type='application/atom+xml' href='http://icefacesextentionsandexamples.blogspot.com/feeds/8327559658291067244/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://icefacesextentionsandexamples.blogspot.com/2010/08/example-for-custom-loop-jsf-component.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2894230897541710318/posts/default/8327559658291067244'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2894230897541710318/posts/default/8327559658291067244'/><link rel='alternate' type='text/html' href='http://icefacesextentionsandexamples.blogspot.com/2010/08/example-for-custom-loop-jsf-component.html' title='Example for custom loop jsf component with zebra style and index'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/03730825366007127346</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>