How to check ifdirty (is modified) for View Object?

Requirement – Checking if data modified in viewobject ADF

Solution-You can use isDirty() method provided by API to get status

 DCBindingContainer bind =(DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
        JUCtrlHierBinding object = (JUCtrlHierBinding)bind.findCtrlBinding("DepartmentVO1"); // or get ViewObject form Iterator in ADFUtils.
        ViewObject deptVo = object.getViewObject(); 
        Boolean b = deptVo.getApplicationModule().getTransaction().isDirty();This gives Boolean value of True/False. 

another way

DCBindingContainer dcBindingContainer=(DCBindingContainer)
BindingContext.getCurrent().getCurrentBindingsEntry();
if(dcBindingContainer.getDataControl().isTransactionModified()){
//Code goes here...
}

few more use case i found on internet i.e http://oracleadfhowto.blogspot.de/2012/03/iterator-uncommitted-data-availability.html, so thought of sharing that as well –

1. If you are using iterator based UI component like table:
Expression #{row.row.entities[0].entityState} will return state viz. (0 – New, Modified – 2, Unmodified – 1, Initialized – -1 where row refers to the table node and row.row is the instance of row in the iterator/table.

The following expression also notify that there is dirty data available –

-> #{!bindings.EmployeesView1Iterator.dataControl.TransactionDirty}   // this statment will notify that there is uncommitted or unsaved data in the iterator
-> #{!bindings.Commit.enabled}
-> #{!controllerContext.currentRootViewPort.dataDirty}
-> #{!controllerContext.currentViewPort.dataDirty} 

Happy ADF learning with Vinay in techartifact….

How to Read/convert an InputStream to a String

There are multiple ways .I will list down few of them.

Using Old and standard java solution –

public static String fromStream(InputStream in) throws IOException
{
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    StringBuilder out = new StringBuilder();
    String line;
    while ((line = reader.readLine()) != null) {
        out.append(line);
    }
    return out.toString();
}

return sb.toString();

if you using Google-Collections/Guava-

InputStream stream = ...
String content = CharStreams.toString(new InputStreamReader(stream, Charsets.UTF_8));
Closeables.closeQuietly(stream);

If you can use Apache Common library..then this is useful –

StringWriter writer = new StringWriter();
IOUtils.copy(inputStream, writer, encoding);
String theString = writer.toString();

Quick way but only work in deserialization process –

String result = (String)new ObjectInputStream( inputStream ).readObject();

Note:ObjectInputStream is about deserialization, and the stream have to respect the serialization protocol to work, which may not always true in all cases.

In the end, the most efficient solution and only in two lines using java Scanner class –

Tricky is to remember the regex \A, which matches the beginning of input. This effectively tells Scanner to tokenize the entire stream, from beginning to (illogical) next beginning.

public static String convertToString(InputStream in) {
    java.util.Scanner s = new java.util.Scanner(in).useDelimiter("\\A");  
        
    return s.hasNext() ? s.next() : "";
}

I would love to hear any comment by you for making more simple…

Happy learning by Vinay Kumar in techartifact

Book Review: Developing Web Applications with Oracle ADF Essentials

The folks at Packt asked me to review one of their book on Developing Web Applications with Oracle ADF Essentials of stenvesterli .If you are interested in buying it .
You can get it from

Amazon site
packt site

Book cover

This book contains 8 chapter –

Chapter 1. My First ADF Essentials Application
– How to install MySql,JDK, Glassfish.
– How you can setup jdev and ADF essential.

Chapter 2. Creating Business Services
– Give depth knowledge of ADF BC
– Creating sample application in ADF BC and testing.

Chapter 3. Creating Task Flows and Pages
– How you can create pages
– How to work in taskflow. Explanation of task flow.I really liked.

Chapter 4. Adding Business Logic
– Adding custom login in BC classes
– Adding logic to UI
– Sample application

Chapter 5. Building Enterprise Applications
– How to structure your code ,Using sub version.
– How to create libraries in ADF
– Creating sample application and use these features
Chapter 6. Debugging ADF Applications
– How to use ADF logging.
– How to do logging in Glassfish
– How you can do debugging in Jdeveloper
Chapter 7. Securing an ADF Essentials Application
– Most interesting chapter for me.Clearly explained APache shiro .
– Advanced features of Apache shiro.
– Implementation Authorization
Chapter 8. Build and Deploy
– Another interesting topic.How you can build Application
– creating script and deploying in glassfish.
– Advanced topoc for preparing application for go live.

Summary:
Good and detailed explanation of ADF essentials what are limitations and how to overcome on it. This book not only cover ADF essentail but whole ADF except ADF security.
Very usefull if you want to run your app on glassfish,Jboss or tomcat.Creatomg build script for ADF developer is really usefull. Someone who starting ADF learning, i would really recommend for him

Happy learning with Vinay in techartifact….