Translate

Tuesday, September 25, 2012

SharePoint 2010 - Fast Search "Failed to connect..." Error

This was just one of the many problems I had to deal with today! One of the common things that happens with a Fast Search setup is to have your self-signed certificate expire after one year. When this happens, you will get the following error in the application error log of your SharePoint server:
Failed to connect to SERVER.com:XXXX Failed to initialize session with document engine: Unable to resolve Contentdistributor

The solution is simple enough, just install a new certificate!
Here are some helpful sites:
SharePoint Malarkey
SharePoint Fanatic
FAST Forum
Microsoft
Microsoft TechNet

Friday, September 7, 2012

Struts - Include Causes BufferOverflowException

Using the Struts include tag on some pages is causing the following error:
java.nio.BufferOverflowException
at java.nio.HeapByteBuffer.put(Unknown Source)
at org.apache.struts2.util.FastByteArrayOutputStream.decodeAndWriteOut(FastByteArrayOutputStream.java:161)
at org.apache.struts2.util.FastByteArrayOutputStream.writeTo(FastByteArrayOutputStream.java:94)
at org.apache.struts2.components.Include.include(Include.java:285)
at org.apache.struts2.components.Include.end(Include.java:167)
at org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42)
The only solution I could find so far is to replace the Struts include with a JSP include. Does anyone know how to fix this so it works in Struts?

Thursday, August 2, 2012

jQuery - Submit a Form Using an Anchor Tag

While you can use JavaScript in the onclick event of an anchor tag to submit a form, there may be times when you need to submit additional information along with the form. That's what I needed to do and this is how I did it using the jQuery method. This example is for Struts 2 but should work with a regular anchor tag.


<s:url var="urlFkey" namespace="%{namespace}" action="GotoAddForeignKeyRecord" escapeAmp="false" >
  <s:param name="target" >disp${fieldName}</s:param>
  <s:param name="fkeyName" value="fkeyName"/>
  <s:param name="fkeyTableName" value="fkeyPrimaryTableName"/>
  <s:param name="recordID" value="recordID"/>
</s:url>
<s:a id="disp%{fieldName}" href="%{urlFkey}" cssClass='nyroModal' onclick="this.href = this.href + '&' + $('#%{dispTablename}saveRecord').serialize();">
   Add New <s:property value="fkeyPrimaryTableNameLabel"/>
</s:a>

In the JSP snippet above I am calling the jQuery serialize method in the onclick event of the anchor tag and appending the returned result to the href for the tag.

Monday, July 23, 2012

Internews - Study Examines Potential of Digital Society in Indonesia

With more than 43 million Facebook accounts and 19 million active Twitter users, Indonesia boasts the second highest number of social media users in Asia. Despite the wave of new technology, these figures mask a stronger undercurrent of digital and social inequality. Indonesia: New Digital Nation?, a new report from the Internews Center for Innovation & Learning, explores the potential and limitations of social media and new ICTs to support local community development and advocacy in Indonesia. Read more.

Wednesday, July 18, 2012

jQuery - DataTables, Buttons, CSV

Another example of adding buttons in jQuery DataTables and outputing to CSV. This puts a button in the wrapper div.


$(document).ready(function() {
   $('#example').dataTable();
   $('<div />').css({'float' : 'left'}).css({'padding-right' : '20px'}).attr({'id' : 'fButtons'}).prependTo($('#example_wrapper'));
   $('<button />').attr({
      'id' : 'tabletocsv'
   })
   .html('CSV')
   .appendTo($('#fButtons'));

   $('#tabletocsv').click( function () {
    rgDataTable2CSV(0);
   });     
     
function rgDataTable2CSV(mOffset) {
  
    function row2CSV(tmpRow) {
        var tmp = tmpRow.join(''); // to remove any blank rows
        if (tmpRow.length > 0 && tmp !== '') {
            var mystr = tmpRow.join(',');
            csvData[csvData.length] = mystr;
        }
    }       
    function formatData(input) {
        // replace " with “
        var regexp = new RegExp(/["]/g);
        var output = input.replace(regexp, "“");
        //HTML
        regexp = new RegExp(/\<[^\<]+\>/g);
        output = output.replace(regexp, "");
        if (output === "") return '';
        return '"' + output + '"';
    }       
    function popup(data) {
        var generator = window.open('', 'csv', 'height=400,width=600,menubar=1,resizable=1');
        generator.document.write('<html><head><title>CSV</title>');
        generator.document.write('</head><body >');
        generator.document.write('<textArea cols=70 rows=15 wrap="off" >');
        generator.document.write(data);
        generator.document.write('</textArea>');
        generator.document.write('</body></html>');
        generator.document.close();
        generator.focus();
    }
    var csvData = [];
    var tmpRow = [];

   //get the header
   var el = $('#example').find('thead');
   (el).find('tr').each (function() {   
   tmpRow = [];   
   $(this).find('th').each(function(index, domEle) { 
   tmpRow[tmpRow.length] = formatData($.trim($(this).html()));
    });
   row2CSV(tmpRow);   });

    //get the data
   $('#example').find('tr').each (function() {   
   tmpRow = [];   
   $(this).find('td').each(function(index, domEle) {   
   tmpRow[tmpRow.length] = formatData($.trim($(this).html()));
   });
   row2CSV(tmpRow);   });
 
    var mydata = csvData.join('\n');
    return popup(mydata);

}  
     
});

You can test it out here.

Tuesday, July 17, 2012

jQuery - Add Buttons to DataTables

A simple example of adding buttons to jQuery DataTables before the search filter.


$(document).ready(function() {
   $('#example').dataTable();
     
   $('<div />').addClass('UnSelectAllButton').css({'float' : 'left'}).attr({'id' : 'UnSelectAllButtons'}).prependTo($('#example_filter'));
     
   $('<button />').attr({
      'id' : 'deSelectAll'
   })
   .html('Deselect All')
   .appendTo($('#UnSelectAllButtons'));

   $('<button />').attr({
      'id' : 'selectAll'
   })
   .html('Select All')
   .appendTo($('#UnSelectAllButtons'));

   $('#deSelectAll').click( function () {
    alert( 'Deselect all.');
   });     
     
   $('#selectAll').click( function () {
    alert( 'Select all.');
  });
     
});

You can test it out here.

Monday, July 16, 2012

jQuery - Output DataTables as CSV

I switched to using jQuery DataTables in my project and need a way to output the table data as CSV. Here is the JavaScript that I came up with:


function rgDataTable2CSV(mTable, mOffset) {
   var csvData = [];
   var tmpRow = [];
   var cL = 0;
   //get the header
   $('#lstTabHead'+ mTable + ' th').each (function(index, domEle) {
       if ($(this).closest('.dataTables_scrollHeadInner').length > 0){
          tmpRow[tmpRow.length] = formatData($.trim($(this).html()));
       };
   });
    row2CSV(tmpRow);
    //get the data
   $('#lstTab' + mTable).find('tr').each (function() {
      tmpRow = [];
      $(this).find('td').each(function(index, domEle) {
          tmpRow[tmpRow.length] = formatData($.trim($(this).html()));
        });
       row2CSV(tmpRow);
   });
    tmpRow = [];
    //this gets the left side (the fixed column)
   $('#lstTabFoot' + mTable).find('tr').each (function() {
      $(this).find('td').each(function(index, domEle) {
          tmpRow[tmpRow.length] = formatData($.trim($(this).html()));
        });
   });
   cl = 0;
   //this gets the right side
   $('#lstTabFoot'+ mTable + ' td').filter(':visible').each (function(index, domEle) {
       if ($(this).closest('.dataTables_scrollFootInner').length > 0){
          cL = cL + 1
          if(cL > mOffset){
          tmpRow[tmpRow.length] = formatData($.trim($(this).html()));
          };
       };
   });
   row2CSV(tmpRow);    
    var mydata = csvData.join('\n');
    return popup(mydata);
          
    function row2CSV(tmpRow) {
        var tmp = tmpRow.join('') // to remove any blank rows
        if (tmpRow.length > 0 && tmp != '') {
            var mystr = tmpRow.join(',');
            csvData[csvData.length] = mystr;
        }
    }
       
    function formatData(input) {
        // replace " with “
        var regexp = new RegExp(/["]/g);
        var output = input.replace(regexp, "“");
        //HTML
        var regexp = new RegExp(/\<[^\<]+\>/g);
        var output = output.replace(regexp, "");
        if (output == "") return '';
        return '"' + output + '"';
    }
       
    function popup(data) {
        var generator = window.open('', 'csv', 'height=400,width=600,menubar=1,resizable=1');
        generator.document.write('<html><head><title>CSV</title>');
        generator.document.write('</head><body >');
        generator.document.write('<textArea cols=70 rows=15 wrap="off" >');
        generator.document.write(data);
        generator.document.write('</textArea>');
        generator.document.write('</body></html>');
        generator.document.close();
        generator.focus();
    }
       
}


This script is based off of the Table2CSV script. The HTML table structure for the of the DataTables in my application have a thead id = lstTabHead + tablename, tbody id = lstTab + tablename, tfoot id = lstTabFoot + tablename. This naming convention is required by this script. Call the script using "rgDataTable2CSV(tablename, 1)". The second parameter is an offset that is used for the first column being omitted.