Executing An Action on JSF Page Startup with Pagedef

Someone asked this on the OTN forum:
Create an JSF page with an ADF Form and a Create button - now when you run it - you first have to click the create button to get an empty record in the screen that you can insert data into.
The question is how do I get the form to load up with an empty record.

Here is a trick that will do it.
Go to your JSF page's pagedef.xml file and look in the structure pane - you'll see this:
create1:

Notice that you have a binding already in place for the Create action.
Next add an invokeAction executable BEFORE the iterator executable.

Create2:

In the dialog that pop-up specify a name for the binding - and then specify the Create operation.

create003.gif:

Now when you'll run the page you'll get an empty record ready for you to work on.

[small update based on some comments]

However, if you'll run the page now you'll see that after you press commit - another new record is created. This is because the action is being executed again after the postback.

The solution for this is to restrict the execution of the method through the refresh condition of the action in the pagedef.
You set it to be ${!adfFacesContext.postback}

You also need to set the Refresh property to be renderModel (see chapter 10.5.5.3 in the ADF Developer Guide)

Create4:

Now run the page and you'll get an empty form when you start and after you press commit there is no additional insert.

Now that you have the understanding of how this technique works behind the scene, I should probably mention that there is a simpler way to create this form.

In your first step, instead of dropping the view as an ADF Form drop it as an "ADF Creation Form".
When you look at the code that was created you'll see the same thing we have created manually in this blog :-)

Comments:

hi, also you can create a "adf creation form" since data control palette. Regards

Posted by fetishcode on July 25, 2007 at 07:11 PM PDT #

I have a different problem. I get my new record when I run my page, but I also get two more, when I come back froma popup window my page is calling. Any suggestions?

Posted by Lana on August 28, 2007 at 01:21 AM PDT #

Lana, I would suggest that you post your question on the JDev forum on OTN with a bit more details about what you are doing specifically. As well as the information about the refresh condition set for your action binding.

Posted by Shay Shmeltzer on August 28, 2007 at 06:48 AM PDT #

Hi, well done.. i have a different problem if u can help me?? i need to set the where clause for my view objects at runtime , because they depend on a runtime variable, but i want this to be at pages load not according to a client invoke???

Posted by Ebtehal on May 21, 2008 at 10:37 PM PDT #

If this approach doesn't work for you (you can replace the create method in this sample with any AM service method that you expose). Then maybe go for sample 60 on Steve Muench's blog: http://radio.weblogs.com/0118231/stories/2004/09/23/notYetDocumentedAdfSampleApplications.html#60

Posted by Shay Shmeltzer on May 22, 2008 at 06:05 AM PDT #

Hi.. Thanks for this post Its very helpful to me. I follow the step and its work but i face one problem when page load the only label of input textbox is appear, textbox not appear . I am not able to identify the problem please help me.

Posted by guest on May 23, 2011 at 03:06 PM PDT #

I will like to know, when I have an ADF Forms and I want to save the information on it, but I have some fields not visible because they have a default value on the DB i got some errors and do not let me save my info on the DB. I'm new on ADF but I really want to know, or if I have those fields with a default value on the DB I should not include the fields on my entities or what can I do?. Thanks

Posted by Leonardo Betancourt on July 07, 2011 at 01:00 AM PDT #

Leonardo, this type of questions should be posted on the JDeveloper discussion forum on OTN. In general if your attribute can be sent empty to the database and it will get a default value there, you can probably mark the attribute as not being mandatory in the EO definition.

Posted by Shay on July 07, 2011 at 02:35 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

me
I'm a Director of Product Management for the Oracle Java Development Tools.
Follow me:
Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today