<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Fabio Brandão - Blog &#187; JSF</title>
	<atom:link href="http://www.fnbrandao.com.br/blog/tag/jsf/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.fnbrandao.com.br/blog</link>
	<description></description>
	<lastBuildDate>Tue, 24 Aug 2010 01:33:22 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PostBack no JSF</title>
		<link>http://www.fnbrandao.com.br/blog/2008/06/postback-no-jsf/</link>
		<comments>http://www.fnbrandao.com.br/blog/2008/06/postback-no-jsf/#comments</comments>
		<pubDate>Fri, 06 Jun 2008 12:06:32 +0000</pubDate>
		<dc:creator>fabio</dc:creator>
				<category><![CDATA[Java EE]]></category>
		<category><![CDATA[Programação]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[JEE]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[postback]]></category>

		<guid isPermaLink="false">http://www.fnbrandao.com.br/blog/?p=7</guid>
		<description><![CDATA[Um grande problema com o JSF é que na especificação 1.1 não existe algum método para saber se a página está sendo executada no postback (quando você reenvia os dados para ela mesma). Mas existe o seguinte workaround:

package web.jsf.vh;

import java.io.IOException;
import java.util.Locale;
import java.util.Map;

import javax.faces.FacesException;
import javax.faces.application.ViewHandler;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;

public class PostBackViewHandler extends ViewHandler {

  protected ViewHandler baseViewHandler;

 [...]]]></description>
			<content:encoded><![CDATA[<p>Um grande problema com o JSF é que na especificação 1.1 não existe algum método para saber se a página está sendo executada no postback (quando você reenvia os dados para ela mesma). Mas existe o seguinte workaround:</p>
<p><code>
<pre>package web.jsf.vh;

import java.io.IOException;
import java.util.Locale;
import java.util.Map;

import javax.faces.FacesException;
import javax.faces.application.ViewHandler;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;

public class PostBackViewHandler extends ViewHandler {

  protected ViewHandler baseViewHandler;

  public CustomViewHandler(ViewHandler viewHandler) {
    super();
    this.baseViewHandler = viewHandler;
  }

  public Locale calculateLocale(FacesContext facesContext) {
    return baseViewHandler.calculateLocale(facesContext);
  }

  public String calculateRenderKitId(FacesContext facesContext) {
    return baseViewHandler.calculateRenderKitId(facesContext);
  }

  public UIViewRoot createView(FacesContext facesContext, String arg1) {
    setPostback(facesContext, false);
    return baseViewHandler.createView(facesContext, arg1);
  }

  public String getActionURL(FacesContext facesContext, String arg1) {
    return baseViewHandler.getActionURL(facesContext, arg1);
  }

  public String getResourceURL(FacesContext facesContext, String arg1) {
    return baseViewHandler.getResourceURL(facesContext, arg1);
  }

  public void renderView(FacesContext facesContext, UIViewRoot arg1) throws IOException, FacesException {
    baseViewHandler.renderView(facesContext, arg1);

  }

  public UIViewRoot restoreView(FacesContext facesContext, String arg1) {
    setPostback(facesContext, true);
    return baseViewHandler.restoreView(facesContext, arg1);
  }

  public void writeState(FacesContext facesContext) throws IOException {
    baseViewHandler.writeState(facesContext);
  }

  public Map getRequestScope(FacesContext facesContext) {
    return (Map)facesContext.getApplication().createValueBinding(“#{requestScope}”).getValue(facesContext);
  }

  public void setPostback(FacesContext facesContext, boolean value) {
    getRequestScope(facesContext).put(“ispostback”, new Boolean(value));
  }

}</pre>
<p></code></p>
<p>O código acima é um View Handler do JSF, agora basta registrá-lo no <i>&#8220;facesconfig.xml&#8221;</i>:</p>
<p><code>
<pre>&lt;application&gt;
   &lt;view-handler&gt;web.jsf.vh.PostBackViewHandler&lt;/view-handler&gt;
&lt;/application&gt;</pre>
<p></code></p>
<p>E para saber em sua página se é um postback:</p>
<p><code>
<pre>public boolean isPostback() {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    Map requestScope = (Map)facesContext.getApplication().createValueBinding(“#{requestScope}”).getValue(facesContext);
    boolean ispostback = ((Boolean)requestScope.get(“ispostback”)).booleanValue();
    return ispostback;
}</pre>
<p></code></p>
<p>Obs.: Esse workaround só funciona se o estado da view não é salva no servidor.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fnbrandao.com.br/blog/2008/06/postback-no-jsf/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>JSF &#8211; Duplicate componentID</title>
		<link>http://www.fnbrandao.com.br/blog/2008/05/jsf-duplicate-componentid/</link>
		<comments>http://www.fnbrandao.com.br/blog/2008/05/jsf-duplicate-componentid/#comments</comments>
		<pubDate>Fri, 23 May 2008 18:07:28 +0000</pubDate>
		<dc:creator>fabio</dc:creator>
				<category><![CDATA[Java EE]]></category>
		<category><![CDATA[Programação]]></category>
		<category><![CDATA[JEE]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[RichFaces]]></category>

		<guid isPermaLink="false">http://www.fnbrandao.com.br/blog/?p=11</guid>
		<description><![CDATA[Utilizando o DataTable do RichFaces em uma simples página, após um reload na página sempre era retornado o seguinte erro:
Duplicate component ID '_id0:_dataTable:_id1' found in view.
Segue abaixo o código da página que causava o erro:

&#60;ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
	xmlns:rich="http://richfaces.ajax4jsf.org/rich"&#62;

	&#60;h:form binding="#{UserConsultPage.component}"&#62;
		&#60;rich:dataTable id="dataTable"
			binding="#{UserConsultPage.dataTable}" var="item"&#62;
			&#60;rich:column&#62;
				&#60;f:facet name="header"&#62;
					&#60;h:outputText value="Name" /&#62;
				&#60;/f:facet&#62;
				&#60;h:outputText value="#{item.name}" /&#62;
			&#60;/rich:column&#62;
			&#60;rich:column&#62;
				&#60;f:facet name="header"&#62;
					&#60;h:outputText value="Email" /&#62;
				&#60;/f:facet&#62;
				&#60;h:outputText value="#{item.email}" /&#62;
			&#60;/rich:column&#62;
		&#60;/rich:dataTable&#62;

		&#60;h:commandButton id="btnLoad" actionListener="#{UserConsultPage.load}" /&#62;
	&#60;/h:form&#62;

&#60;/ui:composition&#62;

A solução foi colocar [...]]]></description>
			<content:encoded><![CDATA[<p>Utilizando o DataTable do RichFaces em uma simples página, após um reload na página sempre era retornado o seguinte erro:</p>
<p><code>Duplicate component ID '_id0:_dataTable:_id1' found in view.</code></p>
<p>Segue abaixo o código da página que causava o erro:</p>
<p><code>
<pre>&lt;ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
	xmlns:rich="http://richfaces.ajax4jsf.org/rich"&gt;

	&lt;h:form binding="#{UserConsultPage.component}"&gt;
		&lt;rich:dataTable id="dataTable"
			binding="#{UserConsultPage.dataTable}" var="item"&gt;
			&lt;rich:column&gt;
				&lt;f:facet name="header"&gt;
					&lt;h:outputText value="Name" /&gt;
				&lt;/f:facet&gt;
				&lt;h:outputText value="#{item.name}" /&gt;
			&lt;/rich:column&gt;
			&lt;rich:column&gt;
				&lt;f:facet name="header"&gt;
					&lt;h:outputText value="Email" /&gt;
				&lt;/f:facet&gt;
				&lt;h:outputText value="#{item.email}" /&gt;
			&lt;/rich:column&gt;
		&lt;/rich:dataTable&gt;

		&lt;h:commandButton id="btnLoad" actionListener="#{UserConsultPage.load}" /&gt;
	&lt;/h:form&gt;

&lt;/ui:composition&gt;</pre>
<p></code></p>
<p>A solução foi colocar id&#8217;s em todos os componentes <em>&#8220;outputText&#8221;</em>. Segue abaixo a página modificada:</p>
<p><code>
<pre>&lt;ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
	xmlns:rich="http://richfaces.ajax4jsf.org/rich"&gt;

	&lt;h:form binding="#{UserConsultPage.component}"&gt;
		&lt;rich:dataTable id="dataTable"
			binding="#{UserConsultPage.dataTable}" var="item"&gt;
			&lt;rich:column&gt;
				&lt;f:facet name="header"&gt;
					&lt;h:outputText <strong>id="headerNameValue"</strong> value="Name" /&gt;
				&lt;/f:facet&gt;
				&lt;h:outputText <strong>id="nameValue"</strong> value="#{item.name}" /&gt;
			&lt;/rich:column&gt;
			&lt;rich:column&gt;
				&lt;f:facet name="header"&gt;
					&lt;h:outputText <strong>id="headerEmailValue"</strong> value="Email" /&gt;
				&lt;/f:facet&gt;
				&lt;h:outputText <strong>id="emailValue"</strong> value="#{item.email}" /&gt;
			&lt;/rich:column&gt;
		&lt;/rich:dataTable&gt;

		&lt;h:commandButton id="btnLoad" actionListener="#{UserConsultPage.load}" /&gt;
	&lt;/h:form&gt;

&lt;/ui:composition&gt;</pre>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.fnbrandao.com.br/blog/2008/05/jsf-duplicate-componentid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
