Topic
  • No replies
SystemAdmin
SystemAdmin
11979 Posts

Pinned topic Problem while adding multiple values into DATA Table in JSF

‏2008-02-11T15:02:36Z |
Hi,

Iam facing one issue regarding Data table.The problem is like
I need to add the values into a DataTable.
I had one Button and 2 fields each time i enter
some values and when i click submit those values
should be added to the DataTable.For this iam using
one arraylist in managed bean and adding the bean values
to the Arraylist.And iam binding the Arraylist to
JSF page.But the problem is like iam unable maintain the
previous values.SO how should be able to maintain the
bean in the context.Can any one please reply me back
with some solution.Thanks in Advance.Please find the code below.
Managed bean code:

public class SampleDataTableBean extends PageCodeBase {

private String name;
private String SSN;
private VehicleDescriptionList vehicleDescriptionList;
protected HtmlScriptCollector scriptCollector1;
VehicleDescription vehicleDescription;
public String vehicleInform(){

// FacesContext context = FacesContext.getCurrentInstance();

// Application app = context.getApplication();

// ValueBinding binding = app.createValueBinding("#{pc_Contact}");
//VehicleDescriptionList contactListBean = (VehicleDescriptionList) binding.getValue(context);

// facesContext1.getCurrentInstance().
VehicleDescription vehicleDescription = new VehicleDescription();
vehicleDescriptionList = new VehicleDescriptionList();
vehicleDescription.setName(this.name);
vehicleDescription.setSSN(this.SSN);
vehicleDescriptionList.add(vehicleDescription);
getSessionScope().put("vehicleDescription", vehicleDescriptionList);
return "Success";

}

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSSN() {
return SSN;
}
public void setSSN(String ssn) {
SSN = ssn;
}

public VehicleDescriptionList getVehicleDescriptionList() {
return vehicleDescriptionList;
}

public void setVehicleDescriptionList(
VehicleDescriptionList vehicleDescriptionList) {
this.vehicleDescriptionList = vehicleDescriptionList;
}
}
JSF page code:

<%@page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@taglib uri="http://www.ibm.com/jsf/html_extended" prefix="hx"%>
<html>
<head>
<title>DataTableTestPage</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="GENERATOR" content="Rational Application Developer">
<link rel="stylesheet" type="text/css" href="theme/stylesheet.css"
title="Style">
</head>
<f:view>
<body>
<hx:scriptCollector id="scriptCollector1">

<h:form id="form1" styleClass="form">
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td><h:outputLabel id="label1" styleClass="outputLabel">
<h:outputText id="text1" styleClass="outputText" value="Name:"></h:outputText>
</h:outputLabel></td>
<td><h:inputText id="text3" styleClass="inputText"
value="#{vehicle.name}"></h:inputText></td>
</tr>
<tr>
<td><h:outputLabel id="label2" styleClass="outputLabel">
<h:outputText id="text2" styleClass="outputText" value="SSN"></h:outputText>
</h:outputLabel></td>
<td><h:inputText id="text4" styleClass="inputText"
value="#{vehicle.SSN}"></h:inputText></td>
<td>
</td>
<td>
<hx:commandExButton type="submit" value="Submit" id="button1"
styleClass="commandExButton" action="#{vehicle.vehicleInform}"></hx:commandExButton></td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
<hx:dataTableEx border="0" cellpadding="2" cellspacing="0"
columnClasses="columnClass1" headerClass="headerClass"
footerClass="footerClass" rowClasses="rowClass1, rowClass2"
id="tableEx1" styleClass="dataTableEx"
var="varvehicleDescriptionList"
value="#{vehicle.vehicleDescriptionList}">
<hx:columnEx id="column1">
<f:facet name="header">
<h:outputText id="text6" styleClass="outputText" value="Name"></h:outputText>
</f:facet>
<h:outputText id="text7" styleClass="outputText"
value="#{varvehicleDescriptionList.name}"></h:outputText>
</hx:columnEx>
<hx:columnEx id="columnEx1">
<f:facet name="header">
<h:outputText id="text5" styleClass="outputText" value="SSN"></h:outputText>
</f:facet>
<h:outputText id="text8" styleClass="outputText"
value="#{varvehicleDescriptionList.SSN}"></h:outputText>
</hx:columnEx>
</hx:dataTableEx></td>
</tr>
<tr>
<td>
</td>
</tr>
</tbody>
</table>
</h:form>
</hx:scriptCollector>
</body>
</f:view>
</html>

Thanks & Regards
Ram