Java Class Data Control and ADF Binding Tricks Demo

This demo started from a simple request on the OTN forum asking how would you go about creating a JSF page that reads and writes a file content.

The quick answer I gave was that you can do this with a simple Java class that you expose as a datacontrol. But then I started thinking there will be some more tricky parts that you'll need to do in order to get the UI and binding to work exactly as you would like. The trick is to merge the result of one operation to be the input for the other operation. I played around with the solution I provided and decided to record this since there are a few steps here that will be useful to refer people to in the future.

The "Tricky Parts" that demo shows are:
1. Creating a data control from a simple Java class
2. Binding with ADF Parameter Form to invoke methods
3. Setting the value for method's parameters using the binding tab
4. Creating a backing bean for a JSF page
5. Modifying a default ADF method in a backing bean
5. Accessing an ADF binding control value in your backing bean
6. Binding an existing JSF components to a backing bean
7. Deleting a component from a JSF page without deleting it's binding

Here is the demo:

I hope this helps.
(And sorry that I got a phone call and an IM while recording :-) )

Note - some people requested to see the actual code - you can find the completed workspace here.

Comments:

Thanks Shay ! As always very simple and lucid explanation. 1. One question though. Could we have populated the return value of 'readFile' directly (using EL declaratively) into the text box bound to the writeFile input variable? This would have eliminated creating a backing bean isnt it? 2. I have not been able to understand binding API completely. How did the ControlBinding class for the 'Return' binding get converted into String used in setValue() method? Shouldnt it have needed 'inputValue' of Return binding? (just like we use in EL bindings.return.inputValue). Please advice. PS. ScreenToaster widget doent allow us to scroll thru the video and finding what we want sometimes requires us to go thru the entire tutorial :)

Posted by husain on August 04, 2009 at 06:08 AM PDT #

Husain, The tricky part is that the return value from the read operation is in a "read-only" mode - so if you used that EL as the value for the inputTextItem for the writeFile - it would have turned it into an output text. I'm guessing this also explains the reason you didn't need the inputValue.

Posted by shay on August 04, 2009 at 06:16 AM PDT #

You are right. I tried to use a richTextEditor to display a value from a java file and used EL #{bindings.return.inputValue} and the RTE was displayed as output text. However I tried to put the EL #{bindings.return} and it does seem to work now. Is it possible to share your code or is it possible that i send you my code that worked? Thanks, Husain

Posted by husain on August 04, 2009 at 11:49 PM PDT #

Shay, Did you post the project for this example anywhere? thx,matt

Posted by Matt Orsie on November 16, 2009 at 02:04 AM PST #

Matt, You can get the workspace for this blog here: https://codesamples.samplecode.oracle.com/servlets/tracking/id/S478 Shay

Posted by shay on November 16, 2009 at 07:09 AM PST #

Hi Shay Would you be able to push this solution to any ADF controls and would it make sense for you? Basically in the past we've been developing ADF application based on a DATA model and this is the regular way to do it. But sometimes you need to prototype how the application will look and you don't have yet the database model and teh middle tier. So could we imagine to use ADF controls with data that would be just populated in a bean or in a file (like you do) and redirect later the user interface to a real database model via the middle tier? In this context do you have more samples to point to, that you would know?

Posted by Stephane on October 13, 2010 at 08:00 AM PDT #

Stephane, for quick prototyping without an actual ADF data model we recommend using the ADF place holder data control. Some basic info here: http://www.oracle.com/technetwork/developer-tools/jdev/ccset20-all-097735.html and http://technology.amis.nl/blog/3408/adf-11g-placeholder-data-control-for-off-line-demonstration-of-application-andor-rapid-ui-prototyping-without-a-need-for-a-business-service

Posted by shay.shmeltzer on October 13, 2010 at 08:09 AM PDT #

hy Shay, that's nice tutorial...., but i have question 1. with more binding between java class with jspx components, control data generated will be more. whether it will not affect the application ? 2. why when I create a java class that the model> view object> class, there was an error [can not find the file DCX], my question, whether the data control can only be done in CiewController> ApplicationSource> class ..?. regard thanks ..:)

Posted by agungdmt on October 29, 2010 at 10:15 PM PDT #

agungdmt For 1 - I'm not sure what you mean here - yes there will be more meta-data created for the Java class, but what is the alternative? writing a managed bean to access the Java class? how is this any simpler? 2. Again I'm not exactly sure what you are trying to do, but you should be able to access any java class, right click it and create a data control. Then as long as your view project is mapped to depend on the project that contains your model you should be able to see them in your data control palette. If you are running into specific problems try posting on the JDeveloper forum on OTN.

Posted by shay.shmeltzer on November 02, 2010 at 05:44 AM PDT #

Hi Shay, I have a JSF page that has a datacontrol.. I convert to portlet using "Create Portlet entry" in Jdev 11g. is it possible to call the data control using a portlet parameter passed to my portletized app? thanks!

Posted by cosmoghurl on December 12, 2010 at 06:18 PM PST #

I'm not too familiar with portlets - so it might be best to post the question on the WebCenter forum - but in general from your binding you should be able to access anything that is in the scope of the page and refer to it in your data control parameters.

Posted by shay.shmeltzer on December 13, 2010 at 02:29 AM PST #

Hi; I have don't data controls palette in JDeveloper 11g. How I can add? thanks.

Posted by melih on May 26, 2011 at 09:09 AM PDT #

Melih, make sure that you are using the Studio Edition of JDeveloper and that you are in the default role under tools->preferences->roles.

Posted by shay on May 26, 2011 at 10:13 AM PDT #

I did it. Thanks shay:)

Posted by melih on May 27, 2011 at 12:33 AM PDT #

Thanks Shay for this great demo.
i have question, i want to use java class as model layer and JSF as presentation layer (it is very important to use JSF tags not ADF tags)
I successfully made simple application with methods return String values but I need to use method return List to use it to fill JSF table (Again JSF table not ADF table), I can't use drag and drop cause it generate ADF tags, I need ur help

Posted by Belal on July 04, 2011 at 04:20 PM PDT #

Belal,
The drag and drop binding is provided by ADF both for ADF Faces and the Trinidad components see example here: http://blogs.oracle.com/shay/2009/02/using_trinidad_in_jdeveloper_1.html
So if you can't use ADF Faces Trinidad is your option.
If you can't use Trinidad either - then you'll need to use regular JSF binding by createing managed beans to hold your data.

As a side note,
Why can't you use ADF Faces? Is it because of licensing issues? if so note that using ADF Binding has the same license as ADF Faces - so you probably can't use that either.

Posted by Shay on July 05, 2011 at 08:53 AM PDT #

thanks for ur answer Shay,
I have another problem (I am newbie) and I need your help
in my application all users and roles must be created from the application, not form jdeveloper ,weblogic console or Active Directory.
each created user will be assigned to
- user name and password from Active Directory to authentication operation
- group created in the application and has no relation with AD groups for Authorization operation
in English: username and password from AD, groups and permissions from the application
what I have to use, and if there any example will be great
thanks

Posted by belal on July 18, 2011 at 04:26 PM PDT #

I am trying the input file and backing bean, for read/write the reader fails; would you please provide the code snippet and relevant printscreen

Posted by guest on September 14, 2011 at 03:56 PM PDT #

guest - I added a link to the actual JDeveloper workspace that you can download and try -
http://blogs.oracle.com/shay/resource/FileReadWrite.zip

Posted by Shay on September 15, 2011 at 08:06 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