Wednesday, January 5, 2011

Updating(Replace) anchor href values in a webpage

Using the jquery One can update attribute values of html elements in a simple steps .
The following jquery script will update the href value of all the anchor links those
 available in a web page to a static url http://www.tecrocks.com.

$('a[href]').attr('href', 'http://www.tecrocks.com');

This will be helpful for the situation like displaying the webpage content in a custom print preview page like so.
The following block will update all the href value in page without considering the element of the href value.

$('[href]').each(function () {
  $(this).attr('href', 'http://www.tecrocks.com');
});

Using *= filders with in [] we can filter the href url's.

Tuesday, January 4, 2011

Truncating(Clip) Excess text with Ellipsis in HTML5

      Text-overflow property in CSS gives the way to deal with the clipped text when the actual text content size is exceed the container box.
      'text-overflow' css attribute allows the text to be clipped when its exceed the allowed display area by setting text-overflow value as ellipsis, it will display ellipsis( three periods) following the clipped text.

.cliptext 
       {
            color: #eee;
            border: 1px solid #000000;
            overflow: hidden;
            width: 100%;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

To get this ellipsis effect when the content fall outside the box you may need to set the boxs overflow property to hidden or scroll and white-space  property to  'nowrap'.

If you have any comments or suggestions in setting ellipsis please leave a comment.

Wednesday, November 24, 2010

Generate a random alpha-numeric string in Java

By combinig use of Char array that having alphabets and numbers are an string of alphanumberic characters we can generate random alpha numberic strings in java.here is the exampls code that generate random alpha numberic string for the given length.

 /**
     * Generates alpha numeric random number for the given length.
     * for this it accounts lowercase alpha characters(a-z) and numbers(0-9)
     * @param length length of the alpha numeric random to be generated.
     * @return resulting random alpha numeric string for the given length.
     */
    public static String getAlphaNumbericRandom(int length) {
        //include lower case alpha(a-z) and numbers(0-9)
        String chars = "abcdefghijklmnopqrstuvwxyz0123456789";
        int numberOfCodes = 0;//controls the length of alpha numberic string
        String code = "";
        while (numberOfCodes < length) {
            char c = chars.charAt((int) (Math.random() * chars.length()));
            code += c;
            numberOfCodes++;
        }
        System.out.println("Code is :" + code);
        return code;
    }

If we want to create 6 digit apha numberic random means we have call getAlphaNumbericRandom methods as

getAlphaNumbericRandom(6);

Wednesday, October 20, 2010

Format Source Code for Blogging


Here is the interface to change your source code for put in blogging environments. This escapes the html tags so you can display your source codes in blogs




Tab size: 2 4 8

Embed Stylesheet:

Copy the HTML below to your clipboard. Insert the HTML of your blog or wiki.

This is an example of what your text will look like.
    • Tabs are converted to spaces.
    • Quotes and other special characters are converted to HTML.
    • Everything is enclose in HTML's 'pre' and 'code' tags.
    • Style is set:
        • Fixed width font.
        • Shaded box.
        • Dotted line border.
 

Source :formatmysourcecode.blogspot.com

Wednesday, September 8, 2010

Disable Enter key in Form tag

Placing the following code in your page section will disable the enter key operation in text field



 <script type="text/javascript">   
 function stopRKey(evt) {   
  var evt = (evt) ? evt : ((event) ? event : null);   
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);   
  if ((evt.keyCode == 13) && (node.type=="text")) {return false;}   
 }   
 document.onkeypress = stopRKey;   
 </script>  
Source : http://www.webcheatsheet.com

Saturday, September 4, 2010

Redirect Action result to another action in struts2

Using special result type in Struts-2 result we can forward one actions result to another action before forwarding it to view logic.
"redirect-action" result type is used to achieve this.here is the sample code snippet to show how to redirect one actions result to another action


 <action name="userInfo" class="UserAction">  
  <!-- Redirect to another namespace -->  
  <result type="redirect-action">  
   <param name="actionName">getDetails</param>  
   <param name="userId">${userId}</param>  
  </result>  
 </action>  

Here after finishing userInfo action getDetails action will be invoked.Here by using "Param" tags we can pass the values to the getDetails action.