Utilizzo di una Collection su una h:dataTable

Forum relativo ai framework per l'utilizzo della tecnologia JSP

Utilizzo di una Collection su una h:dataTable

Messaggioda alesslud » gio giu 23, 2011 8:32 am

Qui di seguito vi riportiamo un esempio di utilizzo di una List su h:dataTable.

L'esempio completo è stato provato su Eclipse Helios Service Release 1 su una version JDK 1.6_22 ed è scaricabile dal link download.
Allegati
facesimpletable.zip
(10.77 KiB) Scaricato 275 volte
alesslud
Site Admin
 
Messaggi: 779
Iscritto il: mer nov 08, 2006 8:09 am

index.jsp

Messaggioda alesslud » gio giu 23, 2011 8:34 am

<html>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<link href="styles.css" rel="stylesheet" type="text/css"/>
<f:view>
<head>
<f:loadBundle basename="messages" var="msgs"/>
<title>
<h:outputText value="#{msgs.windowTitle}"/>
</title>
</head>

<body>
<h:outputText value="#{msgs.pageTitle}"/>
<p>
<h:form>
<h:dataTable value="#{tableData.namesAsList}"
var="name" columnClasses="custid,name">
<h:column>
<h:outputText value="#{name.last}"/>
<f:verbatim>,</f:verbatim>
</h:column>

<h:column>
<h:outputText value="#{name.first}"/>
</h:column>
</h:dataTable>
</h:form>
</body>
</f:view>
</html>
alesslud
Site Admin
 
Messaggi: 779
Iscritto il: mer nov 08, 2006 8:09 am

style.css

Messaggioda alesslud » gio giu 23, 2011 8:35 am

.customers {
border: thin solid black;
}
.customersHeader {
text-align: center;
font-style: italic;
color: Snow;
background: Teal;
}
.customersFooter {
font-size: 0.75em;
text-align: center;
background: PowderBlue;
}
.delete {
text-align: center;
color: Black;
background: Red;
}
.custid {
height: 25px;
text-align: center;
background: MediumTurquoise;
}
.name {
text-align: left;
background: PowderBlue;
}
.firstName {
width: 6em;
text-align: left;
color: Black;
background: MediumTurquoise;
}
.age {
width: 3em;
text-align: center;
color: Black;
background: PowderBlue;
}
.sex {
width: 3em;
text-align: center;
color: Black;
background: MediumTurquoise;
}
.city {
width: 9em;
text-align: center;
color: Black;
background: PowderBlue;
}
.state {
width: 3em;
text-align: center;
color: Black;
background: MediumTurquoise;
}
.zip {
width: 6em;
text-align: center;
background: PowderBlue;
}
.evenRow {
background: PowderBlue;
}
.oddRow {
background: MediumTurquoise;
text-style: italic;
}
.pageLink {
font-size: 0.75em;
}
.editableControl {
text-align:Left;
}
.controlPanel {
text-align:left;
}
.page {
text-align:left;
}
.bulbImage {
border-width: 0px;
}
.emphasis {
font-size: 1.35em;
font-style: italic;
}
.value {
font-style: italic;
}
.controlLeft {
width: 45px;
vertical-align: top;
text-align:left;
}
.controlMiddle {
width: 50px;
vertical-align: top;
text-align:left;
}
.controlRight {
width: 40px;
vertical-align: top;
text-align:left;
}
.pageLinks {
border: thin solid Black;
background: PowderBlue;
}
alesslud
Site Admin
 
Messaggi: 779
Iscritto il: mer nov 08, 2006 8:09 am

faces-config.xml

Messaggioda alesslud » gio giu 23, 2011 8:35 am

<?xml version="1.0"?>

<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
"http://java.sun.com/dtd/web-facesconfig_1_0.dtd">

<faces-config>
<managed-bean>
<managed-bean-name>tableData</managed-bean-name>
<managed-bean-class>com.aquilasiti.TableData</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>
alesslud
Site Admin
 
Messaggi: 779
Iscritto il: mer nov 08, 2006 8:09 am

web.xml

Messaggioda alesslud » gio giu 23, 2011 8:36 am

<?xml version="1.0"?>

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
alesslud
Site Admin
 
Messaggi: 779
Iscritto il: mer nov 08, 2006 8:09 am

messages.properties

Messaggioda alesslud » gio giu 23, 2011 8:36 am

windowTitle=Un DataTable di esempio
pageTitle=Lista di nomi:
alesslud
Site Admin
 
Messaggi: 779
Iscritto il: mer nov 08, 2006 8:09 am

DataTable

Messaggioda alesslud » gio giu 23, 2011 8:36 am

package com.aquilasiti;


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

public class TableData {
private static final Name[] simpleNames = new Name[] {
new Name("Alessandro", "Ludovici"), new Name("Pippo", "Carluccio"),
new Name("Giorgino", "Giorgetto"), new Name("Picchio", "Forte"),
new Name("Vendo", "Patate") };

public Name[] getSimpleNames() {
return simpleNames;
}

public List<Name> getNamesAsList() {
List<Name> name = new ArrayList<Name>();
Name[] names = this.getSimpleNames();
for (Name i : names) {
name.add(i);
}
return name;
}
}
alesslud
Site Admin
 
Messaggi: 779
Iscritto il: mer nov 08, 2006 8:09 am

Name

Messaggioda alesslud » gio giu 23, 2011 8:37 am

package com.aquilasiti;

public class Name {
private String first;
private String last;

public Name(String first, String last) {
this.first = first;
this.last = last;
}

public void setFirst(String newValue) { first = newValue; }
public String getFirst() { return first; }

public void setLast(String newValue) { last = newValue; }
public String getLast() { return last; }
}
alesslud
Site Admin
 
Messaggi: 779
Iscritto il: mer nov 08, 2006 8:09 am


Torna a JSF e Struts

Chi c’è in linea

Visitano il forum: Nessuno e 1 ospite

cron