wood burning stoves*
The moose likes JSF and the fly likes adding an empty row to a datatable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "adding an empty row to a datatable" Watch "adding an empty row to a datatable" New topic
Author

adding an empty row to a datatable

biny panackal
Ranch Hand

Joined: Apr 12, 2007
Posts: 72
hi,
i am having a dataTable in my jsf page. i have to add an empty row to the existing table. How can i be possible any body know this pleas help me. It is my 5th day on this issue..


Biny Balan
binypanackal@gmail.com
Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536
Just add a blank record to the arraylist that is bound to your data table.


MCSD, SCJP, SCWCD, SCBCD, SCJD (in progress - URLybird 1.2.1)
biny panackal
Ranch Hand

Joined: Apr 12, 2007
Posts: 72
thank you Mr.Richard Green ,

The situaltion is like that. while clicking on my add button i have to add a new row to the data table. which contain a text box too. and when clicking on the save i have to save all the data from the datatable. How can i get the values of all the text box in the datatable.
biny panackal
Ranch Hand

Joined: Apr 12, 2007
Posts: 72
hi i tryied adding a blank record to my existng list and it doesnt worked
Pavel Kubal
Ranch Hand

Joined: Mar 13, 2004
Posts: 356
Maybe you could provide us with more info. Like what happened when you tried to add blank record? What exceptions are you getting?
biny panackal
Ranch Hand

Joined: Apr 12, 2007
Posts: 72
Datatabl
<h:dataTable binding="#{Page2.dataTable1}" headerClass="list-header" id="dataTable1" rowClasses="list-row-even,list-row-odd"
style="left: 168px; top: 72px; position: absolute" value="#{Page2.dat}" var="currentRow">
<h:column binding="#{Page2.column1}" id="column1">
<h:inputText id="outputText1" value="#{currentRow.name}"/>
<f:facet name="header">
<hutputText binding="#{Page2.outputText2}" id="outputText2" value="column1"/>
</f:facet>
</h:column>
</h:dataTable>


Bean clas
//adding two new elements to datatable.
//am using my constructor Page2(Strig name) to set the values for the obj
public List getDat()
{
list.add(new Page2("test"));
//page[0]=new Page2("biny");
return list;
}
//this is for adding the new row.
public Page2[] test()
{
list.add(new Page2(""));

return page;
}
biny panackal
Ranch Hand

Joined: Apr 12, 2007
Posts: 72
am not getting any kind of exeption but the row is not added
A. Dusi
Ranch Hand

Joined: Sep 27, 2004
Posts: 114
Make sure the page is refreshed once you add the row.
Can you post the code that the ADD button is calling? Is that an action or actionListener?
Also from your code below, I could not figure out when this test() is called and why it is returning an array.


//this is for adding the new row.
public Page2[] test()
{
list.add(new Page2(""));

return page;
}
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16011
    
  19

What A. Dusi means is that an action processor returns a String. If you attempted to define this method to be called directly as an action processor, it wouldn't match the signature requirements and wouldn't get called.


Customer surveys are for companies who didn't pay proper attention to begin with.
biny panackal
Ranch Hand

Joined: Apr 12, 2007
Posts: 72
thanks for your replay,

the ruturn type was the problem..
i need to replay list..
but now i added a single row. but when agin i am clicking the add buttion i am not able to add the second add row insted the page is getting refressed and only one row is getting added..


i will send the code in detail to you soon.. i have to make sure am not done any mistake since i send it to you.
Pascal Zelen
Greenhorn

Joined: Dec 14, 2005
Posts: 3
Hi!

Example of adding a new client to a clienttable (left out irrelevant details).

In JSF page:

<h:commandButton id="addbutton" value="Add Client" action="#{clientBean.addClientAction}">
In backing bean (clientBean):

List<Client> clients;

public String addClientAction() {

Client client = new Client();
clients.add(client);
FacesContext.getCurrentInstance().renderResponse();
return null;
}
[ November 29, 2007: Message edited by: Pascal Zelen ]
ramakrishnan perumal
Greenhorn

Joined: Apr 11, 2013
Posts: 1
Hi Biny,

I am Facing the same Situation. Could you please post your XHTML tag for adding new Rows and the Action Event for AddAction in Backing Bean?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16011
    
  19

Welcome to the JavaRanch, Ramakrishnan!

You have "awakened a zombie". That is the term we use to describe threads that have been dormant for a long period of time. We don't encourage that. After this long, it's very possible that none of the people in the thread still frequent this forum, have the same jobs, or even are working with the same technology. For that matter, the technology they were working with has probably changed a lot since then.

So it's better to just start a new thread of your own. We don't charge extra!
 
 
subject: adding an empty row to a datatable