Editing dataTable e cancellazione di una riga: index.jsp

Forum relativo ai framework per l'utilizzo della tecnologia JSP

Editing dataTable e cancellazione di una riga: index.jsp

Messaggioda alesslud » gio lug 06, 2006 9:39 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>
<link href="styles.css" rel="stylesheet" type="text/css"/>
<f:loadBundle basename="com.corejsf.messages" var="msgs"/>
<title>
<h:outputText value="#{msgs.windowTitle}"/>
</title>
</head>
<body>
<h:form>
<h:dataTable value="#{tableData.names}" var="name"
styleClass="names" headerClass="namesHeader"
columnClasses="last,first">
<h:column rendered="#{tableData.editable}">
<f:facet name="header">
<h:outputText value="#{msgs.deleteColumnHeader}"/>
</f:facet>
<h:selectBooleanCheckbox value="#{name.markedForDeletion}"
onchange="submit()"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{msgs.lastColumnHeader}"/>
</f:facet>
<h:outputText value="#{name.last}"/>
<f:verbatim>,</f:verbatim>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{msgs.firstColumnHeader}"/>
</f:facet>
<h:outputText value="#{name.first}"/>
</h:column>
</h:dataTable>
<h:outputText value="#{msgs.editPrompt}"/>
<h:selectBooleanCheckbox onchange="submit()"
value="#{tableData.editable}"/>
<h:commandButton value="#{msgs.deleteButtonText}"
rendered="#{tableData.editable}"
action="#{tableData.deleteNames}"
disabled="#{not tableData.anyNamesMarkedForDeletion}"/>
</h:form>
</body>
</f:view>
</html>
Ultima modifica di alesslud il gio lug 06, 2006 9:42 am, modificato 1 volta in totale.
alesslud
Site Admin
 
Messaggi: 779
Iscritto il: mer nov 08, 2006 8:09 am

Name.java

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

package com.corejsf;

public class Name {
private String first;
private String last;
private boolean markedForDeletion = false;

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 isMarkedForDeletion() { return markedForDeletion; }
public void setMarkedForDeletion(boolean newValue) {
markedForDeletion = newValue;
}
}
alesslud
Site Admin
 
Messaggi: 779
Iscritto il: mer nov 08, 2006 8:09 am

TableData.java

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

package com.corejsf;

import javax.faces.model.DataModel;
import javax.faces.model.ArrayDataModel;

public class TableData {
private boolean editable = false;
private ArrayDataModel model = null;


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

public TableData() { model = new ArrayDataModel(names); }

public DataModel getNames() { return model; }

public boolean isEditable() { return editable; }
public void setEditable(boolean newValue) { editable = newValue; }

public String deleteNames() {
if (!getAnyNamesMarkedForDeletion())
return null;

Name[] currentNames = (Name[]) model.getWrappedData();
Name[] newNames = new Name[currentNames.length
- getNumberOfNamesMarkedForDeletion()];

for(int i = 0, j = 0; i < currentNames.length; ++i) {
Name name = (Name) currentNames[i];
if (!name.isMarkedForDeletion()) {
newNames[j++] = name;
}
}
model.setWrappedData(newNames);
return null;
}

public int getNumberOfNamesMarkedForDeletion() {
Name[] currentNames = (Name[]) model.getWrappedData();
int cnt = 0;

for(int i = 0; i < currentNames.length; ++i) {
Name name = (Name) currentNames[i];
if (name.isMarkedForDeletion())
++cnt;
}
return cnt;
}

public boolean getAnyNamesMarkedForDeletion() {
Name[] currentNames = (Name[]) model.getWrappedData();
for(int i = 0; i < currentNames.length; ++i) {
Name name = (Name) currentNames[i];
if (name.isMarkedForDeletion())
return true;
}
return false;
}
}
alesslud
Site Admin
 
Messaggi: 779
Iscritto il: mer nov 08, 2006 8:09 am

messages.properties

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

windowTitle=Deleting Table Rows
pageTitle=An array of names:
selectColumnToSort=Select a column to sort
editPrompt=Edit
firstColumnHeader=First Name
lastColumnHeader=Last Name
deleteColumnHeader=Delete
deleteButtonText=Delete selected names
alesslud
Site Admin
 
Messaggi: 779
Iscritto il: mer nov 08, 2006 8:09 am

faces-config.xml

Messaggioda alesslud » gio lug 06, 2006 9:41 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:42 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


Torna a JSF e Struts

Chi c’è in linea

Visitano il forum: Nessuno e 1 ospite

cron