วันอาทิตย์ที่ 9 กันยายน พ.ศ. 2555

การเพิ่ม font ภาษาไทย เพื่อใช้ใน jasper report ใน Project ในรูปแบบ jar




ในการใช้งาน Jasper Report ส่วนมาก report เราเป็นภาษาไทยดังนั้นการทำให้เป็นภาษาไทยเราต้องเปลี่ยนประเภท font   วิธีการเพิ่ม font เข้าไปใน project ที่เราทำงานอยู่มีอยู่หลายวิธีแต่วิธีที่ผมจะแนะนำเป็นวิธิีที่ง่ายและทำได้รวดเร็วใช้ได้ทั้ง desktop และ web application มีวิธีการ 2 ช่วงคือ

  1.    เพิ่ม font เพื่อใช้ในการออกแบบ jasper report ผมว่าส่วนนี้เข้าใจว่า มือใหม่อาจจะไม่รู้ผมเลยเพิ่มเติมให้
  2.   ส่วนนี้เป็นการนำ font ที่ใช้ในการออกแบบ export เป็น jar แล้วนำมาเข้า project  หลายๆท่านอาจจะรู้แล้วนะครับ แต่ว่ามีอาจจะมีหลายท่านที่ไม่รู้


เรามาเริ่มช่วงที่ 1. การเพิ่ม font






  1. เลือก font ที่เราต้องการใช้ใน project แล้ว
  2. เลือก Tool -> Options
  3. เลือก tab Jasper Report  ใน tab Jasper Report  ก็จะมี tab ให้เลือก font
  4. เพิ่ม font ที่เราเลือกไว้โดยการ คลิก Button Install Font
  5. Netbean ทำการแสดง แสดงหน้าจอเพื่อให้ใส่ font ที่เราต้องการใช้งาน โดยมีลำดับดังต่อไปนี้
    5.1  เลือก font


  5.2  มีช่องให้ใส่ font แต่ละประเภท Bold,Italic,Bold Italic
5.3 เลือก Locale ถ้าเราต้องการแสดงผลประเภทวันเดือนปีสามารถตั้งได้ที่นี้ครับ
5.4 สิ้นสุดการเพิ่ม font

เมื่อเสร็จสิ้นกระบวนการนี้ก็สามารถนำ font ไปใช้ในการออกแบบได้ครับ

ช่วงที่ 2 การ คือการ นำไฟล์ jar ที่ได้จากการ export เอาเข้าไปไว้ใน project มีรายละเอียดดังนี้

  1. เลือก Tool -> Options
  2. เลือก tab Jasper Report  ใน tab Jasper Report  ก็จะมี tab ให้เลือก font

  3.  เลือก font ที่ต้องการ export เป็น jar ไฟล์  และทำการ click  Button "Export ass extension" ตรงด้าน ขวามือของ รายการ
  4. Netbean จะแสดงช่องให้เราเลือกตำแหน่งท่ี่จะเก็บ jar file  ตอนจะ save ให้เลือก Files of Type เป็น *.jar, *.zip นะครับ
  5. เมือ save ไฟล์ได้แล้วก็สามารถนำ file.jar ที่จะบันทึกไว้นำเข้า project เราก็จะสามารถใช้งาน font ที่ต้องการได้ครับ
 ท่านสามารถติดตาม เทคนิคต่างๆ ในการงาน ด้าน java ได้ที่ http://www.facebook.com/groups/javaplatforminth/

และสุดท้ายผมขอขอบคุณทุกท่านที่นำ เทคนิคต่างๆนำมาแบ่่งปันกัน





วันพุธที่ 12 มกราคม พ.ศ. 2554

Active Directory on Glassfish

<auth-realm name="active" classname="com.sun.enterprise.security.auth.realm.ldap.LDAPRealm"> <- not change
<property name="jaas-context" value="ldapRealm" /> <- not change
<property name="base-dn" value="DC=ce,DC=kmutnb,DC=ac,DC=th" /> <- change to your domain
<property name="directory" value="ldap://x.x.x.x:3268" /> <- your domain name or ip but your port use 3268
<property name="search-filter" value="(&amp;(objectCategory=user)(sAMAccountName=%s))" /> <- not change
<property name="group-search-filter" value="(&amp;(objectCategory=group)(member=%d))" /> <- not change
<property name="search-bind-password" value="password" /> <- your password
<property name="search-bind-dn" value="CN=Administrator,CN=Users,DC=ce,DC=kmutnb,DC=ac,DC=th" /> <- your user in active
<property name="assign-groups" value="Domain Users" /> <- your domain group in active directory
</auth-realm>

วันอาทิตย์ที่ 4 เมษายน พ.ศ. 2553

การตั้งค่าสำหรับ session mail สำหรับ glassfish

ต้องเพิ่มลงใน glassfish ดังต่อไปนี้


<property name="mail-smtps-socketFactory-class"
value="javax.net.ssl.SSLSocketFactory"/>

<property name="mail-smtps-auth" value="true"/>
<property name="mail-smtps-socketFactory-port" value="465"/>
<property name="mail-smtps-port" value="465"/>
<property name="mail-smtps-user" value="prady...@gmail.com"/>
<property name="mail-smtps-starttls-enable" value="true"/>
<property name="mail-smtps-socketFactory-fallback" value="false"/ >
http://picasaweb.google.com/pradyutb/OopPraddy?authkey=Gv1sRgCOKBjZTD9db1bA&feat=directlink#5312016739707868290

การส่ง email ผ่าน spring

จากค่าืพื้นฐานต่างๆแล้วต้องมีการเิพิ่มค่าดังต่อไปนี้ด้วย
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.starttls.enable">true</prop>
</props>
</property>

วันพุธที่ 10 กุมภาพันธ์ พ.ศ. 2553

ตัวอย่างการเปลี่ยน instance binding ของ swing

List bindings = bindingGroup.getBindings(); //เรียก binding จาก bindingGroup
//หา binding อันไหนที่ต้องการเปลี่ยน instance
for(Binding binding : bindings){
binding.unbind();
Object obj = binding.getSourceObject();
if( obj instanceof Vector){
Vector vector = (Vector) obj;
if(vector.size() > 0 && vector.lastElement().getClass().toString().equals("class databaseconnection.model.Gis")){
if(gisList.size() == 0){
gisList.add(new Gis());
}
binding.setSourceObject(gisList); // เลือก instance ตัวไหม่ที่ต้องการ binding
}


}
//ยืนยันการเปลี่ยน
binding.bind();
}

วันจันทร์ที่ 23 พฤศจิกายน พ.ศ. 2552

Use NetBeans IDE 6.7 to Combine JAR Files Into a Single JAR File

The Java Warehouse is the repository for Java and JavaFX applications submitted by developers for distribution through the Java Store to hundreds of millions of desktops worldwide. The Java Warehouse Developer Center Release Notes make clear that there is currently no way to upload applications composed of several Java Archive (JAR) files into the Java Warehouse. However, there is a workaround: Just concatenate each of the user and library classes into a single JAR file. This is very easy to do for both Java and JavaFX projects using NetBeans IDE 6.7.1.

To demonstrate how to do this, let's use one of the sample Java projects that is included in the NetBeans IDE 6.7.1 distribution: the Mars Rover Viewer. Open the NetBeans IDE, select File > New Project, then scroll down to the Samples folder and choose Java from the Categories pane. From there, select Mars Rover Viewer in the Projects pane and click Next, as shown in Figure 1. Next, choose a suitable location for the project and click Finish.

Creating the Mars Rover Viewer Sample Project in NetBeans
Figure 1 - Creating the Mars Rover Viewer Sample Project in NetBeans.

We've chosen this project because it makes use of a popular compile-time library that is not included with the standard Java Development Kit (JDK): the Swing Application Framework. To verify that this library is being used, right-click on the project in the upper left pane and choose Properties. From there, select Libraries on the left pane to verify that the Swing Application Framework is indeed listed, as shown in Figure 2. Then click OK to close the Project Properties dialog box.

The Mars Rover Viewer Application Uses the Swing Application Framework Library
Figure 2 - The Mars Rover Viewer Application Uses the Swing Application Framework Library.

In order to bundle all of the libraries into a single JAR file, you will need to edit the project's Ant file, which is called build.xml. Choose the Files tab in the Project window in the upper left, then expand the project tab if necessary to show the build.xml file. Double-click this file to edit it in the source-code editor pane and scroll down to the bottom. Now copy and paste the following text to the end, just before the final line, which is the closing tag:

                                                                                                                                                                                                                             

Note that you must change the following line in the Ant code above to match your particular project.

The property store.jar.name specifies the name of the JAR file that will be created in the store directory — change the value to whatever name you like. After you have changed this name, save the build.xml file. Figure 3 shows the additions to the build.xml file for the sample MarsRoverViewer project relative to the closing tag.

Additions to the Project's build.xml File Relative to the Closing Tag
Figure 3 - Additions to the Project's build.xml File Relative to the Closing Tag.

From here, you can continue normal development, editing Java source files and compiling and running as necessary. Figure 4 shows the Mars Rover Viewer application fully built and running within the NetBeans IDE.

Running the Mars Rover Viewer Within the NetBeans IDE
Figure 4 - Running the Mars Rover Viewer Within the NetBeans IDE.

When you're ready to package all of the classes and libraries into a single JAR file, switch back to the Files view in the upper left, then right-click the build.xml file. Choose Run Target, scroll down to select Other Targets, then choose package-for-store, as shown in Figure 5, to execute the target. In this case, package-for-store is the name of the Ant target that you created previously in the project build.xml file.

Executing the package-for-store Ant Target From the Files Tab Inside the NetBeans IDE
Figure 5 - Executing the package-for-store Ant Target From the Files Tab Inside the NetBeans IDE.

Executing this Ant target will create a directory called store inside your project directory. NetBeans and Ant will then copy all of the classes and libraries into a temporary JAR file and strip out any unwanted files, placing the final result under the JAR name that you specified earlier. NetBeans will then delete the temporary file. The results are shown in Figure 6.

The Final JAR File, Ready to Upload to the Java Warehouse
Figure 6 - The Final JAR File, Ready to Upload to the Java Warehouse.

That's all there is to it — you can use this JAR file to upload to the Java Warehouse. Note that if you get an error stating that the dist/lib directory was not found, you should check that you have indeed included other libraries in your project, as this is the location where their JAR files will be stored.

If you'd like to verify that the JAR file contains the appropriate libraries, you can use one of three methods:

  • Use the command-line tool: jar tvf (filename).
  • Use a number of OS-based tools to inspect the JAR files (or ZIP files, if you change the extension).
  • Double-click on the JAR file to be sure that the Java runtime can execute it.

For More Information



อ้างอิง
http://java.sun.com/developer/technicalArticles/java_warehouse/single_jar/

วิธีการรับค่า input จาก form ของ web ที่เป็นภาษาไทย ให้เป็น UTF-8

String value = request.getParameter("form");
try{
value = new String(value.getBytes("8859_1"), "UTF-8"); }catch(java.io.UnsupportedEncodingException e)
{
System.err.println(e);
}
หรือ
try {
request.setCharacterEncoding("UTF-8");
} catch (UnsupportedEncodingException ex) {
}