Tuesday, October 22, 2013

Uploading Large Files from ADF 11g Applications

In ADF upload component if we want to increase upload file size we have to keep below code in web.xml.

<context-param>
    <param-name>org.apache.myfaces.trinidad.UPLOAD_MAX_DISK_SPACE</param-name>
    <param-value>20971520</param-value>
  </context-param>

if we set adf instead of apache that use to throw "The file could not be uploaded because it is too large" error on upload component.


Monday, October 14, 2013

Disable or Enable Button/InputText in ADF by using Javascript

Disabling ADF Faces UI component on the client-side could be tricky sometimes.You basically need to set unsecure="disabled" and clientComponent="true". But if you use button.setProperty('disabled', true) on a commandButton, your button will still look like undisabled (though it won't invoke action event), proper style class and 'disabled' attribute will not be applied to the button element.
To properly disable button you can use script like this: 


<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  <jsp:directive.page contentType="text/html;charset=UTF-8"/>
  <f:view>
    <af:document id="d1">
      <af:resource type="javascript"> 

      function disableField(actionEvent) { 
  
        var nameInputText = actionEvent.getSource().findComponent("nameFld"); 
        nameInputText.setProperty("disabled", true); 
         
        //The following line is for partial refresh, in this case  
        //its taken care by framework 
        //AdfPage.PAGE.addPartialTargets(nameInputText); 
         
       
      } 
  
      function enableField(actionEvent) { 
  
        var nameInputText = actionEvent.getSource().findComponent("nameFld"); 
        nameInputText.setProperty("disabled", false); 
       
      } 
      function setButtonDisabled(actionEvent) {
        var button = actionEvent.getSource().findComponent("submitButton"); 
            button.setProperty('disabled', true);
            AdfDomUtils.addOrRemoveCSSClassName(true,
                AdfRichUIPeer.getDomElementForComponent(button),
                AdfRichUIPeer.DISABLED_STYLECLASS);
            var buttonDom = button.getPeer().getButtonElement(button);
           
                buttonDom.setAttribute('disabled', 'disabled');
                  
        }
   
   
      function setButtonEnabled(actionEvent) {
        var button = actionEvent.getSource().findComponent("submitButton"); 
            button.setProperty('disabled', false);
            AdfDomUtils.addOrRemoveCSSClassName(false,
                AdfRichUIPeer.getDomElementForComponent(button),
                AdfRichUIPeer.DISABLED_STYLECLASS);
            var buttonDom = button.getPeer().getButtonElement(button);
           
           
                buttonDom.removeAttribute('disabled');
                  
        }
   
   
     </af:resource> 
     <af:form id="f1"> 
       <af:panelGroupLayout id="pgl1"> 
         <af:commandButton text="Disable Name Field" id="disableBtn" clientComponent="true" unsecure="disabled"
                  > 
       <af:clientListener type="action" method="setButtonDisabled"/>     
         </af:commandButton> 
         <af:commandButton text="Enable Name Field" id="enableBtn" clientComponent="true" unsecure="disabled"
                  > 
           <af:clientListener type="action" method="setButtonEnabled"/> 
         </af:commandButton> 
      
       <af:inputText unsecure="disabled" clientComponent="true" label="Name" id="nameFld"/> 
       <af:commandButton disabled="true" text="Submit" id="submitButton" clientComponent="true" unsecure="disabled">
      
       </af:commandButton>
     </af:panelGroupLayout> 
     </af:form> 

    </af:document>
  </f:view>
</jsp:root>



unsecure:

 A whitespace separated list of attributes whose values ordinarily can be set only on the server, but need to be settable on the client. Currently, this is supported only for the "disabled" attribute. Note that when you are able to set a property on the client, you will be allowed to by using the the .setProperty('attribute', newValue) method, but not the .setXXXAttribute(newValue) method. For example, if you have unsecure="disabled", then on the client you can use the method .setProperty('disabled', false), while the method .setDisabled(false) will not work and will provide a javascript error that setDisabled is not a function.

clientComponent:

 whether a client-side component will be generated. A component may be generated whether or not this flag is set, but if client Javascript requires the component object, this must be set to true to guarantee the component's presence. Client component objects that are generated today by default may not be present in the future; setting this flag is the only way to guarantee a component's presence, and clients cannot rely on implicit behavior. However, there is a performance cost to setting this flag, so clients should avoid turning on client components unless absolutely necessary.

Friday, October 11, 2013

Reading Weather data from xml

      
 Reading Weather data from xml
    try {

                String url = "http://weather.yahooapis.com/forecastrss?w=2442047&u=f";
        System.out.println("::::Weather URL::::"+url);
              
                SAXParserFactory factory = SAXParserFactory.newInstance();
                SAXParser saxParser = factory.newSAXParser();

                DefaultHandler handler = new DefaultHandler() {
                    boolean flag;
                    public void startElement(String uri, String localName,
                                             String qName,
                                             org.xml.sax.Attributes attributes) throws SAXException {
                      
                        try {
                            // _logger.info("Start Element :" + qName);
                           
                            if (qName.equalsIgnoreCase("latitude")) {
                                flag=true;
                            }
                            if (qName.equalsIgnoreCase("description")) {
                                System.out.println(":::::::Start::::::Weather Condition:::::::::");
                                flag=true;
                            }
                            if (qName.equalsIgnoreCase("yweather:condition")) {
                                System.out.println(":::::::Start::::::Weather Condition:::::::::");
                                System.out.println(":::text:"+attributes.getValue("text"));
                                System.out.println(":::temp:"+attributes.getValue("temp"));
                                System.out.println(":::date:"+attributes.getValue("date"));
                                System.out.println(":::::::End::::::Weather Condition:::::::::");
                            }

                            if (qName.equals("yweather:forecast")) {
                                System.out.println(":::::::Start::::::Weather Forecast:::::::::");
                                System.out.println("Code:" + attributes.getValue("day"));
                                System.out.println(":::date:"+attributes.getValue("date"));
                                System.out.println(":::low:"+attributes.getValue("low"));
                                System.out.println(":::high:"+attributes.getValue("high"));
                                System.out.println(":::text:"+attributes.getValue("text"));
                                System.out.println(":::::::End::::::Weather Forecast:::::::::");
                            }
                           
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        System.out.println("::::::END Processes::::::;:::");
                    }


                    //                        public void endElement(String uri, String localName,
                    //                                        String qName) throws SAXException {
                    //                        }

                    public void characters(char[] ch, int start,
                                           int length) throws SAXException {
                    if(flag){
                        String s=new String(ch, start, length);
                           
                        System.out.println(":::new String(ch, start, length):::"+s.split("<br />")[0]);
                       
                    flag=false;
                    }
                    }

                };
                System.out.println("::::::::::::::::::::::::::::::::::::::::::::");

                saxParser.parse(url, handler);
                System.out.println(":::::::::::::::::::::::::::");
            } catch (Exception e) {
                e.printStackTrace();
            }


Adding Images to jspx page
<f:verbatim>
                <input type="image"
                       src="http://l.yimg.com/a/i/us/we/52/33.gif"/>
              </f:verbatim>
              <af:image source="http://l.yimg.com/a/i/us/we/52/26.gif" id="i1"/>
              <![CDATA[
<img src="http://l.yimg.com/a/i/us/we/52/33.gif"/>]]>
            </af:group>
           
         
      

Thursday, October 10, 2013

Setting Multiple Java Options or Time Zone in Jdeveloper

1) We can set multiple java options in Jdeveloper
     I. Goto the Project properties of Model or ViewController
    II.Go to Run/Debug/Profile on the Left Pane.
   III.If you are using Project Settings Click on Edit by selecting your Profile most of the cases it is  
         Default.
   IV.Select Launch Settings on the left pane and in Java option enter this value Note: you can  
        change according to your options by giving space between multiple java parameters . 

                            -Duser.timezone="+05:30" -Doracle.adfm.usemds=true
2) Error :oracle.jbo.JboException: JBO-29000: Unexpected exception caught:
               java.sql.SQLDataException, msg=ORA-01882: timezone region not found

    Solution : Set time zone in java options -Duser.timezone="+05:30"
                      This time zone is for India, you can set which ever time zone required.