Wednesday, May 18, 2016

Javascript HTML - Firefox does not show default selected value on page load

Problem:
I have a web page where user will enter his/her Date of Birth by choosing from the Month, Day and Year List.
Date of Birth Drop Down List

Date of Birth will automatically be saved after clicking the Next button. Which I have verified successful.


When user clicked the back button, page should automatically select the previously entered Date of Birth. My Jquery library is jquery-1.12.3 and my jquery code is this:
 var dobth = $('#dobthOrig').val();  
 var comp = dobth.split('/');  
 var m = parseInt(comp[0], 10) - 1;  
 var d = parseInt(comp[1], 10);  
 var y = parseInt(comp[2], 10);      
 $('select.month option[value='+m+']').attr('selected','true');  
 $('select.day option[value='+d+']').attr('selected','true');  
 $('select.year option[value='+y+']').attr('selected','true');   

However, when user clicked the back button, the Date drop down displayed current date (which is the default date) and not the selected date. I checked thru Dev Tool of Firefox and correct value is selected but display is not.


Selected Day

Selected Month


Solution: 
 autocomplete="off"  
- I searched from forum that code
- But what worked perfectly for me is changing the "attr" attribute to "prop".
 $('select.month option[value='+m+']').prop('selected','selected');  
 $('select.day option[value='+d+']').prop('selected','selected');  
 $('select.year option[value='+y+']').prop('selected','selected');   

Thursday, April 14, 2016

Oracle Statement to extract fields that has numeric value

I have this data where users should input a description of profession. But one day, i found out that there are pure numeric entries. I need to query all record where PROFESSION column has numeric value.

Oracle Statement to extract fields that has numeric value

 SELECT EMPID, NAME, PROFESSION  
 FROM EMPLOYEE  
 WHERE REGEXP_LIKE(PROFESSION, '^[[:digit:]]+$')  

Tuesday, April 12, 2016

Add left and bottom border for iText Cell PDF

Code
So I have this PDF layout that a cell should have both left and bottom border. 
 PdfPCell row26cell_4 = new PdfPCell(row26Par_4);  
 row26cell_4.setBorder(Rectangle.BOTTOM);  
 row26cell_4.setBorder(Rectangle.RIGHT);  
 row26cell_4.setBorderWidth(.9f);  


Solution:
 PdfPCell row26cell_4 = new PdfPCell(row26Par_4);  
 row26cell_4.setBorder(Rectangle.RIGHT | Rectangle.BOTTOM);  

Tuesday, July 28, 2015

Java: Trigger is Mutating

Error:
 org.apache.ibatis.exceptions.PersistenceException:   
 ### Error committing transaction. Cause: org.apache.ibatis.executor.BatchExecutorException: 
 DEPENDENT.insertDependentToStaging (batch index #1) failed. Cause: java.sql.BatchUpdateException:   
 ORA-04091: table MO0RCO00_UAT.RCMBENSTAGWF is mutating, trigger/function may not see it  
 ORA-06512: at "MO0RCO00_UAT.TRIG_DEPENDENTNO", line 4  
 ORA-04088: error during execution of trigger 'MO0RCO00_UAT.TRIG_DEPENDENTNO'  


I have a DAO

   public void saveBeneficiariesToStaging(List<DependentBean> dependents){  
     SqlSession session = getSqlSessionFactory().openSession(ExecutorType.BATCH);  
     int len = dependents.size();  
     try {  
      for(int i = 0; i < len; i++) {        
       session.update("insertDependentToStaging", dependents.get(i));       
      }  
     } catch(Exception e) {  
      logger.error("saveBeneficiariesToStaging", e);  
      e.printStackTrace();  
      session.close();  
     }finally{   
       session.close();    
     }  
   }  

Solution
 public void saveBeneficiariesToStaging(List<DependentBean> dependents){  
      SqlSession session = getSqlSessionFactory().openSession(ExecutorType.BATCH);  
      int len = dependents.size();  
      try {  
       for(int i = 0; i < len; i++) {        
           session.update("insertDependentToStaging", dependents.get(i));  
           session.commit();      
       }  
      } catch(Exception e) {  
       logger.error("saveBeneficiariesToStaging", e);  
       e.printStackTrace();  
       session.close();  
      }finally{  
           session.close();   
      }  
 }    
Explanation: The trigger is selecting from the latest inserted rows in the batch update. But Trigger is mutating because it selects something that is not yet on the table because I am using batch update. Program should commit each row it inserts so that the trigger can select the recently inserted row.

Radio Button Erratic Behavior in Firefox Only

I have this HTML below. Where there are two radio buttons.
  <label class="full-width label-indented">Are you applying for membership in the Flexi Fund Program?       
      <p><input type="radio" id="flexi" name="flexi" value="A" autocomplete="off" />&nbsp;<span class="label">Yes</span></p>  
      <p><input type="radio" id="flexi1" name="flexi" value="0" autocomplete="off" checked/>&nbsp;<span class="label">No</span></p>  
 </label>  

Problem:
On first try, When I select No radio button, it automatically selects to Yes. And the Yes button is always clicked no matter how I try to select the No button.

Solution: Remove radio buttons inside label tag.
 <label class="full-width label-indented">Are you applying for membership in the Flexi Fund Program?</label>  
 <p><input type="radio" id="flexi" name="flexi" value="A" autocomplete="off" />&nbsp;<span class="label">Yes</span></p>  
 <p><input type="radio" id="flexi1" name="flexi" value="0" autocomplete="off" checked/>&nbsp;<span class="label">No</span></p>  

Tuesday, June 16, 2015

Invalid Namespace Value ORACLE TRIGGER

Error:

FAILURE ORA-28267: Invalid NameSpace Value
ORA-02063: preceding line from SYS00_DEVSCS00
ORA-06512: at "SYS00_UAT.CONTACTINFOMF_TX_TRG", line 4
ORA-04088: error during execution of trigger 'SYS00_UAT.CONTACTINFOMF_TX_TRG'

Trigger Code

 create or replace trigger SYS00_UAT.CONTACTINFOMF_TX_TRG  
 AFTER INSERT OR UPDATE of CONTACT_CD, CONTACT_INFO on SYS00_UAT.CONTACTINFOMF  
 REFERENCING NEW AS New OLD AS Old  
 FOR EACH ROW  
 BEGIN  
 -- test if contact code is Mobile  
  if :New.CONTACT_CD = 'M' then  
  insert into SYS00_UAT.MOBILENOTF (CUSTID, CEL_NO, SYSTEM_CODE, TRAN_CODE, MESSAGE)  
  VALUES(:New.SSNUM, :New.CONTACT_INFO, 'REG', 'REG','Sample Message');  
  end if;  
 END;  

Background:

Table CONTACTINFOMF is in Oracle 11g. MOBILENOTF is in Oracle 10g. Though Dblink and other configs are seem okay, the error above is still encountered. Based on forums the error needs a database patch to fix this, but of course this will take time and may affect the stable configuration of the table.

I am using Java and running on WebLogic Server.

Quick Fix:

I downloaded a ojdbc6.jar on the oracle site, loaded it in my application library. Then voila, works like magic!

Hope this helps you!



Wednesday, June 3, 2015

Java Log4j - Log Errors in Text File Then Download

//java

 import java.io.File;  
 import java.io.FileInputStream;  
 import java.io.InputStream;  
 import com.opensymphony.xwork2.ActionSupport;  
 public class DownloadLogsAction extends ActionSupport {  
   private InputStream fileInputStream;  
   public InputStream getFileInputStream() {  
       return fileInputStream;  
   }  
   public String execute() throws Exception {      
     fileInputStream = new FileInputStream(new File("/u01/app/logs/systemerr.log"));  
     return SUCCESS;  
   }  
 }  

//struts action
   <action name="download" class="com.project.system.utilities.DownloadLogsAction">  
     <result name="success" type="stream">  
       <param name="contentType">application/octet-stream</param>  
       <param name="inputName">fileInputStream</param>  
       <param name="contentDisposition">attachment;filename="systemerr.log"</param>  
       <param name="bufferSize">1024</param>  
     </result>  
   </action>  

//html
 <%@ taglib prefix="s" uri="/struts-tags" %>  
 <html>  
 <body>  
 <h1>Struts 2 download RCS Redesigned logs</h1>  
 <s:url id="fileDownload" namespace="/" action="download" ></s:url>  
 <h4>Download file - <s:a href="%{fileDownload}">rcsv3.log</s:a>  
 </h4>  
 </body>  
 </html>