Total Pageviews

2011/08/12

Install jquerywtp to Make Eclipse WTP's JavaScript Content Assistance Support jQuery

1. Go to download jar file, jqueryWTP1.00foEN.jar, from http://code.google.com/a/eclipselabs.org/p/jquerywtp/downloads/list

2. execute java -jar jqueryWTP1.20foEN.jar in command line

3. Jar File --> Browse --> Choose org.eclipse.wst.jsdt.core_1.1.4.v201102102045.jar


4. Output Dir --> Browse

5. Click Generate Button


6. You can get new jar file, org.eclipse.wst.jsdt.core_1.1.4.v201102102045.jar, in C:\

7. Overwrite jar file in eclipse\plugins

8. Then restart eclipse with -clean to clear plug-in cache.

9. Check the result

Remember to remove -clean after you launch eclipse

ADMA0176E: Application installation of {0} faild with PrivilegedActionException. Ear file path is {1}.

Problem


When I try to deploy an ear file to my WAS (WebSphere Application Server)



I get the following error:

ADMA0176E: Application installation of {0} faild with PrivilegedActionException. Ear file path is {1}.



Solution


right click on project --> Properties --> Dependecncy Management --> Check "Automatically update dependencies from Maven pom.xml" checkbox




And do "Update Project Configuration" on your project



See....my ear file had been deployed to WAS successfully.

And can open my jsp successfully.

The name "Ybdt010" is not a recognized entity or identifier

Problem
As I do query via OpenJPA in WAS(WebSphere Application Server), it complains this error message
 org.apache.openjpa.persistence.ArgumentException: An error occurred while parsing the query filter "select t from Ybdt010 t where t.emplCd = ?1". Error message: The name "Ybdt010" is not a recognized entity or identifier. Perhaps you meant Nigt010, which is a close match. Known entity names: [Nigw001, Nigt010, Nigt055, Nigt011, Nigt012, JUTSysParam, Nigt013, Nigt036, Nigt037, Nigt038, Nigt039, JUTMsg, Nigt080, Nigt081, Nigt082, Nigt040, Nigt063, Nigt041, Nigt042, Nigt020, Nigt064, Nigt021, Nigt043, Nigt044, Nigt088, Nigt001, Nigt045, Nigt005, Nigt006, Nigt007, Nigt008, JUTCode]   
 at org.apache.openjpa.kernel.exps.AbstractExpressionBuilder.parseException(AbstractExpressionBuilder.java:118) ~[com.ibm.ws.jpa.jar:1.0.1-SNAPSHOT]   
 at org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getClassMetaData(JPQLExpressionBuilder.java:177) ~[com.ibm.ws.jpa.jar:1.0.1-SNAPSHOT]   
 at org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.resolveClassMetaData(JPQLExpressionBuilder.java:150) ~[com.ibm.ws.jpa.jar:1.0.1-SNAPSHOT]   
 at org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getCandidateMetaData(JPQLExpressionBuilder.java:225) ~[com.ibm.ws.jpa.jar:1.0.1-SNAPSHOT]   
 at org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getCandidateMetaData(JPQLExpressionBuilder.java:195) ~[com.ibm.ws.jpa.jar:1.0.1-SNAPSHOT]   


Why it happened?
There was a problem if the first time you accessed an Entity type (ie. Ybdt010) via a Query instead of some other access.
It should be WebSphere's bug, need to install fixpack to fix this problem.

Solution
Here has a workaround solution to fix this problem. Before executing your query, you just insert something simple like...
 Ybdt010 ybdt010 = new Ybdt010();  


2011/08/08

員工失去幹勁,主管做錯了什麼?

  • 不斷的批評
  • 無法達成的目標
  • 不斷改變目標
  • 未提供相關資訊使目標難以達成
  • 當大問題發生的時候,主管卻只責備一個人
  • 侵入式的監督他人工作
  • 低估已經完成的工作
  • 主管將別人的努力據為己有

org.apache.openjpa.persistence.NoResultException


Problem
As we do search via primary key, it will show this exception message if JPA does not search any matched data
1:  org.apache.openjpa.persistence.NoResultException: The query on candidate type "class gov.fdc.nig.domain.Nigt020" with filter "select t1 from Nigt020 t1, Nigt022 t2 where t2.id.dlvUnit = ?1 and t2.id.taxCd = ?2 and t2.id.dlvYr = ?3 and t2.id.flgTp = ?4 and t2.id.serialNo = ?5 and t2.paraTp <> ?6 and t2.paraTp = t1.paraTp" was configured to have a unique result, but no instance matched the query.   
2:  at org.apache.openjpa.kernel.QueryImpl.singleResult(QueryImpl.java:1299) ~[com.ibm.ws.jpa.jar:1.0.1-SNAPSHOT]   
3:  at org.apache.openjpa.kernel.QueryImpl.toResult(QueryImpl.java:1221) ~[com.ibm.ws.jpa.jar:1.0.1-SNAPSHOT]   
4:  at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:990) ~[com.ibm.ws.jpa.jar:1.0.1-SNAPSHOT]   
5:  at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:805) ~[com.ibm.ws.jpa.jar:1.0.1-SNAPSHOT]   
6:  at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:775) ~[com.ibm.ws.jpa.jar:1.0.1-SNAPSHOT]   
7:  at org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:533) ~[com.ibm.ws.jpa.jar:1.0.1-SNAPSHOT]   
8:  at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:252) ~[com.ibm.ws.jpa.jar:1.0.1-SNAPSHOT]   
9:  at org.apache.openjpa.persistence.QueryImpl.getSingleResult(QueryImpl.java:317) ~[com.ibm.ws.jpa.jar:1.0.1-SNAPSHOT]   


The original approach is to call getSingleResult method:
1:  public Object createQueryForSingleResult(String jpql, Object[] params, Dao.PersistenceUnit persistenceUnitName) {   
2:       EntityManager em = getEntityManager(persistenceUnitName);   
3:       Query query = em.createQuery(jpql);   
4:       for (int i = 0; i &lt; params.length; i++) {   
5:            query.setParameter(i + 1, params[i]);   
6:       }   
7:       return query.getSingleResult();   
8:  }  

Solution
Just change to this way, then the exception will not take place again:
1:  public Object createQueryForSingleResult(String jpql, Object[] params, Dao.PersistenceUnit persistenceUnitName) {   
2:       Object result = null;   
3:       EntityManager em = getEntityManager(persistenceUnitName);   
4:       Query query = em.createQuery(jpql);   
5:       for (int i = 0; i < params.length; i++) {   
6:            query.setParameter(i + 1, params[i]);   
7:       }   
8:       List list = query.getResultList();   
9:       if(!CollectionUtils.isEmpty(list)){   
10:            result = list.get(0);   
11:       }   
12:       return result;   
13:  }   

2011/08/05

2011/08/04

How to Change WebSphere Console to English

Problem
As I start up WebSphere, the console show Traditional Chinese in default.
But it's difficult for us to figure out solutions as we face problems.

Solution
Please login WAS administration console: https://localhost:9043/ibm/console
Go to 伺服器 > 伺服器類型 > WebSphere Application Server > 應用程式伺服器 > server1 > 伺服器基礎架構 > Java 和程序管理 > 程序定義 > Java 虛擬機器 > 自訂內容

Create a new property:
  • name: user.language
  • value: en



Then restart WAS, and check the console

Taking Over a Project

Reference: http://kaczanowscy.pl/tomek/2011-08/taking-over-a-project

Team

  • who? + characteristics + how long they work with the team + strong/weak points + maturity level / how independent they are? + maybe there is some BSC mechanism, if so, take a look at the previous records
  • language skills
  • contact - mail, skype/jabber nick etc.
  • working hours? anyone working half-time? anyone with unusual working hours?
  • where? one room or many places
  • some people from other teams involved? independent consultants? some project partners (external companies) that we cooperate with?
  • what are the roles of people
  • who knows what?
  • are team members involved in other projects?
  • questions to ask to each team member:
    • what are you proud/angry/annoyed about? what (de)motivates you?
    • please draw the architecture of the system
    • please write down the "definition of done"
    • what issues do you think we have? what is the most common source of bugs? which bugs are the most annoying for us / for clients?

Meetings / Telcos

  • internal (only the team is involved) - Scrum - daily / sprint / backlog ?
  • with clients
  • with higher-ups?
  • traveling? where? for how long?
  • how are the invitations send? who sends them? who sets the agenda? who sends minutes (if any)? who attends?
  • how long is the meeting? who participates?

Documents

  • where can I find them, how are they generated, who maintains them?
  • technical documentation
  • user documentation
  • developers documentation
  • reporting - internal / external
  • templates - documents? mails? reports? presentations?
  • bug tracker - how are issues commented?
  • where is the database schema?

Infrastructure

  • SCM, FTP/WebDavs, Sonar, CI, bug tracker, artifacts repository, wiki
  • keystores, certificates
  • mailing lists (internal, external)
  • adresses, credentials, who creates accounts? who administrates?
  • environments - local, testing, production?
  • Can anyone, besides the team, access any of these (e.g. client reading bug tracker issues) ?

Processes

  • SCRUM? how does it really look like? how are user stories sized - hours or t-shirts (M, S, XL)? what meetings, how often etc., are daily standups held regularly
  • code reviews - formalized, informal, who does them? peer reviews? external audits of code?
  • any visualization tools? (well, these are the easiest to notice, aren't they?)
  • what is the "definition of done" of this team?
  • any special recruiting process for this team?
  • build process - automated?
  • How are versions/releases created? What is a naming pattern? Are there different internal (for team) and external (for client) versions? How can one learn about the changes between versions X and Y?
  • statuses of issues on issue tracker (e.g. todo, in progree, done, accepted etc.)
  • production deploy & rollback, tools used - Puppet, Liquidbase?
  • code conventions - format (Eclipse formatter?), checkstyle etc, but also use of TODO/FIXME tags in code
  • SCM (SVN/git) - branches? how/when created, when merged?
  • CI - schedules, how are they set?

Testing

  • unit
  • integration
  • end2end
  • does client test?
  • automation? which requirements functional and non functional are being automatically tested?
  • code coverage - how high, is it automatically calculated, is code coverage of different tests merged?

Development Tools

  • what tools/software is being used by team members
  • OS? IDE? build tools? testing libraries? mocking libraries? code review tools?
  • specific applications for Win (Visio?, Outlook?)

Problems

  • what we know? what are the main problems from our point of view? (e.g. internal code quality, our build process, client?), does client is aware of this?
  • recent problems, what were the causes, are they fixed?
  • what is the main concern of client?
  • common bugs, how many critical bugs, are they added to the current sprint?

Client(s)

  • communication - how do we communicate with clients? with whom exactly should I talk about certain topics? who has the right to make decisions?
  • communication - how does client communicates with us?
  • communication - what hours is he available? does he answer emails immediately?
  • what does he value, what are his goals?
  • does he own the code?
  • does he has a say in technologies we used, should we ask him for approval for new libraries/tools that we plan to use?
  • is it possible to negotiate the scope?

Next steps

  • What is the most pressing matter? Are we late with anything?
  • Any meetings/telcos ahead?

Architecture

  • software
  • hardware

2011/07/30

Java Tools: Source Code Optimization and Analysis


Below is a list of some tools that can help you examine your Java source code for potential problems:

2011/07/29

[Java] 字串半型轉全型

Problem
使用者希望所輸入的地址,在存入資料庫的時候,能夠將數字的部份轉成全型,這樣列印起來比較美觀。

How-To
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
    package gov.fdc.nig.web.util;  
    import org.apache.commons.lang.StringUtils;  
    /**  
    * 用於處理NIG系統內部字串  
    *  
    * @author albert  
    *  
    */  
    public class NIGStringUtils {  
          private static NIGStringUtils instance = new NIGStringUtils();  
          public static NIGStringUtils getInstance(){  
               return instance;  
          }  
          /**  
          * 將地址半型的數字轉成全型數字  
          *  
          * @param str String  
          * @return  
          */  
          public String covertToChineseFullChar(String str) {  
               String result = "";  
               if (StringUtils.isNotEmpty(str)) {  
                    char[] chars = str.toCharArray();  
                    for (int i = 0; i < chars.length; i++) { //bypass Chinese character   
                         if (chars[i] > '\200') {  
                              continue;  
                         }  
                         // 半型空白轉成全型空白  
                         if (chars[i] == 32) {  
                              chars[i] = (char) 12288;  
                              continue;  
                         }  
                         // 有定義的字、數字及符號  
                         if (Character.isLetterOrDigit(chars[i])) {  
                              chars[i] = (char) (chars[i] + 65248);  
                              continue;  
                         }  
                         // 其它不合要求的,全部轉成全型空白。  
                         chars[i] = (char) 12288;  
                    }  
                    result = String.valueOf(chars);  
               }  
               return result;  
          }  
     }  



2011/07/28

Handling JPA lifecycle event using listeners and callbacks

Problem
As we manipulate table, we need to insert values into user id(使用者代號), timestamp(西元年) and update date(民國年) as we do insert or update.
It's prone to forget to insert values to these columns.

Solution
Define setting value method and utilize JPA lifecyle to invoked automatically by JPA when these events occur.

JPA Lifecycle Events
Callback methods are user defined methods that are attached to entity lifecycle events and are invoked automatically by JPA when these events occur.

Internal callback methods should always return void and take no arguments. They can have any name and any access level (public, protected, package and private) but should not be static.

The annotation specifies when the callback method is invoked:
  • @PrePersist - before a new entity is persisted (added to the EntityManager).
  • @PostPersist - after storing a new entity in the database (during commit or flush).
  • @PostLoad - after an entity has been retrieved from the database.
  • @PreUpdate - when an entity is identified as modified by the EntityManager.
  • @PostUpdate - after updating an entity in the database (during commit or flush).
  • @PreRemove - when an entity is marked for removal in the EntityManager.
  • @PostRemove - after deleting an entity from the database (during commit or flush).

Implementation Restrictions
To avoid conflicts with the original database operation that fires the entity lifecycle event (which is still in progress) callback methods should not call EntityMan­ager or Query methods and should not access any other entity objects.

If a callback method throws an exception within an active transaction, the transaction is marked for rollback and no more callback methods are invoked for that operation.

How to do it
1. Define EntityListener class
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package gov.fdc.nig.domain.listener;

import gov.fdc.common.util.DateUtil;
import gov.fdc.nig.util.NigUtils;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.Timestamp;
import java.util.Calendar;

import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;

public class EntityListener {

 /**
  * Set date time and user id
  *
  * This method will be invoke before a new entity is persisted or
  * when an entity is identified as modified by the EntityManager
  *
  * @param obj Object
  * @throws IllegalArgumentException
  * @throws IllegalAccessException
  * @throws InvocationTargetException
  */
 @SuppressWarnings("unused")
 @PrePersist
 @PreUpdate
 private void setTimeAndUser(Object obj) throws IllegalArgumentException,
  IllegalAccessException, InvocationTargetException {
   Method methods[] = obj.getClass().getDeclaredMethods();
   String methodName = "";
   for (Method method: methods) {
    methodName = method.getName();
    if (methodName.matches("setUpdateDate")) {
     method.invoke(obj, DateUtil.getFormattedDate(NigUtils.getCurrentTimestamp(), "twyMMdd"));
    } else if (methodName.matches("setTimeStamp")) {
     method.invoke(obj, new Timestamp(Calendar.getInstance().getTime().getTime()));
    } else if (methodName.matches("setUserId")) {
     method.invoke(obj, NigUtils.getUser().getUserID());
    } else if (methodName.matches("setUpdateUserCd")) {
     method.invoke(obj, NigUtils.getUser().getUserID());
    }
   }
  }
}


2. add @EntityListeners({EntityListener.class}) annotation to each entity class

1
2
3
4
5
6
7
8
9
package gov.fdc.nig.domain;
@Entity
@EntityListeners({
 EntityListener.class
})
@Table(name = "NIGT036", schema = "AP_TAX")
public class Nigt036 extends DomainBase {
 //............
}

Therefore, we don't need to set these columns in controller class. And we won't forget to set values to theses columns again.

Using jQuery and Ajax to load sub-sections of a webpage

Ajax powered tab sets

Tabs can; broadly-speaking, be loaded in three different ways:
  • Immediately loaded – i.e. when the webpage has loaded, it is the default selected tab.
  • Later (deferred loading) – i.e. after the user clicks a tab, go off to the server and retrieve the contents of a tab, or
  • Lazy loading – e.g. load in the background before the user clicks a tab. This enhances the user experience as the contents of a tab are immediately shown, but on the flip side means requires more traffic and the user may never click the tab anyway, effectively wasting bandwidth.
In this case, we choose the third approach to implement (Lazy loading)

Scenario
We have four tabs in our page, the screen shots are as bellowing:




Solution
Here’s a javascript (using jQuery) implementation of the above which supports "lazy loading"

nig.nig451w.js

$(document).ready(function() {
$( "#tabs" ).tabs();
}


JSP relationships

Then the next thing to do is to add some HMTL to the page to act as tabs:


WELL DONE!

2011/07/26

Controlling the width/height of the button

Problem
By default, the dimensions of the button is automatically set to the dimensions required to accommodate the content inside, such as an image. But my length of text is larger than the default width of button.
The html is as bellows:

Solution
There will often be times when you want to manually control this dimension to fit your design. By using another CSS declaration, you can. To control the width/height of the button, use the following style declaration:

Therefore, my html will be looked like this way

Demo

The Principles of Good Programming

http://www.artima.com/weblogs/viewpost.jsp?thread=331531

1. DRY - Don’t repeat yourself
2. Abstraction Principle
3. KISS (Keep it simple, stupid!)
4. Avoid Creating a YAGNI (You aren’t going to need it)
5. Do the simplest thing that could possibly work
6. Don’t make me think
7. Open/Closed Principle
8. Write Code for the Maintainer
9. Principle of least astonishment
10. Single Responsibility Principle
11. Minimize Coupling
12. Maximize Cohesion
13. Hide Implementation Details
14. Law of Demeter
15. Avoid Premature Optimization
16. Code Reuse is Good
17. Separation of Concerns
18. Embrace Change

2011/07/25

Building DropDown Menu Using jQuery and JSON

Scenario
We have six dropdown menus where we populate violation number (違章編號) and will be triggered on onBlur event.

Screenshot


jQuery
jQuery is a light weight JavaScript library that simplifies the client side DOM manipulation, event handling, ajax communication easier and faster.

JSON
JSON means JavaScript Object Notation. It is a simple text based, human readable data format that is widely used in AJAX application to transfer data as an alternative to XML format. In simple words, it is simply key- value pairs, separated by commas and enclosed in curly braces.

NIG451W.jsp

nig.nig451w.js


Sequence Diagram


NIG451Controller.java
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  @Controller
  @RequestMapping("/front/NIG451W")
  public class NIG451Controller extends AbstractController {
      @SuppressWarnings("unused")
      @RequestMapping(value = "/autoCompleteDropdownMenu", method = RequestMethod.POST)
      private @ResponseBody
      void autoCompeleteDropdownMenu(final NIG451DataBean formBean,
      final HttpServletResponse response) throws FDCDefineException,
      IllegalAccessException, InvocationTargetException, IOException {
          //setup primary key
          Nigt001PK nigt001PK = new Nigt001PK(formBean.getDlvUnit(),
          formBean.getTaxCd(), formBean.getDlvYr(), formBean.getFlgTp(),
          formBean.getSerialNo());
          //do query based on the search criteria
          List nig451Beans = nig451Manager.autoCompeleteDropdownMenu(nigt001PK);
          
          JSONArray jsonArray = new JSONArray();
          
          for(NIG451Bean vo : nig451Beans){
              Map map = new HashMap();
              map.put("name", vo.getVioOrgNm());
              map.put("value", vo.getVioOrgCd());
              jsonArray.add(map);
          }
          
          response.setContentType(NigAccessKey.JKEY_CONTENT_TYPE);
          response.getWriter().write(jsonArray.toString());
      }
  }


NIG451ManagerImpl

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
  @Service
  public class NIG451ManagerImpl implements NIG451Manager {
      /*
      * (non-Javadoc)
      * @see gov.fdc.nig.punishment.service.NIG451Manager#autoCompeleteDropdownMenu(gov.fdc.nig.domain.Nigt001PK)
      */
      @Override
      public List autoCompeleteDropdownMenu(Nigt001PK nigt001pk) {
          return nigt001Dao.autoCompeleteDropdownMenu(nigt001pk);
      }
  }




Demo

Eugene H. Krabs

昨天看到一本書,上面是這樣寫的:『當一個人被剝奪做出重要決策的機會,它就會開始把所有能做的決定,都當成是重要決策。他會開始挑剔歸檔的方式,強烈希望每支鉛筆都被削的很尖,渴望確定窗戶事打開(或關上)的,並且傾向使用兩到三種不同顏色的筆。』

ㄎㄎㄎ,有點身歷其境的感覺唷

2011/07/22

Project Plan

長官們往往把規劃擱置一旁,總是先做當天沒這麼重要卻比較緊急的工作。
最後,等到不能再拖下去的時候,就匆匆忙忙地為重大任務訂出計畫,然後很不明智的把拙劣的計畫變成具體的、不能改變的目標,進而帶領團隊往這個目標前進。結果,任務還沒開始正式執行,整個團隊就因為準備不周而筋疲力竭。

緊急 != 重要

緊急的事情,不等於重要的事情。
常常總是在下午三、四點接到email,要在下午五點以前繳交報告或統計數據。此時,就要放下手邊重要的事情,去做長官交辦的緊急的事情,反倒讓重要的事情進度落後,長官在回過頭來檢討為什麼進度落後。這樣豈不荒謬、可笑!

Project Delay

在專案進度嚴重落後時,長官們總是為了要更進一步掌控各個組別的細部進度,了解問題出在哪裡,導致開會次數與報告書變多,因此最重要的工作反而無法進行。更嚴重的是,工作場所的工作氣氛會變得更惡劣,員工的工作動機也會下降,反而讓專案進度更加落後。
這樣的錯誤,總是在不同的公司,重複上演,沒有謝幕的一天。

Building Auto-Completion Using jQuery and JSON

Scenario
As I filled in violation number, system should fill out its related column on onBlur event of violation number(違章編號). [it will return single value, i.e. a Java bean class]


Sequence Diagram

How to do it
nig.nig451.js: will be triggered on onBlur event

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
  $(document).ready(function() {
      //略....
      $("#vioNumDlg").blur(function() {
       
         $.ajax({
           url: 'NIG451W/autoComplete',
           type: gsAjaxPost,
           data: formData,
           dataType: gsAjaxJson,
           contentType: gsAjaxContentType,
           //略...
           });
      });
  });


NIG451Controller: will be triggered when doing post over 'NIG451W/autoComplete' url pattern

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
   @RequestMapping(value = "/autoComplete", method = RequestMethod.POST)
   private @ResponseBody
   void autoCompletForm(final NIG451DataBean formBean,
                        final HttpServletResponse response) throws FDCDefineException,
                        IllegalAccessException, InvocationTargetException, IOException {
       //primary key
       Nigt001PK nigt001PK = new Nigt001PK(formBean.getDlvUnit(),
       formBean.getTaxCd(), formBean.getDlvYr(), formBean.getFlgTp(),
       formBean.getSerialNo());
       
       //service class will search by primary key and return a POJO class
       NIG451Bean result = nig451Manager.autoCompleteForNIG451(nigt001PK);
       
       //instantiate JSONObject object, and set result to it.
       JSONObject json = new JSONObject();
       json.put("result", result);
       
       //write json string to HttpServletResponse
       response.setContentType(NigAccessKey.JKEY_CONTENT_TYPE);
       response.getWriter().write(json.toString());
   }

nig.nig451.js:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
   $(document).ready(function() {
       //略....
       
       $("#vioNumDlg").blur(function() {
           //略....
           $.ajax({
               url: 'NIG451W/autoComplete',
               type: gsAjaxPost,
               data: formData,
               dataType: gsAjaxJson,
               contentType: gsAjaxContentType,
               success: function(jsonResult, status) {
                   //get values from json result
                   //syntax: jsonResult.[key value we set in JSON].[bean class attribute]
                   $("#manageCd").val(jsonResult.result.manageCd);
                   $("#vioYr").val(jsonResult.result.vioYr);
                   $("#vioHostNm").val(jsonResult.result.vioHostNm);
                   $("#vioHostIdnBan").val(jsonResult.result.vioHostIdnBan);
                   $("#respNm").val(jsonResult.result.respNm);
                   $("#respIdn").val(jsonResult.result.respIdn);
                   $("#respAddr").val(jsonResult.result.respAddr);
               },
               error: function(xhrInstance, status, xhrException) {
               }
           });
       });
   });



NIG451W.jsp

Check the result