! . . Album Hình . . !

Tìm kiếm Những Gì Bạn Thích !

11 tháng 12, 2013

Javascript Validator problem in Eclipse

Right click vào Project chọn Properties chọn xuống chổ Builders sau đó bỏ check chọn chổ JavaScript Validator

7 tháng 12, 2013

Đánh số trang (PageNumber) từ 1 trang bất kỳ.


Ví dụ ở đây bạn muốn đánh trang số 1 bắt đầu từ trang thứ 3 thì làm như sau:
  1. Đưa con trỏ chuột vào trang thứ 2, Chọn qua thẻ Page Layout, Chọn Breaks, Chọn Next Page


  1. Click vào trang thứ 3, Chọn quan thẻ Insert, Chọn Page Number, Chọn Format Page Number

Một hộp thoại hiện ra như sau :

Nhớ chọn giống như hình trên : Start at: 1.
  1. Chọn nơi để chèn số trang: Trên (Top of page),  Dưới (Bottom of page),.., Ví dụ mình chọn chính giữa bên dưới



Khi đó số trang sẽ được đánh như sau:
Trang thứ 1
Đánh số 1
Trang thứ 2
Đánh số 2
Trang thứ 3
Đánh số 1
Trang thứ 4
Đánh số 2
Trang thứ 5
Đánh số 3


  1. Double click vào số 1trang thứ 3. Click vào nút
     để bỏ kết nối giữa các session sau khi mình break (Next Page).
  2. Double click vào số 1 ở trang thứ nhất xóa số trang này đi thì nó sẽ tự xóa tất cả số trang ở session thứ nhất (Session thứ nhất này mình gồm 2 trang đầu tiên) là xong.
Chú ý: Nếu không làm thao tác thứ 4 mà chỉ làm thao tác thứ 5 thì nó sẽ xóa hết các số trang => chưa đánh số trang.

28 tháng 11, 2013

Tomcat không kết nối được mysql

Mô tả lỗi:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have a n error in your SQL syntax; check the manual that corresponds to your MySQL serv er version for the right syntax to use near 'OPTION SQL_SELECT_LIMIT=DEFAULT' at line 1
Cách khắc phục:
  • Download Mysql Connector sau đó giải nén thành file .jar bỏ vào thư mục tomcat/lib/ext của tomcat.
  • Khởi động lại server tomcat là OK 

23 tháng 11, 2013

Mysql port xung đột khi cài Mysql Workbench với Mysql Xampp hoặc Wamp

Khi bạn cài MYSQL WORKBENCH vào cùng với XAMPP hoặc WAMP sẽ xãy ra tình trạng đụng port cơ sở dữ liệu 3306. Vì vậy để khắc phục lỗi này ta tắt 1 trong những dịch vụ.
 Sau đây là cách tắt service của MYSQL WORKBENCH để chạy MYSQL XAMPP.

  1. Nhấn tổ hợp phím "Lá cờ (gần nút Alt) + R", sau đó gõ services.msc.
  2. Tìm tới MySQL56, click chuột phải lên chọn Stop.
  3. Khởi động lại Mysql Xampp.

7 tháng 11, 2013

HƯỚNG DẪN KẾT HỢP JASPER REPORT VỚI DYNAMIC JASPER

1.     Thiết kế phần tỉnh của báo cáo
Chúng ta có thể dùng Ireport để design những phần thông tin tỉnh như  header hay footer, sau khi design xong ta lưu lại file với tên là file*.jrxml.
2.      Generate phần dữ liệu động lên mẫu tỉnh đã design
Tạo DynamicReport
DynamicReportBuilder drb = new DynamicReportBuilder();
Tạo các column động
ColumnBuilder columnName = ColumnBuilder.getNew();
columnName.setTitle("Name");
columnName.setWidth(180);
columnName.setFixedWidth(true);
columnName.setColumnProperty("name", String.class.getName());
columnName.setHeaderStyle(headerStyle);
                       
ColumnBuilder columnYear = ColumnBuilder.getNew();
columnYear.setTitle("Year");
columnYear.setWidth(180);
columnYear.setFixedWidth(true);
columnYear.setColumnProperty("year", Integer.class.getName());
columnYear.setHeaderStyle(headerStyle);
columnYear.setStyle(rightStyle);
                       
DynamicReport dr = drb.addColumn(columnName.build())
                                                .addColumn(columnYear.build())                                            .setPrintBackgroundOnOddRows(true).setUseFullPageWidth(true)
                                                .build();
for (int i = 1; i < 3; i++) {
            ColumnBuilder columnBuilder= ColumnBuilder.getNew();
            columnBuilder.setTitle("Column Add");
            columnBuilder.setColumnProperty("year"+i,Integer.class.getName());
            columnBuilder.setWidth(100);
            columnBuilder.setFixedWidth(true);
            drb.addColumn(columnBuilder.build());
}
Đọc file mẫu mình đã thiết kế các phần tỉnh
drb.setTemplateFile("E:\\Phien\\TemplateReports\\file*.jrxml");
Xuất ra file excel , word, pdf
JRDataSource ds = new JRBeanCollectionDataSource(listData);
JasperPrint jp = DynamicJasperHelper.generateJasperPrint(dr,new ClassicLayoutManager(), ds);
JasperViewer.viewReport(jp); // finally display the report report
JRXlsExporter exporter = new JRXlsExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,"d://design_jasper_sample_report1.xls");
exporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, true);
exporter.exportReport();

Lưu ý: Phải add thư viện DynamicJasper-5.0.0.jar với jasperreports-5.5.0 vào project

3 tháng 11, 2013

Upload, Download in Liferay JSF


  • File resource_handler
public class App3ResourceHandler extends ResourceHandlerWrapper {
        public static final String LIBRARY_NAME_BCTHSD = "THSD";
public static final String FileDownload = "Download";
// Logger
private static final Logger logger = LoggerFactory
.getLogger(App3ResourceHandler.class);

// Private Data Members
private ResourceHandler wrappedResourceHandler;

public App3ResourceHandler(ResourceHandler wrappedResourceHandler) {
this.wrappedResourceHandler = wrappedResourceHandler;
}

@Override
public Resource createResource(String resourceName, String libraryName) {

if (libraryName.equals(LIBRARY_NAME_BCD)) {
if (BaoCaoDongExel.RESOURCE_NAME.equals(resourceName)) {
try {
BaoCaoDongBean baocaoSLTSTGBHBean = (BaoCaoDongBean) FacesContext
.getCurrentInstance().getExternalContext()
.getSessionMap().get("baocaodongbean");
Resource re = baocaoSLTSTGBHBean.getExport();
return re;
} catch (Exception e) { //
// TODO: handle exception return
wrappedResourceHandler.createResource(resourceName,
libraryName);
}
} else {
return wrappedResourceHandler.createResource(resourceName,
libraryName);
}
} else if (libraryName.equals(LIBRARY_NAME_BCTHSD)) {
if (BCTHSD_Export_Resource.RESOURCE_NAME.equals(resourceName)) {
try {
BaoCaoTinhHinhSuDungBean baocaoTHSDBean = (BaoCaoTinhHinhSuDungBean) FacesContext
.getCurrentInstance().getExternalContext()
.getSessionMap().get("baoCaoTinhHinhSuDungBean");
Resource re = baocaoTHSDBean.getExport();
return re;
} catch (Exception e) { //
// TODO: handle exception return
wrappedResourceHandler.createResource(resourceName,
libraryName);
}
} else {
return wrappedResourceHandler.createResource(resourceName,
libraryName);
}
}
return wrappedResourceHandler.createResource(resourceName, libraryName);
}
@Override
public void handleResourceRequest(FacesContext facesContext)
throws IOException {

ExternalContext externalContext = facesContext.getExternalContext();
String libraryName = externalContext.getRequestParameterMap().get("ln");
String resourceName = externalContext.getRequestParameterMap().get(
"javax.faces.resource");

String folderName = externalContext.getRequestParameterMap().get("BC1");

Resource resource = createResource(resourceName, libraryName);

ReadableByteChannel readableByteChannel = null;

WritableByteChannel writableByteChannel = null;
InputStream inputStream = null;
int bufferSize = 1024;
ByteBuffer byteBuffer = ByteBuffer.allocate(bufferSize);
try {
// Open an input stream in order to read the resource's
// contents/data.
if (libraryName.equalsIgnoreCase(FileDownload)) {
String path = FacesContext.getCurrentInstance()
.getExternalContext().getRealPath("");

if (folderName.equalsIgnoreCase("none")) {
path = path + File.separator + resourceName;
} else {
path = path + File.separator + folderName + File.separator
+ resourceName;
}

try {
File file = new File(path);
inputStream = new FileInputStream(file);
} catch (IOException e) {
// TODO: handle exception
System.out
.println("Rat tiec toi khong tim thay file ban can!");
}

} else {
inputStream = resource.getInputStream();
}

if (inputStream != null) {

// Set the response buffer size.
int responseBufferSize = byteBuffer.capacity();
externalContext.setResponseBufferSize(responseBufferSize);

String responseContentType = resource.getContentType();
externalContext.addResponseHeader("Content-Disposition",
"attachment; filename=" + resourceName);

if (responseContentType != null) {
externalContext.setResponseContentType(responseContentType);
}

// Copy the bytes in the resource's input stream to the
// response's output stream.
int responseContentLength = 0;
readableByteChannel = Channels.newChannel(inputStream);
writableByteChannel = Channels.newChannel(externalContext
.getResponseOutputStream());

int bytesRead = readableByteChannel.read(byteBuffer);
int bytesWritten = 0;

while (bytesRead != -1) {
byteBuffer.rewind();
byteBuffer.limit(bytesRead);

do {
bytesWritten += writableByteChannel.write(byteBuffer);
} while (bytesWritten < responseContentLength);

byteBuffer.clear();
responseContentLength += bytesRead;
bytesRead = readableByteChannel.read(byteBuffer);

if (logger.isTraceEnabled()) {

// Surround with isTraceEnabled check in order to avoid
// unnecessary conversion
// of int to String.
logger.trace("Handling - MORE bytesRead=[{0}]",
Integer.toString(bytesRead));
}
}

// Now that we know how big the file is, set the response
// content length.
externalContext.setResponseContentLength(responseContentLength);
externalContext.setResponseStatus(HttpServletResponse.SC_OK);

logger.debug(
"HANDLED (SC_OK) resourceName=[{0}], libraryName[{1}], responseContentType=[{2}], responseContentLength=[{3}]",
new Object[] { resourceName, libraryName,
responseContentType, responseContentLength });
}
} catch (IOException e) {
externalContext.setResponseStatus(HttpServletResponse.SC_NOT_FOUND);
logger.error(
"NOT HANDLED (SC_NOT_FOUND) resourceName=[{0}], libraryName[{1}], errorMessage=[{2}]",
new Object[] { resourceName, libraryName, e.getMessage() },
e);
} finally {

if (writableByteChannel != null) {
writableByteChannel.close();
}

if (readableByteChannel != null) {
readableByteChannel.close();
}

if (inputStream != null) {
inputStream.close();
}
}
}

@Override
public boolean libraryExists(String libraryName) {

if (LIBRARY_NAME.equals(libraryName)) {
return true;
} else {
return super.libraryExists(libraryName);
}
}

@Override
public ResourceHandler getWrapped() {
return wrappedResourceHandler;
}
}
  • File resource
public class BaoCaoDongExel extends Resource {
public static final String CONTENT_TYPE = "application/vnd.ms-excel";
public static final String RESOURCE_NAME = "BaoCao.xls";
 private String requestPath;
public BaoCaoDongExel() {
setLibraryName(App3ResourceHandler.LIBRARY_NAME_BCD);
setResourceName(RESOURCE_NAME);
setContentType(CONTENT_TYPE);
if (!Validator.isNull(listData)) {
this.listData.clear();
}
}
@Override
public InputStream getInputStream() throws IOException {
byte[] excel = new byte[] {};
try {
// code tạo file xuất ra ở đây

ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
wb.write(byteArrayOutputStream);
excel = byteArrayOutputStream.toByteArray();

} catch (Exception e2) {
System.out.println("co loi trong " + getClass().getName() + "\n"
+ e2);
}

return new ByteArrayInputStream(excel);
}


@Override
public String getRequestPath() {
if (requestPath == null) {
StringBuilder buf = new StringBuilder();
buf.append(ResourceHandler.RESOURCE_IDENTIFIER);
buf.append("/");
buf.append(getResourceName());
buf.append("?ln=");
buf.append(getLibraryName());
buf.append("&");
buf.append("BC1");// chua hieu
buf.append("=");
buf.append(Math.random());
requestPath = buf.toString();
}

return requestPath;
}

@Override
public Map getResponseHeaders() {
// TODO Auto-generated method stub
return null;
}

@Override
public URL getURL() {
// TODO Auto-generated method stub
return null;
}

@Override
public boolean userAgentNeedsUpdate(FacesContext arg0) {
// TODO Auto-generated method stub
return false;
}

}
  • File bean
Lưu ý là sessionscope
private BaoCaoDongExel export;

public BaoCaoDongExel getExport() {
export = new BaoCaoDongExel(các tham số truyền qua tương ứng);
return export;
}

public void setExport(BaoCaoDongExel export) {
this.export = export;
}
-  Download Bean
@ManagedBean (name="downloadBean")
public class DownloadBean {
public String getLink(String folder, String fileName) {
String link1 = null;
if (link1 == null) {
StringBuilder buf = new StringBuilder();
buf.append(ResourceHandler.RESOURCE_IDENTIFIER);
buf.append("/");
buf.append(fileName);
buf.append("?ln=");
buf.append(App3ResourceHandler.FileDownload);
buf.append("&");
buf.append("BC1");
buf.append("=");
buf.append(folder);
link1 = buf.toString();
}

return link1;
}
}
  • File view
- Nếu file đã có sẳn thì down theo đường dẫn nó.
style="display:#{tailieu.existFile=='TRUE'?'block':'none'}"
value="#{downloadBean.getLink(customUtils.GetFolderUpload(),tailieu.tenFileLuu)}">

1 tháng 11, 2013

Microsoft Office Content-Type

Ext
MIME Type
.doc
application/msword
.dot
application/msword
.docx
application/vnd.openxmlformats-officedocument.wordprocessingml.document
.dotx
application/vnd.openxmlformats-officedocument.wordprocessingml.template
.docm
application/vnd.ms-word.document.macroEnabled.12
.dotm
application/vnd.ms-word.template.macroEnabled.12
.xls
application/vnd.ms-excel
.xlt
application/vnd.ms-excel
.xla
application/vnd.ms-excel
.xlsx
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.xltx
application/vnd.openxmlformats-officedocument.spreadsheetml.template
.xlsm
application/vnd.ms-excel.sheet.macroEnabled.12
.xltm
application/vnd.ms-excel.template.macroEnabled.12
.xlam
application/vnd.ms-excel.addin.macroEnabled.12
.xlsb
application/vnd.ms-excel.sheet.binary.macroEnabled.12
.ppt
application/vnd.ms-powerpoint
.pot
application/vnd.ms-powerpoint
.pps
application/vnd.ms-powerpoint
.ppa
application/vnd.ms-powerpoint
.pptx
application/vnd.openxmlformats-officedocument.presentationml.presentation
.potx
application/vnd.openxmlformats-officedocument.presentationml.template
.ppsx
application/vnd.openxmlformats-officedocument.presentationml.slideshow
.ppam
application/vnd.ms-powerpoint.addin.macroEnabled.12
.pptm
application/vnd.ms-powerpoint.presentation.macroEnabled.12
.potm
application/vnd.ms-powerpoint.template.macroEnabled.12
.ppsm
application/vnd.ms-powerpoint.slideshow.macroEnabled.12

25 tháng 9, 2013

Adding Internal JARs in Java Application


    1. Create a new folder named lib in your project folder. This stands for "libraries" and will contain all the JARs you'll be using for that project.

    2. Copy the JARs you need to lib.

    3. Refresh your project by right clicking the project name and selecting Refresh. Thelib folder will now be visible in Eclipse with the JARs inside.

  1. 2
    Complete either of the following methods to finish configuring your build path.

Method 1

  1. 1
    Expand lib in Eclipse and select all the JARs you need.

  2. 2
    Right-click the JARs and navigate to Build Path.

  3. 3
    Select Add to Build Path. The JARs will disappear from lib and reappear in Referenced Libraries.

Method 2

  1. 1
    Right click the project name and navigate to Build Path.

  2. 2
    Select Configure Build Path... and the project properties window will appear showing your build path configurations.


  3. 3
    Select the Libraries tab.

  4. 4
    Click Add JARs...

  5. 5
    Locate and select the JARs you want and click OK. The JARs will now appear in the list of libraries in the build path.


  6. 6
    Click OK to close the properties window. The JARs will now be in Referenced Libraries instead of lib.

Adding External JARs

Note: It is much better to reference JARs that exist in your project or in other projects - this allows you to check in all of your dependencies to your version control system. (You are using version control, right?)
Use one of the following methods.

Method 1

This is the preferred method, as it allows different developers of a common project to locate their external jars in different places.
  1. 1
    Right click the project name and navigate to Build Path.

  2. 2
    Select Configure Build Path... and the project properties window will appear showing your build path configurations.

  3. 3
    Click Add Variable...

  4. 4
    Click Configure Variables...

  5. 5
    Click New...

  6. 6
    Type a name for the new variable. For example, if these are JARs for Tomcat, perhaps call it TOMCAT_JARS

  7. 7
    Browse to the directory that contains the JAR for the path. (You can also select a specific jar file for the variable, if you prefer.)

  8. 8
    Click Ok to define the variable.

  9. 9
    Click Ok to close the preferences dialog.

  10. 10
    Select the variable from the list.

  11. 11
    Click Extend...

  12. 12
    Select the JAR(s) that you want to add to the classpath.

  13. 13
    Click Ok to close the extend dialog.

  14. 14
    Click Ok to close the new classpath variable dialog.

  15. 15
    Click Ok to close the build path setup dialog.
If you share the project with someone else, they must also define the variable. They can define it under
Window->Preferences->Java->Build Path->Classpath Variables

Method 2

Note that if you use this method, the external JAR will need to be in the same location on the hard drive for anyone who uses this project. This can make sharing a common project more difficult.
  1. 1
    Right click the project name and navigate to Build Path.

  2. 2
    Select Add External Archives...



  3. 3
    Locate and select the JARs you want and click Open. The JARs will now appear inReferenced Libraries.

Method 3

Note that if you use this method, the external jar will need to be in the same location on the hard drive for anyone who uses this project. This can make sharing a common project more difficult.
  1. 1
    Right-click the project name and navigate to Build Path.

  2. 2
    Select Configure Build Path... and the project properties window will appear showing your build path configurations.

  3. 3
    Select the Libraries tab.

  4. 4
    Click Add External JARs...

  5. 5
    Locate and select the JARs you want and click Open. The JARs will now appear in the list of libraries in the build path.


  6. 6
    Click OK to close the properties window. The JARs will now be in Referenced Libraries.

Hướng dẫn đăng nhận xét của bạn

  • Nếu muốn đăng nhận xét của mình các bạn click vào "Xem và nhận xét ở đây" dưới mỗi bài đăng, sau đó hộp thoại xuất hiện bạn gõ vào những nhận xét của mình. thế là xong! cảm ơn các bạn đã ghé thăm blog của mình !