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
    XMLInterface.XML_OPT_ALL_ROWS
    Includes all rows in the view object's row set in the XML.

    XMLInterface.XML_OPT_LIMIT_RANGE
    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);
                System.out.println(opStream);
                // Creating a XML document in D Drive
                out = new FileOutputStream("D://Departments.xml");
                out.close();
    
            } catch (Exception e) {
                System.out.println(e.getMessage());
            }
    
            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(AttributeDefImpl.java:2435)
     at oracle.jbo.server.ViewRowImpl.populate(ViewRowImpl.java:3842)
     at oracle.jbo.server.ViewDefImpl.createInstanceFromResultSet(ViewDefImpl.java:2387)
     at oracle.jbo.server.ViewObjectImpl.createRowFromResultSet(ViewObjectImpl.java:6030)
     at oracle.jbo.server.ViewObjectImpl.createInstanceFromResultSet(ViewObjectImpl.java:5861)
     at oracle.jbo.server.QueryCollection.populateRow(QueryCollection.java:3612)
     at oracle.jbo.server.QueryCollection.fetch(QueryCollection.java:3467)
     at oracle.jbo.server.QueryCollection.get(QueryCollection.java:2184)
     at oracle.jbo.server.ViewRowSetImpl.getRow(ViewRowSetImpl.java:5125)
     at oracle.jbo.server.ViewRowSetIteratorImpl.doFetch(ViewRowSetIteratorImpl.java:2936)
     at oracle.jbo.server.ViewRowSetIteratorImpl.ensureRefreshed(ViewRowSetIteratorImpl.java:2792)
     at oracle.jbo.server.ViewRowSetIteratorImpl.refresh(ViewRowSetIteratorImpl.java:3033)
     at oracle.jbo.server.ViewRowSetImpl.notifyRefresh(ViewRowSetImpl.java:2797)
     at oracle.jbo.server.ViewRowSetImpl.execute(ViewRowSetImpl.java:1255)
     at oracle.jbo.server.ViewRowSetImpl.executeQueryForMasters(ViewRowSetImpl.java:1413)
     at oracle.jbo.server.ViewRowSetImpl.executeQueryForMode(ViewRowSetImpl.java:1319)
     at oracle.jbo.server.ViewRowSetImpl.executeQuery(ViewRowSetImpl.java:1304)
     at oracle.jbo.server.ViewObjectImpl.executeQuery(ViewObjectImpl.java:7119)
     at oracle.adf.model.bc4j.DCJboDataControl.executeIteratorBindingIfNeeded(DCJboDataControl.java:1366)
     at oracle.adf.model.binding.DCIteratorBinding.executeQueryIfNeeded(DCIteratorBinding.java:2219)
     at oracle.jbo.uicli.binding.JUCtrlHierBinding.getRootNodeBinding(JUCtrlHierBinding.java:92)
     at oracle.adfinternal.view.faces.model.binding.FacesCtrlHierBinding$HierCurrencyRowKeySet.getRowIterator(FacesCtrlHierBinding.java:1421)
     at oracle.adfinternal.view.faces.model.binding.CurrencyRowKeySet.size(CurrencyRowKeySet.java:34)
     at org.apache.myfaces.trinidad.model.RowKeySet.getSize(RowKeySet.java:152)
     at oracle.adfinternal.view.faces.renderkit.rich.TableRendererUtils.writePojoSelectionState(TableRendererUtils.java:455)
     at oracle.adfinternal.view.faces.renderkit.rich.TableRenderer.renderDataBlockRows(TableRenderer.java:2562)
     at oracle.adfinternal.view.faces.renderkit.rich.TableRenderer.encodeAll(TableRenderer.java:685)
     at oracle.adf.view.rich.render.RichRenderer.encodeAll(RichRenderer.java:1452)
     at org.apache.myfaces.trinidad.render.CoreRenderer.encodeEnd(CoreRenderer.java:511)
     at org.apache.myfaces.trinidad.component.UIXComponentBase.encodeEnd(UIXComponentBase.java:923)
     at org.apache.myfaces.trinidad.component.UIXCollection.encodeEnd(UIXCollection.java:617)
     at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1659)
     at org.apache.myfaces.trinidad.render.CoreRenderer.encodeChild(CoreRenderer.java:624)
     at oracle.adf.view.rich.render.RichRenderer.encodeChild(RichRenderer.java:3201)
     at org.apache.myfaces.trinidad.render.CoreRenderer.encodeAllChildren(CoreRenderer.java:641)
     at oracle.adf.view.rich.render.RichRenderer.encodeAllChildrenInContext(RichRenderer.java:3062)
     at oracle.adfinternal.view.faces.renderkit.rich.FormRenderer.encodeAll(FormRenderer.java:274)
     at oracle.adf.view.rich.render.RichRenderer.encodeAll(RichRenderer.java:1452)
     at org.apache.myfaces.trinidad.render.CoreRenderer.encodeEnd(CoreRenderer.java:511)
     at org.apache.myfaces.trinidad.component.UIXComponentBase.encodeEnd(UIXComponentBase.java:923)
     at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1659)
     at org.apache.myfaces.trinidad.render.CoreRenderer.encodeChild(CoreRenderer.java:624)
     at oracle.adf.view.rich.render.RichRenderer.encodeChild(RichRenderer.java:3201)
     at org.apache.myfaces.trinidad.render.CoreRenderer.encodeAllChildren(CoreRenderer.java:641)
     at oracle.adf.view.rich.render.RichRenderer.encodeAllChildrenInContext(RichRenderer.java:3062)
     at oracle.adfinternal.view.faces.renderkit.rich.DocumentRenderer.encodeAll(DocumentRenderer.java:1277)
     at oracle.adf.view.rich.render.RichRenderer.encodeAll(RichRenderer.java:1452)
     at org.apache.myfaces.trinidad.render.CoreRenderer.encodeEnd(CoreRenderer.java:511)
     at org.apache.myfaces.trinidad.component.UIXComponentBase.encodeEnd(UIXComponentBase.java:923)
     at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1659)
     at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1655)
     at oracle.adfinternal.view.faces.component.AdfViewRoot.encodeAll(AdfViewRoot.java:91)
     at com.sun.faces.application.view.JspViewHandlingStrategy.doRenderView(JspViewHandlingStrategy.java:431)
     at com.sun.faces.application.view.JspViewHandlingStrategy.renderView(JspViewHandlingStrategy.java:233)
     at org.apache.myfaces.trinidadinternal.application.ViewDeclarationLanguageFactoryImpl$ChangeApplyingVDLWrapper.renderView(ViewDeclarationLanguageFactoryImpl.java:350)
     at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
     at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:273)
     at org.apache.myfaces.trinidadinternal.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:165)
     at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._renderResponse(LifecycleImpl.java:1027)
     at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._executePhase(LifecycleImpl.java:334)
     at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:232)
     at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
     at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
     at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
     at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
     at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
     at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
     at oracle.adf.model.servlet.ADFBindingFilter.doFilter(ADFBindingFilter.java:173)
     at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
     at oracle.adfinternal.view.faces.webapp.rich.RegistrationFilter.doFilter(RegistrationFilter.java:122)
     at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:468)
     at oracle.adfinternal.view.faces.activedata.AdsFilter.doFilter(AdsFilter.java:60)
     at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:468)
     at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._doFilterImpl(TrinidadFilterImpl.java:293)
     at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilter(TrinidadFilterImpl.java:199)
     at org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(TrinidadFilter.java:92)
     at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
     at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:111)
     at java.security.AccessController.doPrivileged(Native Method)
     at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:313)
     at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:413)
     at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:94)
     at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:161)
     at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71)
     at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
     at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:136)
     at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
     at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
     at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
     at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3715)
     at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681)
     at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
     at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
     at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277)
     at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)
     at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)
     at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
     at weblogic.work.ExecuteThread.run(ExecuteThread.java:178)
    Caused by: java.sql.SQLException: Invalid column index
     at oracle.jdbc.driver.OracleResultSetImpl.getString(OracleResultSetImpl.java:2824)
     at weblogic.jdbc.wrapper.ResultSet_oracle_jdbc_driver_OracleResultSetImpl.getString(Unknown Source)
     at oracle.jbo.common.StringTypeSQLNativeImpl.getDataFromResultSet(JboTypeMapEntries.java:509)
     at oracle.jbo.server.AttributeDefImpl.loadFromResultSet(AttributeDefImpl.java:2426)
     ... 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