Please disable your adblock and script blockers to view this page

Search this blog

Showing posts with label XML. Show all posts
Showing posts with label XML. Show all posts

Sunday 5 February 2017

Change live application language/resource in Oracle ADF, Change XML Resource file at runtime

Hello All

I have posted about using external XML file as List resource bundle earlier , the aim of resource file is to read application static text from some source so that we can change that without compiling and redeploying application

Next requirement is to change application language , sometimes we need support multiple langauge in ADF application and it requires change in all static text so for this I am going to use separate XML resource file for different language and in this post I'll show that how to update resource file in a live running application

Monday 23 January 2017

Using external XML file as list resource bundle in ADF Application

Hello All

In this post I am talking about using external XML file as list resource bundle in ADF Application

Using this approach we need not to hard code component's label and messages , all labels and messages will be read from XML file and no need to open application to change any resource , In short we can update resources without compiling and redeploying application

Tuesday 10 June 2014

Export ViewObject dataset to XML, Generate customized XML file using ViewObject in Oracle ADF

Hello All,
this post is about exporting a viewObject data to a XML document.
Sometimes we need to generate XML document with the same data in ViewObject, for this ADF provides a facility to directly export data to a XML document using ViewObjectImpl class

See the steps to generate XML for a ViewObject

  • Create a Fusion Web application and model using HR schema (Departments & Employees) table (master detail relation using viewLink)

  • Now to generate XML, i have used writeXML method of ViewObjectImpl class, it produce XML using two parameters

  • from oracle docs-
    writeXML(int depthCount, long options)
    here depthCount - no. of ViewLink levels that should be traversed to produce XML
    options- how many rows you want to export, It can be set any of flags given below
    Includes all rows in the view object's row set in the XML.

    Includes only the rows in the current range in the XML.

  • created a method in DepartmentsVOImpl class to export data to XML, added it to client Interface

  •     /**Method to generate XML from ViewObject data
         * @param level
         * @return
        public String writeVoToXml(int level) {
            FileOutputStream out;
            ByteArrayOutputStream opStream = new ByteArrayOutputStream();
            try {
                // Generating XML for All rows and adding it to Output Stream
                ((XMLNode) this.writeXML(level, XMLInterface.XML_OPT_ALL_ROWS)).print(opStream);
                // Creating a XML document in D Drive
                out = new FileOutputStream("D://Departments.xml");
            } catch (Exception e) {
            return opStream.toString();

  • Now run application module to execute method and see generated XML on console

  • BC4J Tester

    ViewObject XML

  • i have created a simple page with a af:codeEditor to show generated XML , button to generate XML and a spinner to pass depth level of viewLink accessor

  • In case depth level is '0' , it export data only for Departments viewObject

    Change level to '1' , Now it generate XML for Departments --> Employess relation

  • now to how to customize XML ? How to change default tags for attribute names and rows ?
  • To change attribute label (tag in xml)- Suppose i have to change DepartmentName to Name in XML
  • Add attribute level custom property named XML_ELEMENT to a value AnyOtherName to change the XML element name used for that attribute

  • To change Row label (tag in xml)- Suppose i have to change DepartmentsVORow to DepartmentLine in XML
  • Add ViewObject level custom property named XML_ROW_ELEMENT to a value AnyOtherName to change the XML element name used for that Row

  • Now Run and see generated XML -
Cheers :-) Happy Learning

Thursday 18 July 2013

JBO-27022-Failed to load value at index 'n' , java.sql.SQLException: Invalid column index in Oracle ADF

'Invalid column index' is the error occurs due to SQL Exception in ADF Faces.
and main reason behind this is mismatch between ViewObject's query and Attributes.
 suppose i have an application with default HR Schema and Employees Table.

  • See the query and attribute list of Employees ViewObject , when there is no mismatch between attributes and query
and query is -

  • Now i have removed a attribute from ViewObject query, then mismatch between VO Query and attribute list tends towards sql exception "Invalid Column Index"

 Query is- (First_Name is not there)

  •  Now when you try to run application, this error occurs, "Failed to load value at index n - java.sql.SQLException Invalid column index"- see error log 

  • oracle.jbo.AttributeLoadException: JBO-27022: Failed to load value at index 11 with java object of type java.lang.String due to java.sql.SQLException.
     at oracle.jbo.server.AttributeDefImpl.loadFromResultSet(
     at oracle.jbo.server.ViewRowImpl.populate(
     at oracle.jbo.server.ViewDefImpl.createInstanceFromResultSet(
     at oracle.jbo.server.ViewObjectImpl.createRowFromResultSet(
     at oracle.jbo.server.ViewObjectImpl.createInstanceFromResultSet(
     at oracle.jbo.server.QueryCollection.populateRow(
     at oracle.jbo.server.QueryCollection.fetch(
     at oracle.jbo.server.QueryCollection.get(
     at oracle.jbo.server.ViewRowSetImpl.getRow(
     at oracle.jbo.server.ViewRowSetIteratorImpl.doFetch(
     at oracle.jbo.server.ViewRowSetIteratorImpl.ensureRefreshed(
     at oracle.jbo.server.ViewRowSetIteratorImpl.refresh(
     at oracle.jbo.server.ViewRowSetImpl.notifyRefresh(
     at oracle.jbo.server.ViewRowSetImpl.execute(
     at oracle.jbo.server.ViewRowSetImpl.executeQueryForMasters(
     at oracle.jbo.server.ViewRowSetImpl.executeQueryForMode(
     at oracle.jbo.server.ViewRowSetImpl.executeQuery(
     at oracle.jbo.server.ViewObjectImpl.executeQuery(
     at oracle.adf.model.bc4j.DCJboDataControl.executeIteratorBindingIfNeeded(
     at oracle.adf.model.binding.DCIteratorBinding.executeQueryIfNeeded(
     at oracle.jbo.uicli.binding.JUCtrlHierBinding.getRootNodeBinding(
     at oracle.adfinternal.view.faces.model.binding.FacesCtrlHierBinding$HierCurrencyRowKeySet.getRowIterator(
     at oracle.adfinternal.view.faces.model.binding.CurrencyRowKeySet.size(
     at org.apache.myfaces.trinidad.model.RowKeySet.getSize(
     at org.apache.myfaces.trinidad.render.CoreRenderer.encodeEnd(
     at org.apache.myfaces.trinidad.component.UIXComponentBase.encodeEnd(
     at org.apache.myfaces.trinidad.component.UIXCollection.encodeEnd(
     at javax.faces.component.UIComponent.encodeAll(
     at org.apache.myfaces.trinidad.render.CoreRenderer.encodeChild(
     at org.apache.myfaces.trinidad.render.CoreRenderer.encodeAllChildren(
     at org.apache.myfaces.trinidad.render.CoreRenderer.encodeEnd(
     at org.apache.myfaces.trinidad.component.UIXComponentBase.encodeEnd(
     at javax.faces.component.UIComponent.encodeAll(
     at org.apache.myfaces.trinidad.render.CoreRenderer.encodeChild(
     at org.apache.myfaces.trinidad.render.CoreRenderer.encodeAllChildren(
     at org.apache.myfaces.trinidad.render.CoreRenderer.encodeEnd(
     at org.apache.myfaces.trinidad.component.UIXComponentBase.encodeEnd(
     at javax.faces.component.UIComponent.encodeAll(
     at javax.faces.component.UIComponent.encodeAll(
     at oracle.adfinternal.view.faces.component.AdfViewRoot.encodeAll(
     at com.sun.faces.application.view.JspViewHandlingStrategy.doRenderView(
     at com.sun.faces.application.view.JspViewHandlingStrategy.renderView(
     at org.apache.myfaces.trinidadinternal.application.ViewDeclarationLanguageFactoryImpl$ChangeApplyingVDLWrapper.renderView(
     at com.sun.faces.application.view.MultiViewHandler.renderView(
     at javax.faces.application.ViewHandlerWrapper.renderView(
     at org.apache.myfaces.trinidadinternal.application.ViewHandlerImpl.renderView(
     at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._renderResponse(
     at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._executePhase(
     at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.render(
     at javax.faces.webapp.FacesServlet.service(
     at weblogic.servlet.internal.StubSecurityHelper$
     at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(
     at weblogic.servlet.internal.ServletStubImpl.execute(
     at weblogic.servlet.internal.TailFilter.doFilter(
     at weblogic.servlet.internal.FilterChainImpl.doFilter(
     at oracle.adf.model.servlet.ADFBindingFilter.doFilter(
     at weblogic.servlet.internal.FilterChainImpl.doFilter(
     at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(
     at oracle.adfinternal.view.faces.activedata.AdsFilter.doFilter(
     at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(
     at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._doFilterImpl(
     at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilter(
     at org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(
     at weblogic.servlet.internal.FilterChainImpl.doFilter(
     at Method)
     at weblogic.servlet.internal.FilterChainImpl.doFilter(
     at oracle.dms.servlet.DMSServletFilter.doFilter(
     at weblogic.servlet.internal.FilterChainImpl.doFilter(
     at weblogic.servlet.internal.RequestEventsFilter.doFilter(
     at weblogic.servlet.internal.FilterChainImpl.doFilter(
     at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(
     at weblogic.servlet.internal.WebAppServletContext$
     at weblogic.servlet.internal.WebAppServletContext.securedExecute(
     at weblogic.servlet.internal.WebAppServletContext.execute(
    Caused by: java.sql.SQLException: Invalid column index
     at oracle.jdbc.driver.OracleResultSetImpl.getString(
     at weblogic.jdbc.wrapper.ResultSet_oracle_jdbc_driver_OracleResultSetImpl.getString(Unknown Source)
     at oracle.jbo.common.StringTypeSQLNativeImpl.getDataFromResultSet(
     at oracle.jbo.server.AttributeDefImpl.loadFromResultSet(
     ... 97 more
    ## Detail 0 ## 
  • So when you see this type of log , first check your viewObjects and their query.
  • Always match attribute order in query of view object and in XML source, if there is mismatch in order, it may result in  great problem or data mistake
        See here is difference in order of attribute of vo and query- (Last_Name and Email)

  • In this case of mismatch in order, two things may happen-
  • First one- if Data type of mismatched attributes matches (as Last_Name and Email both are Var char) then value in both fields will be set in VO otherwise it will throw an exception.
  • See this scenario in given snap- Only due to wrong ordering ,value of Last_Name and Email got replaced

  • And if you have Impl classes for your Entity Object or View Object then also check indexing in  classes ,query and  XML source.
  • Invalid Column Index may also occur due to pl/sql (database) function call, always check it and its parameter indexing

Wednesday 31 October 2012

Passing parameter in XML Resource and Use it in Managed Bean, Using parameterised Resource Bundle in ADF

If we are developing an Fusion Web application and we are thinking about Multilingual application , then the best option i came to know is to use Resource Bundle properties of ADF . When we use resource bundle we have to use labels of Fields and Validation message or any kind of other custom message from a XML file as Resource.xml.
So first you should know that how to configure resource bundle in an ADF Application and there are plenty of posts about configuring Properties or List ResourceBundle.

In this post i will show you that how to pass parameter in XML or how to use Parametrized resource .

Suppose i  have a xml file for ResourceBundle reference Resource.xml--

  1. <?xml version="1.0" encoding="windows-1252" ?>
  2. <bundle>
  3. <label>
  4.     <key>MessageCheck</key>
  5.     <value>Only %s %s %s %s %s allowed</value>
  6.  </label>
  7. </bundle>

and now i use it in managed bean to show a custom message and replace its parameters %s with any desired value then we code like this

  1. //To get String from XML key, resolvElDC is a method to resolve expression language
  2. String message = resolvElDC("#{bundle['MessageCheck']}").toString();
  3. //here replace parameter(%s) in string message with your values
  4. String saveMsg = message.format(message, ",", "/", "@", "_", "%");
  5. //Show FacesMessage
  6. FacesMessage msg = new FacesMessage(saveMsg);
  7. msg.setSeverity(FacesMessage.SEVERITY_INFO);
  8. FacesContext ctx = FacesContext.getCurrentInstance();
  9. ctx.addMessage(null, msg);
  10. // Code for resolvElDC method
  11. public Object resolvElDC(String data) {
  12.     FacesContext fc = FacesContext.getCurrentInstance();
  13.     Application app = fc.getApplication();
  14.     ExpressionFactory elFactory = app.getExpressionFactory();
  15.     ELContext elContext = fc.getELContext();
  16.     ValueExpression valueExp = elFactory.createValueExpression(elContext, data, Object.class);
  17.     return valueExp.getValue(elContext);
  18. }

Now run your code and see the updated message- Only %s %s %s %s%s allowed is now
FacesMessage Oracle ADF