Friday, December 20, 2013

DIV with Vertical Scroll Bar



How to create a DIV with a scroll bar? 
 
<div style="width: 200px; height: 100px; overflow-y: scroll;">
 




 

Wednesday, December 18, 2013

Hibernate based JPA Query


Can I use a direct SQL query to retrieve results in hibernate based JPA?
the answer is YES.
Below is some example code I wrote in a DAO class:

    @SuppressWarnings("unchecked")
    @Override
    public List<String> getSiteSubTypes() {
        EntityManager em = super.getJpaTemplate().getEntityManagerFactory().createEntityManager();
        Session session = (Session) em.getDelegate();       
       
        SQLQuery sqlQuery = session.createSQLQuery("SELECT DISTINCT siteSubType  FROM portMapping");
       
     
        @SuppressWarnings("rawtypes")
        List result = sqlQuery.list();       
           
        List<String> listResult = (List<String>) result;
 

        return listResult;
    }   

   

In the above example, I am doing something really simple. Get the list of siteSubType distinctive values.


For more SQL query examples, see this link: http://code.google.com/p/simplejpa/wiki/JPAQuery

I copied a few here:

Examples

Basic query
query = entityManager.createQuery("select o from MyTestObject o where o.income = :income and o.age = :age");
query.setParameter("income", 50507.0);
query.setParameter("age", 12);
List<MyTestObject> obs = query.getResultList();
Query with referenced object filter (@ManyToOne)
query = entityManager.createQuery("select o from MyTestObject o where o.anotherObject = :anotherObject");
query.setParameter("anotherObject", anotherObject);
List<MyTestObject> obs = query.getResultList();
Which is equivalent to:
query = entityManager.createQuery("select o from MyTestObject o where o.anotherObject.id = :anotherObjectId");
query.setParameter("anotherObjectId", anotherObject.getId());
List<MyTestObject> obs = query.getResultList();
Can also query down object graph (1 level only right now):
query = entityManager.createQuery("select o from MyTestObject o where o.someOtherObject.name = :name");
query.setParameter("name", "finnigan");
List<MyTestObject> obs = query.getResultList();
But keep in mind, querying down the graph can be slow because it will query for the id's down the graph, then apply them to the top level query.
Like Query:
query = em.createQuery("select o from MyTestObject3 o where o.someField3 like :x");
query.setParameter("x", "fred and%"); List<MyTestObject3> obs = query.getResultList();
This will return all MyTestObject3's that start with "fred and".
Sort query:
query = entityManager.createQuery("select o from MyTestObject o where o.income = :income and o.age = :age order by o.age");
query.setParameter("income", 50507.0);
query.setParameter("age", 12);
List<MyTestObject> obs = query.getResultList();

Count:

Count returns a result list with a single entry that contains a Long.
query = entityManager.createQuery("select count(o) from MyTestObject o where o.income = :income and o.age = :age order by o.age");
query.setParameter("income", 50507.0);
query.setParameter("age", 12);
List obs = query.getResultList();
long count = obs.get(0);

QueryBuilder

QueryBuilder helps with creating parameterized queries.
Example usage:
// the one liner
Query qb = new QueryBuilderImpl()
   .append("select o from IndexStats o where o.numKeywords < :x", "x", 10).makeQuery(em);
   List<IndexStats> resultList = qb.getResultList();
private List<Book> getBooks(BookFilter filter) {
    QueryBuilder qb = new QueryBuilderImpl();
    qb.append("select o from Book o where 1 = 1");
    if (filter.getTitle() != null) {
        qb.append(" and o.title = :title", "title", filter.getTitle());
    }
    Query q = qb.makeQuery(em());
    return q.getResultList();
}

JSP Dropdown Example



 The following example displays:
(1)a default option: ---Select--- , means empty input.
(2) options to choose from. Option values are obtained from a list ${technologyList}. JSTL is used to retrieve and pass the values to <form:option> tag.

                         <span class="sp-fieldlabel">Sub-Type</span>

                        <form:select path="searchCriteria.subType" cssClass="sp-select">
                            <option value="-1">
                                      --<spring:message code="generic.dropdown.selection" />--
                            </option>

                            <c:forEach items="${SiteSubTypes}" var="element">
                                <form:option value="${element}">${element}</form:option>
                            </c:forEach>
                        </form:select>

In the above code example,   <spring:messagecode="generic.dropdown.selection"/>  uses Spring's localization feature. Below shows the results of the above JSP:

Friday, November 29, 2013

JSP vs.HTML

(1)JSP simply puts Java inside HTML pages.

 You can take any existing HTML page and change its extension to ".jsp" instead of ".html".

Now load the new file, with the ".jsp" extension, in your browser. You will see the same output, but it will take longer! But only the first time. If you reload it again, it will load normally. What is happening behind the scenes is that your JSP is being turned into a Java file, compiled and loaded.
This compilation only happens once, so after the first load, the file doesn't take long to load anymore. (But everytime you change the JSP file, it will be re-compiled again.)

 (2)can enclose Java expressions and java code (called a scriplets), which are evaluated at run time. use <%= and %>

 It is true that JSPs are primarily HTML with embedded Java code. However, they have many advantages, such as requiring less (typically none) configuration, and being easy to modify and deploy. Therefore they can lend themselves to other usages, such as writing simple and straightforward controllers.

 JSP's eventually are turned into servlets, and though JSPs are much simpler than servlets, for some cases servlets are still useful.

Thursday, November 28, 2013

HTML Amazing

HTML Amazing

Differences Between HTML and XHTML

In HTML, the <input> tag has no end tag.

In XHTML, the <input> tag must be properly closed, like this <input />.

Here is how to mark deleted text: blue and inserted text: red!


Want to see what HTML can do?

HTML can do a lot of fun things
Your Birthday:
Select your favorite color:

Form with a dropdown box.

Personal information: Name:
E-mail:
Date of birth:

If you click the "Submit" button, the form-data will be sent to a page called "html_form_action.asp".



Tuesday, October 22, 2013

MySQL vs. Oracle DB

Oracle XE does not have windows 64bits version yet. Oralce Standard Version download size 2.5G.

I am looking for a light DB, so I choose MySQL. MySQL windows 64bits is 207M, much lighter.
Below is a nice comparison betw. the 2 databases:


MySQL download site:


Oracle WebCenter 11g Essential docs:


Oracle® Fusion Middleware Developer's Guide for Oracle WebCenter
11g Release 1 (11.1.1)

http://docs.oracle.com/cd/E15523_01/webcenter.1111/e10148/jpsdg_prep_environment.htm#JPSDG133

Installation Guide:
http://docs.oracle.com/cd/E15523_01/install.htm



Tuesday, October 15, 2013

Create JEE Maven project in Eclipse: What if my archetypes are missing?

When I wanted to start a JEE project in Eclipse using Maven, I found that I can't find an archetype JEE to use. What to do?
The following url gave you a good answer:

http://maven.apache.org/archetype/maven-archetype-plugin/usage.html

In short, in command prompt, do:
$ mvn archetype:generate

Then choose org.codehaus.mojo.archetypes:webapp-jee5 
then choose version1.3.






Tuesday, October 8, 2013

How do I add my Yahoo mail into Outlook 2013 and keep the account synced?

How do I add my Yahoo mail into Outlook 2013?
Follow the following link, use imap instead of POP3 since POP is not enabled in Yahoo.com:

http://superuser.com/questions/595827/how-to-add-yahoo-mail-account-to-outlook-2013/656253#656253

Then how do I keep the account synced?
Following the instructions in the following link to download the sync.msi utility and install it.

http://www.wikihow.com/Synchronize-Outlook-Data-with-Yahoo

Then it works!! Beautiful.

Monday, September 23, 2013

Eclipse: Install Plug Ins

If one can connect to internet, it is easy to install Eclipse Plug Ins.
Go to "Help" --> "Install New Software" --> enter url in "Work With"

But what to do when it is not possible to connect to Internet from Eclipse?

two ways:
(1) find the plug in Zip, download it to local, then use
"Help" --> "Install New Software" --> click on "Add" beside "Work With",
click on "Archive" , select the zip file from your local disk, then Open it.


(2) find the internet proxy which can be used to access internet.
Or use Fiddler (IE browser web debugging tool) to find the proxy Fiddler is using and configure in Eclipse to use it to access the plug in web sites.

Eclipse View Installation Detail


To view installation detail for Eclipse, go to "Help"-->"About Eclipse Platform" --> Click on button "Installation Details".  --> click on "Configuration"




Wednesday, September 18, 2013

Oracle Portal 11g: Import/export TransportSet

Recommended way:

follow this:
http://docs.oracle.com/cd/E23943_01/portal.1111/e10239/cg_imex.htm#CCJJIBDC

Note when importing Transport Set from portal builder, if pre-check has errors, then you can still click
"Import Now" to start the importing process, but click on "Clean" to clear and recover from the errors





Tuesday, September 17, 2013

Use SVN with Eclipse





Subversion (SVN) is a popular replacement for CVS, offering improved performance (courtesy of intelligent local caching and a database back end), easy and fast branching, and an answer to every one of the shortcomings that people often run into while using CVS.

great reference here:
http://www.ibm.com/developerworks/library/os-ecl-subversion/

Eclipse: no output to the console when run ant build

Solution:

to get the output in console. you should change the JRE option in the "Edit configuration and launch" for Ant run as to Run in same JRE as the workspace.

Refer to:
http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fviews%2Fdebug%2Fref-editlaunchconfig.htm  for instructions on how to open the "Edit Configuration and Launch".












Edit Launch Configuration                                     



Launch Configuration Dialog

Monday, September 9, 2013

Weblogic wldeploy:Exclusive access to the edit lock

I have encountered this issue lately.
When deploying an application in weblogic, I received error:  The following solution resolved the issue.
Original post from:
http://adfhowto.blogspot.ca/2011/07/troubleshooting-domain-edit-lock-is.html

Error
[Deployer:149163]The domain edit lock is owned by another session in non-exclusive mode - this deployment operation requires exclusive access to the edit lock and hence cannot proceed. If you are using "Automatically Aquire Lock and Activate Changes" in the console, then the lock will expire shortly so retry this operation.


Solution
Actually what Deployer is trying to tell you is that it tried to deployed but another user has Lock and Edit the domain . More regarding Lock and Edit in this related post.

In other not to fail but exist gracefully leaving you deployment to be applied when the Lock is released, then use nonexclusivelock option.

Using this option you ll get the following message, if another user has avquire the lock and the script will not fail:
[wldeploy] Operation is pending and will be activated or cancelled when the ongoing edit session is activated or cancelled. 


In case if you use a wldeploy ant task, here is an example script
<project name="deploy" default="deploy">
<property file="deploy.properties" />

<!-- Setting TaskDefinition -->
<taskdef name="wldeploy" classname="weblogic.ant.taskdefs.management.WLDeploy">
    <classpath>
        <pathelement location="${wldeploy.home}/weblogic.jar"/>
    </classpath>
</taskdef>
<!-- Deploying Applications  -->
<target name="deploy">
<wldeploy action="deploy"
          name="${deploy.name}"
          source="${deploy.source.path}/${deploy.source.ear}"
          verbose="true"
          adminurl="${connection.protocol}://${wls.hostname}:${wls.port}" 
          targets="${deploy.target}"
          upload="true"
          user="${wls.username}"
          password="${wls.password}"
          usenonexclusivelock="true" />
</target>
</project> 

Wednesday, September 4, 2013

view the content of a keystore

The following commands allows you to see how many entries are in a keystore:


E:\>keytool -list -keystore E:\SSL_Cert\TempKeyStore.jks
Enter keystore password:

Keystore type: JKS
Keystore provider: SUN

Your keystore contains 3 entries

alias3, 3-Sep-2013, PrivateKeyEntry,
Certificate fingerprint (SHA1): C2:E9:8D:F3:6D:BC:02:F0:66:7B:FD:6C:69:6A:40:F1:E0:53:BA:0
8
2, 4-Sep-2013, PrivateKeyEntry,
Certificate fingerprint (SHA1): B0:DF:C4:0B:91:92:74:B1:34:85:4E:2F:27:8C:71:41:BA:07:31:4
B
1, 3-Sep-2013, trustedCertEntry,
Certificate fingerprint (SHA1): 24:00:EF:77:DA:59:6A:89:E0:93:68:E9:84:66:EE:22:A4:A5:A0:C
C

Find the alias of a key in a p12 keystore:
keytool -list -keystore E:\SSL_Cert\xxx.p12 -storetype PKCS12

Java Keytool Commands for Checking

If you need to check the information within a certificate, or Java keystore, use these commands.

  • Check a stand-alone certificate keytool -printcert -v -file mydomain.crt
  • Check which certificates are in a Java keystore keytool -list -v -keystore keystore.jks
  • Check a particular keystore entry using an alias keytool -list -v -keystore keystore.jks -alias mydomain


For more detailed info on keystore and import keys, refer to:

http://docs.oracle.com/javase/6/docs/technotes/tools/windows/keytool.html

http://www.sslshopper.com/article-most-common-java-keytool-keystore-commands.html


Kill a process in windows with PID

taskkill /im myprocess.exe /f
The "/f" is for "force". If you know the PID, then you can specify that, as in:
taskkill /pid 1234 /f
Lots of other options are possible, just type taskkill /? for all of them. The "/t" option kills a process and any child processes; that may be useful to you.

Thursday, August 29, 2013

Wednesday, August 28, 2013

Deinstall SOA Suite (BPEL)





I have recently had to de-install the oracle SOA suite and the deployed BPEL processes, web services, and etc. The above Oracle Reference document gave steps on how it can be done. Below is a more concise summary to guide you through al the steps needed:

Easiest way is to use Enterprise Manager to stop all the soa servers one by one.
Then stop the admin server.
2.1 Start RCU by running rcu.bat. then drop all related schemas.
2.2 Dropping Schemas and Deleting Datafiles (Windows Only)
If your database is running on a Windows operating system, and you are using RCU to drop schemas from that database, some components datafiles are not dropped. These datafiles are located in the oradata directory in the database Oracle home.

3.1.      Removing the SOA Oracle Home
To start the deinstaller, navigate to the SOA_ORACLE_HOME/oui/bin (on UNIX operating systems) or SOA_ORACLE_HOME\oui\bin (on Windows operating systems) directory and start the deinstaller.
On Windows operating systems:
setup.exe -deinstall
3.2.      Removing the Oracle Common Home
To start the deinstaller, navigate to MW_HOME\oracle_common\oui\bin (on Windows operating systems) directory and start the deinstaller.
On Windows operating systems:
setup.exe -deinstall -jreLoc JRE_LOCATION
3.3.      Manually remove files
                  Go to Oracle\Middleware\, delete Oracle_SOA1 and Oracle_Commom

Windows
Choose Start > Programs > Oracle WebLogic > Uninstall Oracle WebLogic.
The Oracle Uninstaller Welcome screen is displayed.

On a Windows operating system, if your Middleware home directory was C:\Oracle\Middleware, use a file manager window and navigate to the C:\Oracle directory, then right-click on the Middleware folder and select Delete.
On Windows systems, you must also manually remove the program groups from the Start Menu\Programs folder. As an example (the folder names and program group names on your system may be different), you might remove the following from C:\Documents and Settings\All Users\Start Menu\Programs:
·        Oracle Fusion Middleware 11.1.1.3.0
·        Oracle SOA Suite 11g - Home1
·        Oracle WebLogic