Data Tables editabile

Forum relativo ai framework per l'utilizzo della tecnologia JSP

Data Tables editabile

Messaggioda alesslud » gio lug 06, 2006 9:22 am

In questo articolo sarà possibile osservare come si edita un dataTable
alesslud
Site Admin
 
Messaggi: 779
Iscritto il: mer nov 08, 2006 8:09 am

index.jsp

Messaggioda alesslud » gio lug 06, 2006 9:22 am

<html>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<f:view>
<head>
<title>
<f:loadBundle basename="com.corejsf.messages" var="msgs"/>
<h:outputText value="#{msgs.windowTitle}"/>
</title>
</head>
<body>
<h:form>
<h:dataTable value="#{tableData.names}" var="name">
<h:column>
<f:facet name="header">
<h:outputText value="#{msgs.editColumn}"
style="font-weight: bold"/>
</f:facet>
<h:selectBooleanCheckbox value="#{name.editable}"
onclick="submit()"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{msgs.lastnameColumn}"
style="font-weight: bold"/>
</f:facet>
<h:inputText value="#{name.last}" rendered="#{name.editable}"
size="10"/>
<h:outputText value="#{name.last}"
rendered="#{not name.editable}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{msgs.firstnameColumn}"
style="font-weight: bold"/>
</f:facet>
<h:inputText value="#{name.first}"
rendered="#{name.editable}" size="10"/>
<h:outputText value="#{name.first}"
rendered="#{not name.editable}"/>
</h:column>
</h:dataTable>
<p />
<h:commandButton value="Salva" onclick="" />
</h:form>
</body>
</f:view>
</html>
alesslud
Site Admin
 
Messaggi: 779
Iscritto il: mer nov 08, 2006 8:09 am

faces-config.xml

Messaggioda alesslud » gio lug 06, 2006 9:23 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.corejsf.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 lug 06, 2006 9:23 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.faces</welcome-file>
</welcome-file-list>
</web-app>
alesslud
Site Admin
 
Messaggi: 779
Iscritto il: mer nov 08, 2006 8:09 am

Name.java

Messaggioda alesslud » gio lug 06, 2006 9:24 am

package com.corejsf;

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

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; }

public boolean isEditable() { return editable; }
public void setEditable(boolean newValue) { editable = newValue; }
}
alesslud
Site Admin
 
Messaggi: 779
Iscritto il: mer nov 08, 2006 8:09 am

TableData

Messaggioda alesslud » gio lug 06, 2006 9:24 am

package com.corejsf;

public class TableData {
private static final Name[] names = new Name[] {
new Name("William", "Dupont"),
new Name("Anna", "Keeney"),
new Name("Mariko", "Randor"),
new Name("John", "Wilson")
};

public Name[] getNames() { return names;}
}
alesslud
Site Admin
 
Messaggi: 779
Iscritto il: mer nov 08, 2006 8:09 am

messages.properties

Messaggioda alesslud » gio lug 06, 2006 9:25 am

windowTitle=Editing Table Cells
lastnameColumn=Last Name
firstnameColumn=First Name
editColumn=Edit
alphanumeric=[alpha]
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