Dynamically adding a row in a table in JSF
Hi All,
I am searching for a control in JSF using which I can dynamically add more than one row in a table. Currently I am handling this in javasript where I have to click on the "Add Row" button to add one more row at the bottom of the table. I want to get rid of javascript.
If anyone knows about such control then please help me.
Thanks in advance.
Regards,
Saket
hello Saketh,
here is the code for Create Delete Update code where a row is added for every button click..and the JSF code is at the bottom.. today u r blessed with ocean. :-) have fun!!
package redrose;
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.Query;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
public class RowEntry {
private DataModel datamodel = null;
static Integer sid;
private Medata mdobject = null;
private Medata nm=null;
* @return Returns the newMdobject.
public Medata getNm() {
nm = new Medata();
return nm;
* @param newMdobject The newMdobject to set.
public void setNm(Medata newMdobject) {
this.nm = newMdobject;
* @return Returns the mdobject.
public Medata getMdobject() {
return mdobject;
* @param mdobject The mdobject to set.
public void setMdobject(Medata mdobject) {
this.mdobject = mdobject;
public DataModel getDatamodel()
datamodel = new ListDataModel();
Session hibSession;
try{
hibSession = HibernateSessionFactory.currentSession();
Query q = hibSession.createQuery("FROM Medata");
q.setMaxResults(9999);
datamodel.setWrappedData(q.list());
catch(Exception ex){
System.err.println("%%%% Error GetData %%%%");
ex.printStackTrace();
return datamodel;
* Inserting a new Record by reading from Client
public void insertEntry()
Transaction tx = null;
Session session = null;
try{
session = HibernateSessionFactory.currentSession();
tx = session.beginTransaction();
Medata dbmedata = new Medata();
dbmedata.setEmploy(nm.getEmploy());
session.save(dbmedata);
tx.commit();
session.close();
catch(Exception ex){
System.err.println("%%%% Modify Data %%%%");
ex.printStackTrace();
* Modify data
public void updateEntry()
int a =0;
if (this.datamodel == null) return;
Medata mdupdate = (Medata) this.datamodel.getRowData();
if (mdupdate == null ) return;
Transaction tx = null;
Session session = null;
try{
session = HibernateSessionFactory.currentSession();
tx = session.beginTransaction();
Medata dbmedata = (Medata) session.load(Medata.class,mdupdate.getId());
if (dbmedata != null){ // we have to update the record
dbmedata.setEmploy(mdupdate.getEmploy());
session.update(dbmedata);
else // we have to insert the record
dbmedata = new Medata();
dbmedata.setEmploy(mdupdate.getEmploy());
session.save(dbmedata);
tx.commit();
session.close();
catch(Exception ex){
System.err.println("%%%% Modify Data %%%%");
ex.printStackTrace();
* Delete Data
public void removeEntry()
if (this.datamodel == null) return;
Medata mdupdate = (Medata) this.datamodel.getRowData();
Transaction tx = null;
Session session = null;
try{
session = HibernateSessionFactory.currentSession();
tx = session.beginTransaction();
Medata dbmedata = (Medata) session.load(Medata.class,mdupdate.getId());
if (mdupdate == null ) return;
if (dbmedata != null){ // we have to update the record
session.delete(dbmedata);
tx.commit();
catch(Exception ex){
System.err.println("%%%% Delete Data %%%%");
ex.printStackTrace();
Here starts the JSF code
<%@ page language="java" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSF 'trial.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<f:view>
<h:form>
<h:dataTable border="3" value="#{bla.all}" var="currentRow">
<h:column>
<f:facet name="header">
<h:outputText value="Employee Name" />
</f:facet>
<h:inputText value="#{currentRow.employ}">
</h:inputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Employee Number" />
</f:facet>
<h:inputText value="#{currentRow.id}"></h:inputText>
</h:column>
<h:column>
<f:facet name="header">
</f:facet>
<h:commandButton id="Delete" action="#{bla.insert}" value="Delete"></h:commandButton>
<h:commandButton id="Modify" action="#{bla.modify}" value="Modify"></h:commandButton>
</h:column>
</h:dataTable>
<h:commandButton id="Insert" action="#{bla.insert}" value="Insert"></h:commandButton>
<%--h:outputText value="#{bla.sid}"></h:outputText--%>
</h:form>
</f:view>
</body>
</html>
Faces-config file starts here
<managed-bean>
<description>Inserts a record</description>
<managed-bean-name>bla</managed-bean-name>
<managed-bean-class>redrose.RowEntry</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
Similar Messages
-
How to default the value of a selectOneChoice when adding a row to a table
I have a table where one of the fields is a selectOneChoice. When adding a row to the table, the new row to be added displays the selectoneChoice field blank. I would like to have this field default to a specific value within the selectoneChoice when clicking the add button. Any suggestion on the code I need to add in the backing bean? Thanks in advance.
After some studying I figured out how to do this... code below for anyone interested:
DCIteratorBinding dcib = (DCIteratorBinding) bindings.get("someIterator");
RowSetIterator iter = dcib.getRowSetIterator();
Row newRow = iter.createRow();
newRow.setAttribute("yourFieldName",fieldDefaultValue);
iter.insertRowAtRangeIndex(0, newRow);
iter.closeRowSetIterator(); -
Copy the data from first line while dynamically adding a new line in table
Hi,
1. There is a table
2. An add button adds a new line to the table using 'AddInstance'
3. A record is entered in the first line
4. When the add button is clicked it adds a new line and along with it copies the data entered in the first line
My question is how to copy the data from the first line and show it in the new line added. This is required so that user can use most of the common values in the first line.
Thanks,
NikhilYou can use the following Java Script in the Click event of the button.
// Get the number of rows in the table
var nrows = xfa.resolveNodes("page.table.DATA[*]").length;
// Add a new instance(row) to the table
page.table.addInstance.instanceManager(1);
xfa.form.recalculate(1);
// Copy the values from the first line to the newly created row
page.table.DATA\[ nrows \].field1.rawValue = page.table.DATA\[ 0 \].field1.rawValue;
..........field2
..........field3
Thanks,
Chandra Indukuri -
Adding/Deleting rows in a Table
I am trying to get a couple of buttons to work in a table to add/delete rows. I have followed the directions in the LiveCycle designer help and it isn't working.
In a test setup the only difference I can see from the help file is my Table is called Table1 and the subform containing the 2 buttons is called Subform1
I have therefore amended the script for the click event for the AddRow to
"Table1.Row1.instanceManager.addInstance(1);"
Any ideas where I am going wrong?
TIA
AntonyHi,
My usecase is that user enters a url with parameters for example in the text box--> http://host:port/employee/all?department=abc&location=india. Now i want to parse this url , get the parameters out and put it in the table so that it is convenient for users to modify these parameters. User has a option to add and delete the parameter in the table. So once all this is done and user clicks on say save i don't need to send this table to server. i just have to make sure that the values added/deleted from the table are in sync with the url. So in the server i get all the parameters from the url and continue.
Since this is only needed on the client side i wanted to know if we can create a table with no values and then say on tabbing out of the url text box call a javascript that takes value from it and adds new rows to the table.
I am using JDEVADF_MAIN_GENERIC_140109.0434.S -
hi experts ,
i am working on a table and on an action of button i need to add a row. The table has a lots of elements like input fields, dropdown by key, textviews etc. i have created a new row by incresing visible row count on action but the above mentioned elements are not editable . The cardinality of the node bound to table is 1..n and selection is 1....n.
Please suggest me a proper solution.
Thank you.Hi,
Try this code,
IPrivatePopUpMenuView.IProductsElement ele=wdContext.createProductsElement();
ele.setProductId(str1);
ele.setQuantity(str2);
ele.setPrice(str3);
ele.setName(str4);
ele.setDetails("Detailed discription for "+str4);
wdContext.nodeProducts().addElement(ele);
Here str1 str2 are all the value which unwant to add to table.
Regards,
H.V.Swathi -
Dynamic Select of Row in a table in webdynpro Abap
Hi,
I have an requirement, I have an table and a button, I need to select a row in a table based on button action.
For example : in a table i have 3 rows. I am submiting a value in a button, I want to see that row highlighted for the value I am sending through button.
Please let us know the code how to implement this.
ThanksHi,
First you have to go to table and set its property "SELECTION MODE" to single or multi lead depending on ur need.
Then in the ACTION of the button you can use the following code to get the values in the selected row.
DATA:
node to get table node for finding no. of rows
lo_nd_one TYPE REF TO if_wd_context_node,
Get selected row for finding no. of rows
it_table TYPE wdr_context_element_set,
workarea to get selected row
wa_table LIKE LINE OF it_table,
To get the Selected line item into an internal table
CALL METHOD lo_nd_one->get_selected_elements
RECEIVING
set = it_table. " data in internal format
IF it_table[] IS NOT INITIAL.
type conversion for work area
READ TABLE it_table INTO wa_table INDEX 1.
if a row is present
IF sy-subrc IS INITIAL.
Get the values of each attribute
CALL METHOD wa_table->get_static_attributes
IMPORTING
static_attributes = wa_final. "<Selected data in work area.> ---> this will have your data
ENDIF.
Here wa_final is the work area which is of your table fields type.
This wa_final will have the selected row. -
Adding 10 rows in a table.
Hello,
I need to create a 10 rows in a table by clicking a button. I got it in javascript but i am unable to achieve it in ui5.
can you please help me on this.
Thanks and Regards,
Vicky.try this.
Example
-D -
Adding/removing rows in a table
Hi,
how can I add/remove rows in a table in adobe acrobat pro? Please help.It won’t look pretty, but you can manually redact the rows. This can either replace the removed rows with a specific color or you can make the removed spot white/no color.
-
Adding Additional Rows to a table in subform
I am fairly new to Adobe LiveCycle and would really appreciate some help. I have simple table and would like for the user to click "+" or "-" to manage the number of row. I can't figure out now to complete this...then arrive at a SubTotal.
Hi,
I made your form dynamic, also i added some subforms to make your flowed stuff look good and i added sum script to Totla field.
Form attached.
BR,
Paul Butenko -
Adding a row to a table with a button
Good day all;
I think I have now lost it... ;>))
LifeCycle Designer 8.05
Anyway, If the user of the form requires additional rows to enter infoamtion, I want them to be able to add a row using a button. I have tried using the following
Table"N".Row2.instanceManager.addInstance(1); ="N" is the table name.
I have done this on a couple of other forms but I must be missing something as I am geting the following error in the java Consol
"GeneralError: Operation failed.
XFAObject.addInstance:1:XFA:form1[0]:#subform[0]:#subform[1]:Button1[0]:click
The element [max] has violated its allowable number of occurrences."
The form is saves as a Arcobat 8 Dynamic XML form
I
Page 1 is flowed
Subform is flowed
Would someone be so kind as to point me in the right direction.
Thanks all
ChompThanks Radzmar;
You were correct.... It appears I was only looking at the bindings for the damn table not the row.......
Thanks again -
Dynamically adding a row and context binding
Hi All
i need to display existing values in DB in row wise
Also there is a add button on click of this add button i need to insert a row along with the exiting rows
and also bind a context to the new row.
Finally on clicking of Save button i need to update this to a database table
Please guide me how to insert a row dynamically and binding context to it
client dont want to use table.
Thanks
Karthi D.
Edited by: karthi D on Aug 22, 2008 6:35 AMHi,
Displaying table data in view without using table takes time and you need to work more.
To display the table data follow the below steps
1. Create the "TransparentContainer" UI element in view
2. create the context node and attribute according to your table data
3. get the table data and bind to context
IPrivateSDNView.ITableDataNode node = wdContext.nodeTableData();
IPrivateSDNView.ITableDataElement ele = null;
for(int i=0;i<tableRecords.length;i++) {
ele = node.createTableDataElement();
ele.setId(); // set your data to all attributes
node.addElement(ele);
4.in wdDoModifyView get the "TransparentContainer" UI element and set the layout and col size (ex: 4)
IWDTransparentContainer tContainer = (IWDTransparentContainer)view.getElement("TransparentContainer");
IWDGridLayout gridLayout = (IWDGridLayout)tContainer.createLayout(IWDGridLayout.class);
gridLayout.setColCount(4);
tContainer.destroyAllChildren();
5. Create the UI elements (textview, label ....) and add to tContainer
IPrivateSDNView.ITableDataNode node = wdContext.nodeTableData();
IWDTextView textView = null;
int count = 0;
for(int i=0;i<node.size();i++) {
count = 0;
textView = (IWDTextView)view.createElement(IWDTextView.class,""i(count++));
textView.setText(node.getTableDataElementAt(i).getAtt1());
tContainer.addChild(textView);
textView = (IWDTextView)view.createElement(IWDTextView.class,""i(count++));
textView.setText(node.getEmpDataElementAt(i).getAtt2());
tContainer.addChild(textView);
To insert records into the above table
1. Create the form with your fields with add button with Action "Add"
2. Create the context for this form
3. In onActionAdd method add the element to TableData node context
Let me know if you are not cleared with above code
Thanks -
Creating a form which allows the adding of rows to a table
Hi there,
I am trying to create a form to get declarations of trusteeships, directorships and large shareholdings of our company's directors, so that we can manage any conflicts of interest. Some directors will have one or two declarations to make; others may have a dozen or so.
I want to create a form for each director to make all of their declarations, but can't see how to create a table, with the ability to add more rows, if you have more declarations to make.
Is there a way t do this?This is not really possible to achieve with a form created in Acrobat. You
can create the fields in advanced and then show/hide them, but you can't
"re-flow" the file on the fly and add more form fields to it, pushing the
rest of the content down the page. For that you would need to use Adobe
LiveCycle Designer, which has a separate forum here. -
Adding one row to a table for displaying calculated amounts
Hi,
My requirement is like this:
We are getting values in the table with the columns
recno rectype amount
1 autofare 100
2 airfare 50
3 busfare 25
4 railfare 10
5 carfare 75
i am getting all the values from backend.
now our requirement is want to calculate amount for reno1,3,5 and row should be displayed as below:
recno rectype amount
1 autofare 100
3 busfare 25
5 carfare 75
amount 200 (here amount is not coming from backend.we need to add amount for recno 1,3 ,5 and iot should be displayed like that)
2 airfare 50
4 railfare 10
amount 60
please suggest how to proceed on this?
Regards,
Anithahi Anitha,
you have to create a separate value node for storing original elements and their subtotals in the order you want them in the table.
For showing totals you can use cell variant in the table to give a different look and feel for the subtotal row.
Add another attribute in the value node for storing the variant name. bind this attribute to selected cell variant of table column.
int subtotal =0;
for(int i =0;i < size;i++)
IPrivate<view>NodeElement dataElement = dataNode.getDataElementAt(i);
IPrivate<view>NodeElement tablelement = wdContext.node<table>().createElement();
wdCopyService.copycorresponding(dataElement, tableElement);
//set cell variant to blank for original rows
tableelement.setSelectedVariant("");
wdContext.node<table>().addElement(tablelement);
//Calculate subtotals and add them in another valuenode
subtotal = subtotal + dataElement.getAmt();
if(i ==3)// give condition at which you need to add subtotal row.
IPrivate<view>NodeElement subtotalelement = wdContext.node<table>().createElement();
subtotalelement.setSubtotal(subtotal);
//set cell variant for subtotal row
subtotalelementsetSelectedVariant("subtotal");
wdContext.node<table>().addElement(tsubtotalelement);
subtotal =0; //reset subtotal
hope this helps!
Monalisa -
Adding 2 different rows in the Table in JSF
Hi All,
How can I acheive this in JSF
Let me explain my requirement:
Consider a simple table which is displaying rows.
It has columns say col1->colId and col2->colName.
Id Name
1 kk
2 jjNow on clicking the colId of row1, another row say row001should be embedded in between row1 and row2. Now this row001 should contain 3 columns each having 2 rows.
Id Name
1 kk
DOB ABC Curr Yen
Nation EUR State Thames
2 jj
So the extra details such as DOB, Nation, Curr and state are hidden for id and is displayed only when user clicks Id and collapse when user clicks id again
Don't forget I am novice to JSF :(What you need is a tree.
See Tomahawk (www.myfaces.org) -
Dynamically increasing the rows of a table in interactive forms.
Hi All,
I am new to adobe forms.I am developing an interactive form in webdynpro abap.I have a requirement such that i have 3 columns in a table and the first 5 rows are default i.e, i will add it during design time.when we enter something in the 5th row,6th row should automatically be created which wil be empty.I also need to retrieve the data back into the webdynpro component when user enters something in it and clicks the submit button.can anyone tel me how wil i generate this table and when someone enters something into the form how wil i store the data back in the component.
my context node has hours ,minutes and call code as attributes which wil be the column names.
Thanks in advance.
Regards,
Srividya.Hi Srividya,
For flow of data from the form to webdynpro. Do the follwing:
Suppose you have a table on the form and you want to pass data from this form to web dynpro.
1. Create a node of cardinality 0...n or 1.....n. Add attributes to this. Now this node is as a internal table and the attributes are like intenal table fields.
2. When creating the form. Use This node as the data source for the form.
3. Now its easy in webdynpro ABAP to create a table on the Adobe form. Just drag and drop the Data node(from which you want to create table) from the data view on the designer on to the form.
4. Now its already bound to the node you have created and whatever data you will enter in the table that will be reflected to the node. and you can check it by creating a table on the view from the same node.
5. After you will click on submit button the data will reflect to table on webdynpro view.
If its not works then problem could be that the ACF is not installed on your system due to which button is not processing and fields are not reflecting data.
For ACF you can search it on SAP service market place.
Hope it will help.
Regards,
Vaibhav Tiwari.
Maybe you are looking for
-
I just traded up for the new Iphone 5c. Trying to sync my old info and apps onto my new phone, but it says I need the new version of Itunes... I downloaded it, but my itunes is still the old version and it wont accept my phone. WHAT DO I DO?? Do I
-
Cannot open the file I have downloaded to get a new version of Photoshop
I have had a new computer, and am trying to download the Photoshop Elements 10 again, but I cannot open the file that I get after 20 minutes of downloading from here: Download Photoshop Elements products | 13, 12, 11, 10 In fact, I do have the instal
-
Comparing strings in IfThen() structure of Hyperion Financial Reporting
Can we compare current value of a dimension with a string in the IfThen() structure in hyperion financial reporting tool? I have not been able to carry out the same successfully. Also, I need to get value from a partcular cell to use in IfThen() cond
-
It seems the iphone 5 wifi world is coming to an end? I am a curious fellow tho! Do tell me...any feel good stories of i5 wifi working great out the box?
-
Some letter are not typed well
It's been less than 10 days to use an ipod touch. I charged it with a computer and tried to type, but some English letters are not typed well. What should I do?