Skip to main content

Posts

Showing posts from 2015

best practices for java authentication via LDAP

/*  * To change this template, choose Tools | Templates  * and open the template in the editor.  */ package com.dash.ejb.login; import java.util.Hashtable; import javax.naming.AuthenticationException; import javax.naming.Context; import javax.naming.NameNotFoundException; import javax.naming.NamingEnumeration; import javax.naming.NamingException; import javax.naming.SizeLimitExceededException; import javax.naming.directory.Attribute; import javax.naming.directory.Attributes; import javax.naming.directory.DirContext; import javax.naming.directory.InitialDirContext; import javax.naming.directory.SearchControls; import javax.naming.directory.SearchResult; public class MyLdapAuthinticator {     private static String LDAP_SERVER="ldap server ip";     private static String LDAP_SERVER_PORT="ldap server port";     private static String LDAP_BASE_DN="dc=domain name,dc=com";     private static String LDAP_BIND_DN="CN=ldap power user,CN

JPA ordering list of entities

Example 1:   @ Entity public class Course { ... @ ManyToMany @ OrderBy ( "lastname ASC" ) public List < Student > getStudents ( ) { ... } ; ... } Example 2: @ Entity public class Student { ... @ ManyToMany ( mappedBy = "students" ) @ OrderBy // ordering by primary key is assumed public List < Course > getCourses ( ) { ... } ; ... } Example 3: @ Entity public class Person { ... @ ElementCollection @ OrderBy ( "zipcode.zip, zipcode.plusFour" ) public Set < Address > getResidences ( ) { ... } ; ... }   @ Embeddable public class Address { protected String street ; protected String city ; protected String state ; @ Embedded protected Zipcode zipcode ; }   @ Embeddable public class Zipco

Liferay AlloyUI useful practical user interface

<!-- X characters remaining example http://alloyui.com/tutorials/ -->   <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Example</title> <script src="http://cdn.alloyui.com/2.0.0/aui/aui-min.js"></script> <link href="http://cdn.alloyui.com/2.0.0/aui-css/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <input type="text" id="some-input" /> <span id="counter"></span> character(s) remaining <script> YUI().use( 'aui-char-counter', function(Y) { new Y.CharCounter( { counter: '#counter', input: '#some-input', maxLength: 10 } ); } ); </script> </body> </html>   AlloyUI’s character counter reports the number of characters you can enter in the text fie

sorting list of beans

public class Student implements Comparable < Student > { String name ; int age ; public Student ( String name , int age ) { this . name = name ; this . age = age ; } @Override public String toString () { return name + ":" + age ; } @Override public int compareTo ( Student o ) { return Comparators . NAME . compare ( this , o ); } public static class Comparators { public static Comparator < Student > NAME = new Comparator < Student >() { @Override public int compare ( Student o1 , Student o2 ) { return o1 . name . compareTo ( o2 . name ); } }; public static Comparator < Student > AGE = new Comparator < Student >() { @Override public int compare ( Student o1 , Student o2 ) {

JSF2 backing bean has a reference to another and re using request scoped properties in new requests

 // note exam id and exam text are initialized from exam backing bean which is (request scoped) and in the same time they are traveling in each request @ManagedBean(name = "question")//Constants.QUESTION) @RequestScoped public class QuestionBean {     private int examId;     private String examText;        @ManagedProperty(name="exam", value="#{exam}")     private ExamBean exam; // getters and setters   @PostConstruct         public void init() {            examId = exam.getExamId();            examText=exam.getExamText();                   }     } ------------------------XHTML page --------------------------------------- <?xml version="1.0"?> <f:view     xmlns="http://www.w3.org/1999/xhtml"     xmlns:c="http://java.sun.com/jsp/jstl/core"     xmlns:f="http://java.sun.com/jsf/core"     xmlns:h="http://java.sun.com/jsf/html"     xmlns:ui="http://java.sun.com/jsf/facelets&qu

Very powerful yet simple JSF 2 with Ajax using render and renderd

in the jsf xhml  <?xml version="1.0"?> <f:view     xmlns="http://www.w3.org/1999/xhtml"     xmlns:c="http://java.sun.com/jsp/jstl/core"     xmlns:f="http://java.sun.com/jsf/core"     xmlns:h="http://java.sun.com/jsf/html"     xmlns:ui="http://java.sun.com/jsf/facelets" >     <h:head /> <h:body> <h:form> <h:selectOneRadio value="#{question.questionType}" >        <f:selectItem itemValue="single" itemLabel="Single Choice" />        <f:selectItem itemValue="multi" itemLabel="Multi Choice" />        <f:ajax execute="@this" render="selectedType" /> </h:selectOneRadio>  <h:panelGroup id="selectedType">      <h:panelGroup layout="block" id="choices" rendered="#{question.questionType eq 'multi'}" >         <table>         <tr>    

Oracle export /backup and import /restore schemas

A----------------------------------------EXPORT/BACKUP---------------------------------------------------- 1-  make new folder for the backup  let say  c:/oracle/import/ MY_DATA_PUMP_DIRECTORY 2-  sqlplus  login as system user 3- CREATE DIRECTORY MY_DATA_PUMP_DIRECTORY  AS 'c:/oracle/ MY_DATA_PUMP_DIRECTORY '; 4- grant all on directory MY_DATA_PUMP_DIRECTORY to system; 5- exit sqlplus and run the following from command line expdp system/password DIRECTORY=MY_DATA_PUMP_DIRECTORY DUMPFILE=schemaName.dmp logfile=schemaName.log SCHEMAS=schemaName B-----------------------------IMPORT/RESTORE-------------------------------------------------------------------- 1- make sure you have the directory  MY_DATA_PUMP_DIRECTORY   the same as for the import 2- impdp system/password  DIRECTORY=MY_DATA_PUMP_DIRECTORY dumpfile=schemaName.dmp logfile=schemaName.log SCHEMAS=schemaName

oracle drop all tables and sequences in a certain schema

--  please never put a comment starting with " / "  as this character means execute the previous line  BEGIN   FOR i IN (SELECT us.sequence_name               FROM USER_SEQUENCES us) LOOP     EXECUTE IMMEDIATE 'drop sequence '|| i.sequence_name ||'';   END LOOP;     FOR i IN (SELECT ut.table_name               FROM USER_TABLES ut) LOOP     EXECUTE IMMEDIATE 'drop table '|| i.table_name ||' CASCADE CONSTRAINTS ';   END LOOP; END; -- the following character executes the whole block of pl sql code /

Custom java swing TextField that has auto complete feacher

package com.util; import java.awt.Point; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import javax.swing.JMenuItem; import javax.swing.JPopupMenu; import javax.swing.JTextField; /**  *Custom JText component that has a gentle auto complete menu  * @author melsonbati  */ public class JAutoCompleteTextField extends JTextField {             private JPopupMenu popupMenu;     private List<String> myList=new ArrayList<String>();     private File txtFile=null;         private ActionListener menuListener = new ActionListener() {       public void actionPerformed(ActionEvent event) {           setText(event.getAct

Java Swing please wait panel

package test; import java.awt.BorderLayout; import java.awt.Dialog.ModalityType; import java.awt.Window; import java.awt.event.ActionEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener;   import javax.swing.*; public class PleaseWait{    public static void main(String[] args) {       JButton showWaitBtn = new JButton(new ShowWaitAction("Show Wait Dialog"));       JPanel panel = new JPanel();       panel.add(showWaitBtn);       JFrame frame = new JFrame("Frame");       frame.getContentPane().add(panel);       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       frame.pack();       frame.setLocationRelativeTo(null);       frame.setVisible(true);    } } class ShowWaitAction extends AbstractAction {    protected static final long SLEEP_TIME = 3 * 1000;    public ShowWaitAction(String name) {       super(name);    }    @Override    public void actionPerformed(ActionEvent evt) {       SwingWorker

textarea maxlenght for IE9

/*use this jquery func*/ window . onload = function () { var txts = document . getElementsByTagName ( 'TEXTAREA' ) for ( var i = 0 , l = txts . length ; i < l ; i ++) { if ( /^[0-9]+$/ . test ( txts [ i ]. getAttribute ( "maxlength" ))) { var func = function () { var len = parseInt ( this . getAttribute ( "maxlength" ), 10 ); if ( this . value . length > len ) { alert ( 'Maximum length exceeded: ' + len ); this . value = this . value . substr ( 0 , len ); return false ; } } txts [ i ]. onkeyup = func ; txts [ i ]. onblur = func ; } } }