Sunday, December 17, 2006

Creating new row using CreateInsert operation

Sample application - CreateInsert.zip, demonstrates how to create editable table with 'create new row' functionality in ADF BC.

We will use Jobs entity, generated from standard HR schema Jobs table. When view object and application module are generated, it is time to drag and drop Jobs table in View layer. Drag and drop it as ADF Table (not read-only). When table is created, expand Operations group and select Create operation.


Drag and drop selected Create operation to the 'actions' facet of the table and create ADF Command Button. However, it is not enough just to drag and drop. Additionally, select created button with right mouse click and choose Edit Binding. In the opened dialog choose CreateInsert instead of Insert as an action for JobsView1.


Now, drag and drop Commit operation to the 'actions' facet of the table and create second ADF Command Button. Finally, we have implemented editable table with 'create new row' feature.

71 comments:

Anonymous said...

How to make exisiting records readonly and newly created record writable untill save.

Andrej Baranovskij said...

Hi,

You must change ReadOnly property value for each af:inputText component contained in af:column. Set ReadOnly property value to - #{row.JobId != null} . This means, if row isn't empty => it will displayed as read-only. In other case, if row is empty => it will be displayed as editable.

Regards,
Andrejus

Anonymous said...

How to make the selected row editable in the table.

Editable should be inline with the table

Andrej Baranovskij said...

Hi,

1). Create in af:column two af:inputText components (one read-only,
second editable) for the same attribute.
2). For Edit button create ActionListener, that will store selected
row ID into managed bean atttribute
3). In managed bean create similar method:

public boolean isEnableEditing() {
FacesContext ctx = FacesContext.getCurrentInstance();
Application app = ctx.getApplication();
ValueBinding bind = app.createValueBinding("#{row.id}");
Long rowId = (Long)bind.getValue(ctx);

this.enableEditing = ids.contains(rowId); // change this

return this.enableEditing;
}

4). For editable af:inputText set #{valueHolder.enableEditing} in
Rendered property

For read-only af:inputText set #{!valueHolder.enableEditing} in
Rendered property

(valueHolder - managed bean name)

Regards,
Andrejus

Anonymous said...

Hi,

I am new to ADF EJB Toplink. I followed your instructions but was unable to commit the transaction to the Oracle database. The UI shows as updated for current transaction but the daabase4 does not get updated. How do I add the explicit commit?

Andrej Baranovskij said...

Hi Pankaj,

You can try to drag and drop Commit operation on your Save button. Also, if you are using EJB and TopLink, you can add commit method call into your EJB Session Bean method.

Regards,
Andrejus

Gary said...

probably because I'm a newbie on ADF (or because I'm using 11g) but I can't find the "Actions" facet on the table. I assume I should be looking at the "Structure" view in JDev. I see the af:table. All the af:columns and the "Table facets" with detailsStamp, footer and header.. But I don't see the "Actions facet". Any pointers would be greatly appreciated.. Thanks!

Gary

Andrej Baranovskij said...

Hi,

Yes, Actions facet is not defined in 11g. But you can put buttons into header facet - it shouldn't be a problem. Since we have header facet, Actions facet is not needed.

Regards,
Andrejus

Gary said...

I realized I posted this to the wrong blog entry!

ok, I will try that. Now if I could only get a button to actually show up!!!

Thanks!

Anonymous said...

Hi,

I have a two questions regarding adding new rows to table:

1) As you can see each time it adds the newly created row at the top of the table.
Could you please tell me how I could add it at the end of the table? By at the end I mean after all rows in the table. For now I am considering that my table would not have too many rows a few like around 20-30 rows.

2) Can I add more than one empty row? My requirement is to add three empty rows at the end of the table when the user clicks on create row.

Any help would be greatly appreciated.

Thanks

Andrej Baranovskij said...

Hi,

Yes for sure.

For question one you can use similar code:

BindingContainer bindings = getBindings();

DCIteratorBinding dcib = (DCIteratorBinding) bindings.get("JobsView1Iterator");
RowSetIterator iter = dcib.getRowSetIterator();
Row newRow = iter.createRow();
iter.insertRowAtRangeIndex(iter.getRangeSize() - 1, newRow);
iter.closeRowSetIterator();

For question two, I have already posted exactly similar sample:

Create multiple rows in Oracle ADF

Regards,
Andrejus

* Star Gazer * said...

Hi Andrejus,

Thank you for your prompt reply.
I have one more question regarding this.
User clicks on Add, this add's three new rows to the table. But he ends up filling only one row in the table. The other two rows are empty. Now he clicks on submit to commit the rows. I do not want to add the two empty rows, commit is happening through the Model directly. So can I write a validator on the table such that I remove the rows that are not filled by the user. Since the rows are not committed to the table how do i handle this?

-Thanks and Regards

Andrej Baranovskij said...

Hi,

You can create Action method for Commit button and in that method access Iterator. You can check rows in Iterator and remove any not needed rows.

I will post such sample in the future!

Thanks,
Andrejus

Hiren said...

Hi,

I am using RichTable insted of CoreTable. Richtable is bound to List which contains list of object. When I remove the object from list i can the see the richTable inside backing bean is updated and row count is deceresed. But it is not getting refreshed into UI.

Regards,
Hiren

Andrej Baranovskij said...

Hi Hiren,

RichTable is available in 11g, probably you are using 11g. I have sample application for CRUD operations in 11g - JDeveloper 11g - Create, Edit and Delete operations in ADF Faces af:table component. Hope it will solve your problem.

Regards,
Andrejus

VB said...

Hi,

I want to display a row in a table while loading the page.

Thanks & Regards
Vimala Balan

Andrej Baranovskij said...

Hi Vimala,

It shouldn't be complex. You can just put InvokeAction in Page Definition to invoke Create action. InvokeAction should have condition to be activated on page load.

Regards,
Andrejus

VB said...

Hi Andre,

Thanks for your help. If you don't mine please send sample code. What are the steps to be followed in JDeveloper. Since i am new to the framework... seeking help from people like you to build my application.

Thanks & Regards
Vimalan Balan

VB said...

Hi Andre,

The below syntax given in page definition file. Actually i have master table and detail table. Header details are need to store in master and values from rows need to store in detail table. While loading the page i can show one row now but if i refresh the page it showing two rows and also if i add another row by using create and refresh again it displays 4 rows. Kindly help to solve this.

invokeAction id="createNewRequest" Binds="Create" Refresh="prepareModel"

Thanks & Regards
Vimalan Balan

Andrej Baranovskij said...

Vilmalan,

You are almost right, just little fix from me, you need to use:

invokeAction Binds="Create" id="invokeCreate" Refresh="prepareModel" RefreshCondition="${adfFacesContext.postback == false}"

I have tested, it works.

Regards,
Andrejus

VB said...

Hi Andre,

Once again thanks. I send a mail to you with screen shot and code. Its not working for me.

While page loading it displays single row but if i refreshed again means it shows single row but with navigation option in the row... previous and next.

Thanks & Regards
Vimalan Balan

VB said...

Hi Andre,

Its possible for to check whether the current row is entered or not while refreshing the page or submitting the page.

Any sample code is there means please send it or post it.

Thanks & Regards
Vimalan Balan

Andrej Baranovskij said...

Hi,

I will send you my updated application, with added invokeAction.

Regards,
Andrejus

Anonymous said...

How to do this with ADF Toplink ?

Thanks,
Ricky

Andrej Baranovskij said...

Hi Ricky,

I think it's easily possible to do the same with TopLink as well.

Regards,
Andrejus

Anonymous said...

Hi Andrejus,
I've just found out the toplink method CollectionBeanClass must be set to UpdateableCollection to show operation action in Data Control such as Create,Next,etc..
I have successfully do 'Create' button, but Commit operation is little bit different between ADF BC and Toplink. I've tried using mergeEntity/persistEntity, but still can not commit the new row to db. I've also tried to create method commitTrans in EJB Session bean method, but it's not updated to db. The code is like this :

public void commitTransaction() {
Session session = getSessionFactory().acquireSession();
UnitOfWork uow = getSessionFactory().acquireUnitOfWork(session);
uow.commit();

}

I know there must be something wrong with this code. Could you help ?

Thanks,
Ricky

Anonymous said...

Hi,
i can use persistEntity and pass this value to the entity parameter:
${bindings.findAllMenuDataIter.currentRow.dataProvider}

the new row successfully inserted to database.

Try mergeEntity and also pass the same value, the row did not updated to db.

Regards,
Ricky

Andrej Baranovskij said...

Hi Ricky,

I think this is correct behavior. Since mergeEntity is used to update existing object.

Regards,
Andrejus

HusainD said...

Hi Andrejus,

I am using ADF + EJB + Toplink. How do we configure a button such that it will create a new row or update if row exists?

Andrej Baranovskij said...

Hi,

You should use mergeEntity operation.

Regards,
Andrejus

Unknown said...

Hi

I need to create more than one row using the create Insert operation. Now I want to access the values of the newly created rows .. and insert them into some other table through the Application Module .. writing a method there where I will pass the values dynamically..

Is it possible to do that ??

Andrej Baranovskij said...

Hi,

For multiple rows check my blog post: Create multiple rows in Oracle ADF.

Regards,
Andrejus

Anonymous said...

Hi Andrejus,

What about inserting row that use Oracle generate sequence? since we can't just input this number. How would we configure the "Create" and "Commit" operation to work for it.

Thanks,
Minh

Andrej Baranovskij said...

Hi,

It will work automatically. Just specify DBSequence type for your attribute.

Regards,
Andrejus

Bharathi said...

Hi Anderjus,
i am bharathi. i followed the above mentioned step.
i have one problem i am using LOV is one of the column in that ADF Table.
when ever i add one more row in that table it refresh so the selected LOV also refreshed so the selected value empty. it means i wand select again.
How to resolve this problem,

thanks..

Andrej Baranovskij said...

Hi,

There should not be difference for fields with LOV. May be you need to commit, before creating new rows.

Andrejus

Anonymous said...

Hi,
I have a requirement to make first two columns of the newly added rows invisible or disabled.Can u please suggest how to proceed with it? I'm new to ADF so request you to kindly provide me with some explaination in detail..

Anonymous said...

Hi,

I dragged VO of a table on JSF page. I want one column of it to be in the form of a drop down. When I converted it from input text to selectManyCheckbox,I got error message and when i deleted the column with input texts which i got by dragging the VO and dropped a selectManyCheckbox component from component palette then the value selected in this drop down was not recognized by the application. It's taking null. Can you please help me in resolving either of the below:

1) After dropping VO if i convert one column's inputText to selectManyCheckbox then how to overcome the error and insert the selected value in that paricular column of the table?

OR

2)If I delete one column's inputText and drag and drop selectManyCheckbox from component palette then how do i get the value selected in this dropdown?

Anonymous said...

When Navigating from one Jsf page to another Jsf its giving error as JBO-27014.(SummaryId attribute is required)JDeveloper 10g(10.1.3.3.0) Version.

But SummaryId is there is First Page EO attribute its giving error in Second Jsf Page.

Can Any One, Plz Help us in this regard.....................

Anonymous said...

hi,im havina a small query in ADF. i'm having 2 jspx pages and i want to navigate from one page to another. for that i have given this
(return "To SkillsInformation";)
To SkillsInformation is the name of the navigation link for other page. but after pressing save and proceed button in which i have written this return statement, it is navigating into the second jspx page and while giving data for second page it's showing error as

Error:
JBO-27014: Attribute SummaryId in TempSkillsEO is required

SummaryId is the primary key in the first jspx page's EO. but we are not passing any SummaryId into second jspx page.


can u plz give solution to it.

Anonymous said...

why i can't create new row, when i create table without generate from data control (only drag some field i need it into table column)??????

thx

Anonymous said...

I am trying jdeveloper 10g and I used the createInsert as you have demonstrated here to insert a new row in a table.

The table I have created has rows with fields with selection from a dynamic LOV (List Of Value).

When the new row is inserted in the table the existed rows are re-displayed with empty all the fields that are LOV.

How I can fix that?

Unknown said...

Hi,
How can I use Create with Parameters operations in JDeveloper 11g, can you give me an simple example or some tips.
Thank you!

Regards,
Eleven.Xu

Anonymous said...

Hi Andrew,

I am new to ADF and i have a question about the invokeAction. Currently i am developing some sample application and i am stretching my head to resolve the issue. Hope you will throw some idea to help me on this.

I have a taskflow and a view. In the backing bean i have the init() method and i am invoking that when the taskflow is initialized. However when i refer the one ADF component inside the method then i am getting null because the component is not being initialized based on the JSF phases. Now my question is i would like to execute on method when the page is being loaded. Any other way that i can use the InvokeAction to do that. please not i am not using DataControl for the model. Using standard EJBs.

Please help me on this.
-thiva

Andrej Baranovskij said...

Hi,

You can try to use Method Call before navigating to your page, however it still may not work if you are referencing ADF Component.

As second choice, you can declare beforePhase method on af:document tag, means method will be invoked on page load.

With invokeAction you can invoke only methods declared in Page Definition.

Regards,
Andrej

Anonymous said...

Thanks for the quick response. I tried out this and it is working for view and document. How about for the dialog, popup and Boundedtaskflow which doesn't have the af:view or af:docuemnt.

- thiva

Anonymous said...

Thanks for the quick response. I tried out this and it is working for view and document. How about for the dialog, popup and Boundedtaskflow which doesn't have the af:view or af:docuemnt.

- thiva

Anonymous said...

How to set cursor focus on the first column of a newly added row in a table?

Andrej Baranovskij said...

Hi,

You can try to use DisplayRow = selected property on af:table.

Regards,
Andrejus

Anonymous said...

HI Andrejus,
I am struck at point:-
I want to write code (Enable/Disable and assignment of value to input text etc).

I have gone through Jdeveloper forum and try to implement onpageload() through phaselister but it is not working with. The onpageload()not being called when in open that page.

I need your help in this regard.

Can upload/post any example regarding this issue

I will be thankfull this favour.

Regard

M Niaz

Unknown said...

Hi Andrejus,
I have dragged the view object as a ADF Table and created 3 buttons for CreateInsert, delete and commit functionality for the same.
When i click on createInsert it create's a new row in the table. What should i do if i want to delete that new empty row created. ( it gives me error sayin the Primary key fields needs to be entered and doesn't let me delete the empty row usind the delete button)

Please help.

Regards,
Aparna

Andrej Baranovskij said...

Hi,

You need to use Rollback operation for this, not Delete.

Andrejus

Anonymous said...

Is there any functions or procedure like the NEXT_RECORD in Oracle Forms Developer?This use for the detail record operation to create multi rows and bar scanners input. in your examples it needs to push button to create or insert record.
Im new with this jdeveloper and no knowledge about it ,html or java(etc.). but im trying this adf and im interested with it...

Currently using Forms 10g on AS10g

sorry for my english...
Tnx...

Anonymous said...

Is there any functions or procedure like the NEXT_RECORD in Oracle Forms Developer?This use for the detail record operation to create multi rows and bar scanners input. in your examples it needs to push button to create or insert record.
Im new with this jdeveloper and no knowledge about it ,html or java(etc.). but im trying this adf and im interested with it...

Anonymous said...

Hi,

In my jspx page i have a button,textfield and a table. when user enters a number, say '2' and clicks on the create button 2 rows have to be created in the table provided a unique id(which is combination of char and numbers)be inserted in table and displayed in the table. So when button clicked generating unique id, inserting it to table and displaying it to table has to be done. How can i do that.

Anonymous said...

Hi Andrejus,

This is really a good post. I have one basic doubt here please clarify.
Consider I have two text boxes in my UI and two buttons save and cancel. What operations I should use here. My main doubt here is can i use commit alone without create/createInsert.???

Andrej Baranovskij said...

Yes of course, why not?

Andrejus

Anonymous said...

Hi Andrejus,

Can you provide one quick code snippet for the below scenario.

Consider I have two text boxes and a check box in my UI. and there is no data in the tables. so my landing page should contain two textboxes and one check box, one save button and one cancel. So how can I achieve this. As per my undestanding to insert records into database we should first click either create/createInsert buttons and I dont want to use this. One more thing I observed is if there is no data in the tables. The UI Components are shown in read only mode? why is this behavior? How can i made them editable? Please clarify with some example/code and steps. I am struggling for this past one week.

Andrej Baranovskij said...

May be this post will help you: http://andrejusb.blogspot.com/2011/11/oracle-adf-11g-table-insert-with-empty.html

Andrejus

Anonymous said...

Hi,
No that solution doesn't work for me. In my case consider i have a table with a primary key, a varchar2(15), char(1) columns. and there is no data in that table. now i want to insert data into this table from the ADF page. my adf page contains one textbox bound to that varchar2(15) column and one checkbox bound to char(1) and one save button. now there is no create or createinsert buttons on my page. so how can i do this? i observed if there is no data in the table the textbox is not coming ine thr ui and checkbox is shown in readonly mode. please provide some code snippet. i m struggling for past 15 days. thanks in advance.

Andrej Baranovskij said...

And how you want to insert data without Create data, there must be some other event?

Andrejus

Anonymous said...

Yes Andre, I have a BTF and in that i have a method call. So can i do something with this?? I am thiking like at the time of calling this method it should verify whetehr data is there in the table or not if there is no data then it has to show in create page(with empty fields) and if data osi there then the adf page has to show that existing data. Please provide some solution for this.

Anonymous said...

Hi Andre,

Could you please respond to my previous post.

Andrej Baranovskij said...

Yes, you can implement this easily with Router activity and calling different Method Actions from TF.

Andrejus

Ankitha said...

Hi Andrejus,

Thanks for the post. But in one of the comments the code you provided for adding at the end of the row

iter.insertRowAtRangeIndex(iter.getRangeSize() - 1, newRow)

This will throw error for out of range, so rather it should insert at the index after last row

iter.insertRowAtRangeIndex(iter.getRangeIndexOf(lastRow) +1, newRow);

Andrej Baranovskij said...

Thanks for update.

Andrejus

Anonymous said...

Hi,
I have two col1,col2. col2 is unique.
I want to insert record if it's new(col1 value is new or doesnot exist) and override col2 if the col1 value is already exist,programmatically.

Anonymous said...

Hi Andrejus,

Thank you so much for the post. It helps newbies like to learn a lot from such posts.I have a question regarding similar implementation.

Requirement:

Page to be loaded with an empty form and a table with values. On filling in the empty form and clicking save, the row should be committed to the database and added to the table as well, but the focus on the table has to be on the newly created row. There is only one button to save as on saving the form, the form gets erased and a new form appears and the saved row is populated in the table.

Approach Followed: In my taskflow, I made createInsert as a default view for the iterator I needed and then directed to my view with form and table. I dragged and dropped commit button as save below the form and it works fine.

Question: My question here is I want to programatically commit the page because before committing I want to do some other logic in the page

I used the following
BindingContainer dc = (BindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
OperationBinding operbind= dc.getOperationBinding("Commit");
operbind.execute();

On doing programatically I only see the row populating but its not getting saved. Could you please help me to programatically save on createInsert

Anonymous said...

hi , i want to create the same table but jobID wont be shown on table but when i insert the row to db, i will get jobid from session, is it possible to do it in adf?
thanks for help.

Anonymous said...

Just check if your page def holds commit operation in Binding section. If no, Click on Binding tab of your page , in Bindings column , click on Add , choose a Action , click OK , Select The appropriate DataControl and Select Commit as Operation.

Unknown said...

I have created editable table but one of my column is LOV field for which i have used 'SelectOneChoice' but wen i call 'CreateWithParams' method to get new editable row I m not getting the LOV field, filed is not at all available not even empty. Plz suggest