Wednesday, September 7, 2016

ADF : Export only some columns to excel by exportCollectionActionListener using setPropertyListener tag

Exporting only some columns in excel by exportCollectionActionListener

In some use cases you might want export only some columns to excel , for these find of use cases you can use setPropertyListener tag


update column visible proper



Text wrap for ADF Input text

Wrapping word when long text is entered in inputText tag

I have a inputText tag as below




When some long text is entered horizontal scroll bar appears.



If you want to achieve word wrap and avoid horizontal scroll bar on a input text with long text, you can add inline style tag to input like below text .

inlineStyle="white-space: pre-wrap; word-wrap:break-word; display:inline-block;"




Tuesday, September 6, 2016

Invoking Application module method as default activity with return parameter from bean

Sometimes when task flow is initialized before loading page/fragment we need to execute Application Module method which returns parameter to manipulate some logic. 

Shown below is one way to achieve this kind of use case .

  1. Have a method in AMImpl which returns parameter , here Map is returned .
  2. Drag and drop the AM method on task flow , which creates binding in DataBinding.cpx


DataBinding.cpx will have a page map and page definition usages

<page path="/Sample-TF.xml#Sample-TF@employeeAMMethod"                         usageId="view_Sample_TF_Sample_TF_employeeAMMethodPageDef"/>

<page id="view_Sample_TF_Sample_TF_employeeAMMethodPageDef"

   path="view.pageDefs.Sample_TF_Sample_TF_employeeAMMethodPageDef"/>

Now implement a bean method activity on task flow , below i have execute AMImpl method ,result is returned and setting to bean variable which i will be showing as output text in fragment.


            //Get the current binding context
        BindingContext binding = BindingContext.getCurrent();

        //Find our binding container by name (page id in the DataBindings.cpx)
        DCBindingContainer dcBinding =
            binding.findBindingContainer("view_Sample_TF_Sample_TF_employeeAMMethodPageDef");
        //Execute the method
        OperationBinding operation = dcBinding.getOperationBinding("employeeAMMethod");
        operation.execute();





Output on fragment 



Happy Learning !!!

Friday, September 2, 2016

Creating Document Template Sample using Docx4j and OpenDoPE in ADF Application

Sample Document Template generation using Docx4j

Docx4j is an open source (ASLv2) Java library for creating and manipulating Microsoft Open XML (Word docx, Powerpoint pptx, and Excel xlsx) files. 
Download Docx4j and dependices here Jar's and add them in Libraries and Classpath



Download OpenDoPE Microsoft word extension and run extension.You should OpenDoPE extension on Microsoft as below



Save the Template you want to create first . Click on 'Bind this text' for the text you wanted to generate dynamically.


Click Bind this.. on the extension panel 


Then it should open a XML text editor, paste the XML .which we will be generate using JAXBMarshalling



Select the XML element to Bind with , enter a unique XPath ID and Click Use this XPath



Repeat same for other elements also and template should look like below

Drag and drop EmployeeVO as a form , create a button , Action Listener for that button and change text to 'Create Template' .

Below is code snippet for ActionListener , which gets current row from EmployeesVO and set's Person Object with First Name, Last Name, Email and Phone. Using JAXBMarshalling current row is converted into XML String .



Below snippet code is for binding template with XML String


Finally,After generating Word document will replace the text with dynamic data.




Happy Learning!!!

Creating an Object to XML and XML to Object to using JAXB marshalling

JAXB stands for Java Architecture for XML Binding, using JAXB annotation to convert Java object to / from XML file

Create a Person Object for this object to convert to / from XML , we should annotate with JAXB annotation .Root element/Class with @XmlRootElement and @XmlElement for variables.


Using below snippet code we can create a file from Object to XML ,using JAXBMarshaller

        Person person = new Person();
        person.setFirstName("Steven");
        person.setLastName("Kinggfdgdf);
        person.setPhone("515.123.4567);
        person.setEmail("SKING);

        try {
            File file = new File("C:\\file.xml");
            JAXBContext jaxbContext = JAXBContext.newInstance(Person.class);
            Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

            // output pretty printed
            jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

            jaxbMarshaller.marshal(person, file);
        } catch (PropertyException pe) {
            pe.printStackTrace();
        } catch (JAXBException jaxbe) {
            jaxbe.printStackTrace();
        }

We can also create a String from Object to XML , here we will use java.io.StringWriter 

        Person person = new Person();
        person.setFirstName("Steven");
        person.setLastName("Kinggfdgdf);
        person.setPhone("515.123.4567);
        person.setEmail("SKING);

        try {
            StringWriter sw = new StringWriter();
            JAXBContext jaxbContext = JAXBContext.newInstance(Person.class);
            Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

            // output pretty printed
            jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

            jaxbMarshaller.marshal(person, sw);
            System.out.println(sw.toString());
        } catch (PropertyException pe) {
            pe.printStackTrace();
        } catch (JAXBException jaxbe) {
            jaxbe.printStackTrace();
        }

Output




Below snippet code is to create a Object from XML using JAXBUnmarshaller

            File file = new File("C:\\file.xml");
            JAXBContext jaxbContext = JAXBContext.newInstance(Person.class);

            Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
            Person person = (Person)jaxbUnmarshaller.unmarshal(file);
            System.out.println(person);

Output

Person [email=SKING, firstName=Steven, lastName=Kinggfdgdf, phone = 515.123.4567]


JDeveloper: 11.1.2.4 - Unable to Print all pages in IE11 , prints only first page instead the all pages.

We came across a use case where we had to print content in JSF page and in IE it was printing only first page but works as expected in FireFox.

Below work around had fixed our issue:

If possible, upgrade to the latest  version of ADF. For IE 9 support, use the latest version of 11.1.1.x or 11.1.2.x, as appropriate. For IE 10,11 support, an upgrade to 12.1.2 or later is required.

If this is not possible, a potential workaround is to add one pixel of vertical space to the top of the JSF/JSPX page containing the table. For example:
<af:document title="test.jspx" id="d1" inlineStyle="padding:1px 0px 0px 0px;">

In most cases this spacing is hardly visible, and it appears to solve the problem for IE versions up to and including 10&11

Alternatively Issue can be addressed by setting the following CSS selector

@agent ie and (version: 9.0) and (version: 10.0)and and (version: 11.0) {
  af|document:printable {
  padding-top: 1px;
  }
 }

@agent ie and (version: 9.0) and (version: 10.0) and (version: 11.0){
  af|document:maximized:printable {
  padding-top: 1px;
}
}

JDev :11.1.2.4 - "Page can't be displayed" when using TaskFlow as Run as Dialog Popup


In couple use cases we had to use TaskFlow behavior as 'Run as Dialog' and we used to get "Page can't be displayed" first time when we try to access TaskFlow .It works fine after that .


Adding Below context-param in web.xml has fixed our issue.

    <context-param>
        <param-name>oracle.adf.view.rich.prettyUrl.OPTIONS</param-name>
        <param-value>off</param-value>
    </context-param>