|
| Problem while adding multiple values into DATA Table in JSF |
 |
Mon, 11 Feb 2008 10:02:36 EST |
Hi,<br />
<br />
Iam facing one issue regarding Data table.The problem is like<br />
I need to add the values into a DataTable.<br />
I had one Button and 2 fields each time i enter<br />
some values and when i click submit those values<br />
should be added to the DataTable.For this iam using<br />
one arraylist in managed bean and adding the bean values<br />
to the Arraylist.And iam binding the Arraylist to<br />
JSF page.But the problem is like iam unable maintain the <br />
previous values.SO how should be able to maintain the<br />
bean in the context.Can any one please reply me back<br />
with some solution.Thanks in Advance.Please find the code below.<br
/>
<p />
Managed bean code:<br />
<br />
public class SampleDataTableBean extends PageCodeBase {<br />
<br />
private String name;<br />
private String SSN;<br />
private VehicleDescriptionList vehicleDescriptionList;<br />
protected HtmlScriptCollector scriptCollector1;<br />
VehicleDescription vehicleDescription; <br />
public String vehicleInform(){<br />
<br />
// FacesContext context = FacesContext.getCurrentInstance();<br />
<br />
// Application app = context.getApplication();<br />
<br />
// ValueBinding binding =
app.createValueBinding("#"); <br />
<p />
//VehicleDescriptionList contactListBean = (VehicleDescriptionList)
binding.getValue(context);<br />
<br />
// facesContext1.getCurrentInstance().<br />
VehicleDescription vehicleDescription = new VehicleDescription();<br
/>
vehicleDescriptionList = new VehicleDescriptionList();<br />
vehicleDescription.setName(this.name);<br />
vehicleDescription.setSSN(this.SSN);<br />
vehicleDescriptionList.add(vehicleDescription);<br />
getSessionScope().put("vehicleDescription",
vehicleDescriptionList);<br />
return "Success";<br />
<br />
}<br />
<br />
public String getName() {<br />
return name;<br />
}<br />
public void setName(String name) {<br />
this.name = name;<br />
}<br />
public String getSSN() {<br />
return SSN;<br />
}<br />
public void setSSN(String ssn) {<br />
SSN = ssn;<br />
}<br />
<br />
public VehicleDescriptionList getVehicleDescriptionList() {<br />
return vehicleDescriptionList;<br />
}<br />
<br />
public void setVehicleDescriptionList(<br />
VehicleDescriptionList vehicleDescriptionList) {<br />
this.vehicleDescriptionList = vehicleDescriptionList;<br />
}<br />
<p />
}<br />
<p />
JSF page code:<br />
<br />
<%@page language="java" contentType="text/html;
charset=ISO-8859-1"<br />
pageEncoding="ISO-8859-1"%><br />
<%@taglib uri="http://java.sun.com/jsf/core"
prefix="f"%><br />
<%@taglib uri="http://java.sun.com/jsf/html"
prefix="h"%><br />
<%@taglib uri="http://www.ibm.com/jsf/html_extended"
prefix="hx"%><br />
<p />
<html><br />
<head><br />
<title>DataTableTestPage</title><br />
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1"><br />
<meta name="GENERATOR" content="Rational Application
Developer"><br />
<link rel="stylesheet" type="text/css"
href="theme/stylesheet.css"<br />
title="Style"><br />
</head><br />
<f:view><br />
<body><br />
<hx:scriptCollector id="scriptCollector1"><br />
<br />
<h:form id="form1" styleClass="form"><br
/>
<table border="0" cellpadding="0"
cellspacing="0"><br />
<tbody><br />
<tr><br />
<td><h:outputLabel id="label1"
styleClass="outputLabel"><br />
<h:outputText id="text1"
styleClass="outputText"
value="Name:"></h:outputText><br />
</h:outputLabel></td><br />
<td><h:inputText id="text3"
styleClass="inputText"<br />
value="#{vehicle.name}"></h:inputText>&
;lt;/td><br />
</tr><br />
<tr><br />
<td><h:outputLabel id="label2"
styleClass="outputLabel"><br />
<h:outputText id="text2"
styleClass="outputText"
value="SSN"></h:outputText><br />
</h:outputLabel></td><br />
<td><h:inputText id="text4"
styleClass="inputText"<br />
value="#{vehicle.SSN}"></h:inputText>&
lt;/td><br />
<td><br />
</td><br />
<td><br />
<hx:commandExButton type="submit"
value="Submit" id="button1"<br />
styleClass="commandExButton"
action="#{vehicle.vehicleInform}"></hx:commandExButton&a
mp;gt;</td><br />
</tr><br />
<tr><br />
<td><br />
</td><br />
</tr><br />
<tr><br />
<td><br />
<hx:dataTableEx border="0" cellpadding="2"
cellspacing="0"<br />
columnClasses="columnClass1"
headerClass="headerClass"<br />
footerClass="footerClass" rowClasses="rowClass1,
rowClass2"<br />
id="tableEx1" styleClass="dataTableEx"<br />
var="varvehicleDescriptionList"<br />
value="#{vehicle.vehicleDescriptionList}"><br />
<hx:columnEx id="column1"><br />
<f:facet name="header"><br />
<h:outputText id="text6"
styleClass="outputText"
value="Name"></h:outputText><br />
</f:facet><br />
<h:outputText id="text7"
styleClass="outputText"<br />
value="#{varvehicleDescriptionList.name}"></h:o
utputText><br />
</hx:columnEx><br />
<hx:columnEx id="columnEx1"><br />
<f:facet name="header"><br />
<h:outputText id="text5"
styleClass="outputText"
value="SSN"></h:outputText><br />
</f:facet><br />
<h:outputText id="text8"
styleClass="outputText"<br />
value="#{varvehicleDescriptionList.SSN}"></h:ou
tputText><br />
</hx:columnEx><br />
</hx:dataTableEx></td><br />
</tr><br />
<tr><br />
<td><br />
</td><br />
</tr><br />
</tbody><br />
</table><br />
</h:form><br />
</hx:scriptCollector><br />
</body><br />
</f:view><br />
</html><br />
<br />
Thanks & Regards<br />
|
| Post Reply
|
|
|
|
|
|
|
|
|
|