aspose file tools*
The moose likes JSF and the fly likes how to add a row dynamically  in panel grid by clicking on command button using jsf Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "how to add a row dynamically  in panel grid by clicking on command button using jsf" Watch "how to add a row dynamically  in panel grid by clicking on command button using jsf" New topic
Author

how to add a row dynamically in panel grid by clicking on command button using jsf

Meena sabapathy
Greenhorn

Joined: May 31, 2009
Posts: 2
Hello all,


Iam new to JSF.I created a form which contains panelgrid with rows and one command button.when i click on the command button it should display a new row(textboxes) dynamically.Can anyone help me on how to do this...


Here is my code:

grid.jsp

<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Grid Data</title>
</head>
<body>
<f:view>
<h:form>
<br><br><br><center>
<h:panelGrid width="500" bgcolor="#e6edfd" columns="5" border="0" style="display:block;text-align:left">

<hutputText value="Name"></hutputText>
<hutputText value="num1"></hutputText>
<hutputText value="num2"></hutputText>
<hutputText value="Fax"></hutputText>
<hutputText value="Email"></hutputText>

<hutputText value="Pm :"></hutputText>
<h:inputText maxlength="10" size="10" value=""></h:inputText>
<h:inputText size="10" value=""></h:inputText>
<h:inputText size="10" value=""></h:inputText>
<h:inputText value=""></h:inputText>

<hutputText value="Pe :"></hutputText>
<h:inputText size="10" value=""></h:inputText>
<h:inputText size="10" value=""></h:inputText>
<h:inputText size="10" value=""></h:inputText>
<h:inputText value=""></h:inputText>

<hutputText value="of :"></hutputText>
<h:inputText size="10" value=""></h:inputText>
<h:inputText size="10" value=""></h:inputText>
<h:inputText size="10" value=""></h:inputText>
<h:inputText value=""></h:inputText>

<hutputText value="Dj :"></hutputText>
<h:inputText size="10" value=""></h:inputText>
<h:inputText size="10" value=""></h:inputText>
<h:inputText size="10" value=""></h:inputText>
<h:inputText value=""></h:inputText>

<hutputText value="Df :"></hutputText>
<h:inputText size="10" value=""></h:inputText>
<h:inputText size="10" value=""></h:inputText>
<h:inputText size="10" value=""></h:inputText>
<h:inputText value=""></h:inputText>

</h:panelGrid>
</center>
<br><br><br><center>
<h:commandButton action="" value="Add Row" />
</center>
</h:form>
</f:view>


</body>
</html>





Bean class:





package com.isi.grid.bean;

public class griddata {
String name;
private int num1;
private int num2;
private int fax;
String email;



public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getNum1() {
return num1;
}

public void setNum1(int num1) {
this.num1 = num1;
}

public int getNum2() {
return num2;
}

public void setNum2(int num2) {
this.num2 = num2;
}

public int getFax() {
return fax;
}

public void setFax(int fax) {
this.fax = fax;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

}
Martin Lopez Ochoteco
Greenhorn

Joined: May 28, 2009
Posts: 15
Hi, I'm not really answering your question, but have you considered using dataTable component instead of panelGrid?
The difference is that in dataTable you can bind its value to an array of inputTexts or whatever objects you need, then you can add inputText components to this array by a method binded in the action property of your commandButton.


JM.-
Wei Geng
Greenhorn

Joined: Dec 10, 2004
Posts: 28
I suggest you to read the book of 'JavaServer Faces in Action', the author of which is Kito Mann.

In this book, the first sample is very similar with the case you described.

The keypoint:

1. Bind the GridPanel with the member variable of the backing-bean with 'binding' attribute of component Tag.
2. Write an method as actionListener.
3. When the button triggers the actionListener method, in this method, you can manipulate the GridPanel Java instance with Backing-Bean member varialbe, getting the child-component collection and adding the new component into it. In the following View-Restore phase, the new element will appear on page.

I hope it can be helpful.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to add a row dynamically in panel grid by clicking on command button using jsf