Posts

Facebook JavaScript API: Invite facebook friends

This is the JavaScript code to invite facebook friends (Posting message to their wall) function inviteFBFriend(friend_id,invitation_message){ var opts = {              message : invitation_message,              name : 'Hello User',              description : 'Facebook is great!',              picture : 'http://www.knowledgeserve.in/images/knowledgeServeLogo.jpg '     }; FB.api('/'+friend_id+'/feed', 'post', opts , function(response) {        if (!response || response.error) {         alert('Error occured');                    } else {            alert('Post ID: ' + response.id);        }      }); }

Facebook JavaScript API: Get Facebookfriends name and pictures

Add this coe to body element of your html file..... <div id="findAllFriends">     <div id="fb-root"></div>          <div class="fb_login_user_status">         <a class="fb_button fb_button_medium">             <span id="fb-auth" class="fb_button_text">Log In with Facebook</span>         </a>      </div>      <div class="fbUser" id="user-info"></div     <div id="friendslistFB" >        <table id="fbFriends" width="100%" border="0" >        </table>        </div>    </div> /**** Java Script code ********/ var facebookAppId=' your facebook app id '; window.fbAsyncInit = function() {   FB.init({ appId: facebookAppId,     status: true,  ...

OGNL in struts2: and

Access value form <s:iterator> into <s:if> (ognl with <s:if> and <s:iterator>) For example: Suppose loadUserList is the itertaor(containing UserName and Address ) to be iterate on jsp, <s:if test="loadUserList != null && loadUserList.isEmpty()">   <s:iterator value="loadUserWalksResults" status="rowStatus">                   UserName :<s:property escape="false" value="userName" /> Address: <s:property escape="false" value="address" /> <s:if test='userName.equals("Admin")'>This is admin User</s:if> <s:else>This is not an admin user!</s:else>   </s:iterator> </s:if>

Struts 2 : Tag with status object

The <s:iterator> tag is widely used on UI (jsp)  to iterate some collection returned by any action. <table class="facebookFriendList">    <tr class="even">        <td><b>UserName</b></td>        <td><b>ProfileImage</b></td>     </tr>    <s:iterator value="facebookFriendList" status="rowStatus">      <tr class="<s:if test="rowStatus.odd == true ">odd</s:if><s:else>even</s:else>">          <td><s:property value="userName" /></td>          <td><s:property value="profileImageURL" /></td>      </tr>      </s:iterator> </table> We use the iterator tag to iterator over the collections. See OGNL expression #statusName. Properties of the IteratorStatu...

Get real client ip-address using java / getRemoteAddr() is giving 127.0.0.1 as client ip address in java

Getting real client ip-address using java (if Apache redirection is used...) -------------------------------------------------------------------------- You can use ,     String ipAddress = request.getHeader("X-Forwarded-For");  if you have configured Apache redirection. ------------------------------------------------------------------------- If you will use      request.getRemoteAddr(), it may return 127.0.0.1 if apache redirection has been configured at your deployment server.

JDBC: Prepared Statement

Prepared Statement Demo using Java/MySQL ------------------------------------------------ package com.vicwalks.web.util; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import com.mysql.jdbc.Connection; public class PreparedStatementDemo {  public static void main(String[] args) {  System.out.println("===========Prepared statement demo===========\n");  Connection con = null;  PreparedStatement preparedStatement;  try{    Class.forName("com.mysql.jdbc.Driver");    con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/ DATABASENAME "," userName "," password ");    try{       String sql = "SELECT * FROM employee WHERE salary >= ?";       preparedStatement = con.prepareStatement(sql);       preparedStatement.setInt(1,10000);   ...
Get <td> element value inside a <table> 1) Using JQuery..... $('#tableDivId tr').each(function() {     var tdText = $(this).find("td:first").html();     }); Here you are iterating all rows of a table according to given div id, and then you are fetching first <td> element data for current <tr>.... 2) Without JQuery............... function loadAllTDs(){ var table = document.getElementById('tableDivId');  var rows = table.getElementsByTagName('tr'); var cells, tdText; for (var i = 0, j = rows.length; i < j; ++i) {       cells = rows[i].getElementsByTagName('td');       if (!cells.length) {          continue;       }       tdText = cells[0].innerHTML;  // For 0th td for each tr of this table....       alert(tdText);         } }