HeaderSIS.jpg

KB Team Kudos

From IS480
Jump to navigation Jump to search

Team Kudos Sharing

Andy Soh
Elvin Ong
Yeena Liew
Vincent Lai


To Send Email with Gmail


public static boolean sendEmail(String receipient, String title, String bodyText){
       boolean success = false;
       try {
       String user="xxx@gmail.com";
       String pass="xxx";
       String host = "smtp.gmail.com";
       String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
       String to = receipient; // out going email id       
       String from = "vincentlai@localhost.com"; //Email id of the recipient
       String subject = title;
       String messageText = bodyText;
       boolean sessionDebug = true;
       Properties props = System.getProperties();
       props.put("mail.host", host);
       props.put("mail.transport.protocol.", "smtp");
       props.put("mail.smtp.auth", "true");
       props.put("mail.smtp.port", "465");
       props.put("mail.smtp.socketFactory.fallback", "false");
       props.put("mail.smtp.socketFactory.class", SSL_FACTORY);
       Session mailSession = Session.getDefaultInstance(props, null);
       mailSession.setDebug(sessionDebug);
       Message msg = new MimeMessage(mailSession);
       msg.setFrom(new InternetAddress(from));
       InternetAddress[] address = {new InternetAddress(to)};
       msg.setRecipients(Message.RecipientType.TO, address);
       msg.setSubject(subject);
       msg.setContent(messageText, "text/html"); // use setText if you want to send text
       Transport transport = mailSession.getTransport("smtp");
       transport.connect(host, user, pass);


               try {
                   transport.sendMessage(msg, msg.getAllRecipients());
                   success = true; // assume it was sent
                   }
                   catch (Exception err) {
                   success = false; // assume it's a fail
                   }
                   transport.close();


      } //end try
       catch (Exception e) {
           e.printStackTrace();
       }
        return success;
   }



Using jQuery


/* All codes in jquery requires the library to be included For more info, Please visit http://jquery.com/

  • /

1) Simple dialog box

<script type="text/javascript"> $(function() { $("#dialog").dialog({ bgiframe: true, autoOpen: false, height: 400, modal: true });

       /*$('.dialog').click(function() { //Dialog open when start

$('#dialog').dialog('open'); })*/ }); </script>

2) Tabs that are sortable

<script type="text/javascript"> $(function() { $("#tabs").tabs().find(".ui-tabs-nav").sortable({axis:'x'}); }); </script>

3) Ajax Script

<script type="text/javascript"> $.ajax({

                       type: "GET",
                       url: "viewBooks.action", //url
                       data: "ID="+id, //parameters
                       success: function(data){
                           $('#dialog').html(data); //update div tag to content
                       }

</script>


Struts2 Good Guide


Download 1st ebook here --> https://wiki.smu.edu.sg/is480/Image:StartingStruts2online2.pdf

Download 2nd ebook here --> https://wiki.smu.edu.sg/is480/Image:Struts2Basics.pdf





Useful Javascript/Jquery Add-ons <script> </script>


1) Passing param within form

<script type="text/javascript">
       function calculateMultiple() {
       A = eval(document.form1.textboxname1.value)     //1st text box
       B = eval(document.form1. textboxname2.value)    //2nd text box
       C = (A * B)                                     
       C.toFixed(2);                              
       C.toPrecision(2);
       document.form1.textboxname3.value = C           //3rd text box
       }
   </script>



2) Adding Tooltips Using Javascript to your forms

  Step 1 --> Download http://www.walterzorn.com/tooltip/tooltip_e.htm


  Step 2 --> In your form, add   <script type="text/javascript" src="jquery_plugins/wz_tooltip.js"></script>
  Step 3 --> Add to textbox
                   onmouseover="Tip('This is a good tooltip message')"
                   onmouseout="UnTip()""

3) Autocomplete textfield, with underline as a verified value

/* Require autocomplete.js For more configuration and downloads, please visit http://docs.jquery.com/Plugins/Autocomplete#Demos

  • /

<script type="text/javascript" charset="utf-8">

     //Textfield ID
     var textField = "#Name";
     var hiddenField = "#ID";
     $(document).ready(function(){
       //set textField to have auto complete
       $(textField).result(function(event, data, formatted) {

if (data) {

           $(textField).css("text-decoration", "underline");
           var temp = data[1];
           $(hiddenField).val(parseInt(temp));
           document.getElementById('counterID').value = parseInt(temp);
           

//uses ajax to call a function that replace a div tag(with class="quotebox")

           $.ajax({
               type: "GET",
               url: "viewQuoteBoxSmall.action",
               data: "counterID="+data[1],
               success: function(data_ajax){
                   $('.quotebox').html(data_ajax);
               }
           });
       } else {
            $(hiddenField).val(0);
            document.getElementById('counterID').value = 0;
            $(textField).css("text-decoration", "none");
       }

});

     });
     //pre-fill counterName with counterID. getFields.action is the url that returns an array of pair value with counterID | counterName
     function updateField() {
               $.ajax({
                 type: "GET",
                 url: "getFields.action?action=1",
                 success: function(data_ajax){
                     var t = parse(data_ajax);
                     for (var i=0; i < t.length; i++) {
                         if (t[i].id == document.getElementById('counterID').value) {
                             document.getElementById('counterName').value = t[i].name;
                         }
                     }
                 }
             });
           }
     //updates the auto completer field
     function searchText() {
        $(textField).search();
     }

</script>

4) Lightbox with frame /* Require prettypopin.js For more configuration and downloads, please visit http://www.no-margin-for-errors.com/projects/prettyPopin/

  • /

<script type="text/javascript"> $("a[rel^='prettyPopin']").prettyPopin({

                 modal : true, /* true/false */
                 width : false, /* false/integer */
                 height: false, /* false/integer */
                 opacity: 0.2, /* value from 0 to 1 */
                 animationSpeed: 'fast', /* slow/medium/fast/integer */
                 followScroll: true, /* true/false */
                 loader_path: 'images/prettyPopin/loader.gif', /* path to your loading image */
                 callback: function(){isRefreshing = true; location.reload(true);} /* callback called when closing the popin */
             });

</script>


5)Right Click Menu /* Require contextmenu.js For more configuration and downloads, please visit http://plugins.jquery.com/project/jqueryContextMenu

  • /

HTML

  • <a href="#1">1</a>
  • <a href="#2">2</a>
  • <a href="#3">3</a>
  • <a href="#4">4</a>
  • <a href="#5">5</a>
  • <a href="#6">6</a>

Javascript <script type="text/javascript"> $(document).ready(function(){ $(document).bind("contextmenu",function(e){ return false; });

             $(".rclick_Citem").contextMenu({

menu: 'rclick_Cmenu' }, function(action, el, pos) {

                   if (action == "1") {
                       alert("1");
                   } else if (action == "2") {
                       alert("2");
                   } else if (action == "3") {
                       alert("3");
                   }

}); $(".rclick_Nitem").contextMenu({ menu: 'rclick_Cmenu' }, function(action, el, pos) {

                   if (action == "1") {
                       alert("1");
                   } else if (action == "2") {
                       alert("2");
                   } else if (action == "3") {
                       alert("3");
                   }

});

         });
     </script>