Estou implementando o exemplo do MyFaces (Data Table Master-Detail)
tudo funcionou, menos a parte mais importante, que é o Show/Hide
Codigo da Pagina masterDetail :
<%@ page session=“false” contentType=“text/html;charset=utf-8”%>
<%@ taglib uri=“http://java.sun.com/jsf/html” prefix=“h”%>
<%@ taglib uri=“http://java.sun.com/jsf/core” prefix=“f”%>
<%@ taglib uri=“http://myfaces.apache.org/tomahawk” prefix=“t”%>
<t:dataTable id="data"
styleClass="standardTable"
headerClass="standardTable_Header"
footerClass="standardTable_Header"
rowClasses="standardTable_Row1,standardTable_Row2"
columnClasses="standardTable_Column,standardTable_ColumnCentered,standardTable_Column"
var="currentCountry"
value="#{countryList.countries}"
preserveDataModel="true"
varDetailToggler="detailToggler">
<h:column>
<f:facet name="header">
<h:outputText value="Pais" />
</f:facet>
<t:commandLink action="go_country" immediate="true">
<h:outputText value="#{currentCountry.name}" />
<t:updateActionListener property="#{countryForm.id}" value="#{currentCountry.id}" />
</t:commandLink>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="UF" />
</f:facet>
<h:outputText value="#{currentCountry.isoCode}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Cidades" />
</f:facet>
<h:commandLink rendered="#{detailToggler.currentDetailExpanded}" action="#{detailToggler.toggleDetail}">
<h:outputText value=“Hide” />
</h:commandLink>
<h:commandLink rendered="#{!detailToggler.currentDetailExpanded}" action="#{detailToggler.toggleDetail}">
<h:outputText value=“Show” />
</h:commandLink>
</h:column>
<f:facet name=“detailStamp”>
<t:dataTable id=“cities” styleClass=“standardTable_Column” var=“city” value="#{currentCountry.cities}">
<h:column>
<h:outputText value="#{city}" style=“font-size: 11px” />
</h:column>
<h:column>
<h:selectBooleanCheckbox value="#{city.selected}"></h:selectBooleanCheckbox>
</h:column>
<h:column>
<h:commandLink action="#{city.unselect}" value=“Unselect”/>
</h:column>
</t:dataTable>
</f:facet>
</t:dataTable>
<f:verbatim>
</f:verbatim>
</h:panelGroup>
</h:form>
</f:view>
Quando clico no Link Show da o seguinte problema:
java.lang.ClassCastException: javax.faces.model.ListDataModel
org.apache.myfaces.component.html.ext.HtmlDataTable.updateModelFromPreservedDataModel(HtmlDataTable.java:401)
org.apache.myfaces.component.html.ext.HtmlDataTable.processUpdates(HtmlDataTable.java:387)
javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:935)
javax.faces.component.UIForm.processUpdates(UIForm.java:196)
javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:935)
javax.faces.component.UIViewRoot.processUpdates(UIViewRoot.java:363)
org.ajax4jsf.framework.ajax.AjaxViewRoot.processUpdates(AjaxViewRoot.java:372)
Codigo da Classe:
package conferencia;
import org.apache.myfaces.component.html.ext.HtmlDataTable;
import javax.faces.event.ActionEvent;
import javax.faces.component.UIComponent;
import javax.faces.component.UIData;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
/**
-
DOCUMENT ME!
-
@author Thomas Spiegl (latest modification by $Author: grantsmith $)
-
@version $Revision: 472610 $ $Date: 2006-11-08 20:46:34 +0100 (Wed, 08 Nov 2006) $
*/
public class SimpleCountryList
{
private List _countries = new ArrayList();
static
{
}SimpleCountry getSimpleCountry(long id)
{
for (int i = 0; i < _countries.size(); i++)
{
SimpleCountry country = (SimpleCountry)_countries.get(i);
if (country.getId() == id)
{
return country;
}
}
return null;
}long getNewSimpleCountryId()
{
long maxId = 0;
for (int i = 0; i < _countries.size(); i++)
{
SimpleCountry country = (SimpleCountry)_countries.get(i);
if (country.getId() > maxId)
{
maxId = country.getId();
}
}
return maxId + 1;
}void saveSimpleCountry(SimpleCountry simpleCountry)
{
if (simpleCountry.getId() == 0)
{
simpleCountry.setId(getNewSimpleCountryId());
}
boolean found = false;
for (int i = 0; i < _countries.size(); i++)
{
SimpleCountry country = (SimpleCountry)_countries.get(i);
if (country.getId() == simpleCountry.getId())
{
_countries.set(i, simpleCountry);
found = true;
}
}
if (!found)
{
_countries.add(simpleCountry);
}
}void deleteSimpleCountry(SimpleCountry simpleCountry)
{
for (int i = 0; i < _countries.size(); i++)
{
SimpleCountry country = (SimpleCountry)_countries.get(i);
if (country.getId() == simpleCountry.getId())
{
_countries.remove(i);
}
}
}public SimpleCountryList()
{
_countries.add(new SimpleCountry(1, “AUSTRIA”, “AT”, new BigDecimal(123L), createCities(new String[]{“Wien”,“Graz”,“Linz”,“Salzburg”})));
_countries.add(new SimpleCountry(2, “AZERBAIJAN”, “AZ”, new BigDecimal(535L), createCities(new String[]{“Baku”,“Sumgait”,“Qabala”,“Agdam”})));
_countries.add(new SimpleCountry(3, “BAHAMAS”, “BS”, new BigDecimal(1345623L), createCities(new String[]{“Nassau”,“Alice Town”,“Church Grove”,“West End”})));
_countries.add(new SimpleCountry(4, “BAHRAIN”, “BH”, new BigDecimal(346L), createCities(new String[]{“Bahrain”})));
_countries.add(new SimpleCountry(5, “BANGLADESH”, “BD”, new BigDecimal(456L), createCities(new String[]{“Chittagong”,“Chandpur”,“Bogra”,“Feni”})));
_countries.add(new SimpleCountry(6, “BARBADOS”, “BB”, new BigDecimal(45645L), createCities(new String[]{“Grantley Adams”})));
}/**
- @param names
-
@return
*/
private SimpleCity[] createCities(String[] names)
{
SimpleCity[] result = new SimpleCity[names.length];
for (int i = 0; i < result.length; i++)
{
result[i] = new SimpleCity(names[i]);
}
return result;
}
public List getCountries()
{
return _countries;
}public Map getCountryMap()
{
Map map = new HashMap();List li = getCountries(); for (int i = 0; i < li.size(); i++) { SimpleCountry simpleCountry = (SimpleCountry) li.get(i); map.put(simpleCountry.getIsoCode(),simpleCountry.getName()); } return map;
}
public void setCountries(List countries)
{
_countries = countries;
}public String addCountry()
{
List list = getCountries();
list.add(new SimpleCountry(list.size() + 1, “”, “”, new BigDecimal(0), createCities(new String[] {})));
return “ok”;
}public void deleteCountry(ActionEvent ev)
{
UIData datatable = findParentHtmlDataTable(ev.getComponent());
getCountries().remove(datatable.getRowIndex() + datatable.getFirst());
}/**
- @param component
-
@return
*/
private HtmlDataTable findParentHtmlDataTable(UIComponent component)
{
if (component == null)
{
return null;
}
if (component instanceof HtmlDataTable)
{
return (HtmlDataTable) component;
}
return findParentHtmlDataTable(component.getParent());
}
}
Agradeco a quem puder ajudar.