Korean FAQ

자주 묻는 질문들(FAQ)

애플리케이션 서버

Q: JBoss 4.0 에 배포를 하려고 하면 에러가 납니다. 어떻게 해야 하나요?

JBoss의 통합 클래스 로더(unified class loader)는 Jar 파일들이 충돌하는 경우에 문제를 일으킬 수 있습니다. 특히 자주 발생하는 문제는 log4j에 관한 것입니다. 이 경우 배포된 .war 파일의 log4j.jar를 제거하면 해결됩니다.

또는 다음과 같이 "jboss-service.xml" 파일을 다음과 같이 변경하여 이 기능을 비활성화시키면 됩니다:

이 줄을:

<attribute name="UseJBossWebLoader">true</attribute>

아래와 같이 바꾸세요:

<attribute name="UseJBossWebLoader">false</attribute>

Q: Grails를 Oracle AS에 설치하려면 어떻게 해야 하나요?

Oracle 웹사이트에 Grails를 Oracle에 설치하기 라는 훌륭한 튜토리얼이 있습니다. 이 문서를 참고하세요.

뷰 관련 기술

Q: GSP(Groovy Server Pages)를 바로 보려면 어떻게 해야 하나요?

A: 해당 파일들을 Grails 애플리케이션의 web-app 디랙터리에 두어야 합니다.

콘트롤러

Q: 바이너리 파일을 클라이언트로 보내기 위해 render 메서드를 사용할 수 있습니까?

A: 현재는 불가능합니다. 하지만 ServletResponse 인스턴스를 이용하실 수 있습니다. 예를 들어 서버에서 zip 파일을 만들어서 클라이언트로 보내려면 다음과 같이 하시면 됩니다:

def createZip = {
  byte[] zip = createZipForClient() 
  response.contentType = "application/octet-stream"
  response.outputStream << zip
}

또는 다음과 같이 하셔도 됩니다:

response.setHeader("Content-disposition", "attachment; filename=" +
session.userid + ".csv");
render(contentType: "text/csv", text: "my,comma,seperated,variable,file");

Q: JFreeChart를 이용하여 Grails 애플리케이션에서 도표를 그릴 수 있습니까?

A: 물론 가능합니다! JFreeChart 로 차트 이미지를 만들고 HTTP 응답을 통해 전송하기만 하면 됩니다.

다음은 파이 차트를 생성하는 콘트롤러의 예제입니다:

import org.jfree.chart.ChartFactory
import org.jfree.data.general.DefaultPieDataset
import org.jfree.chart.encoders.EncoderUtil

class PiechartController {

    def index = {

        // create the data for the pie chart
        def slices = [
            [label:"One", percent:43.2],
            [label:"Two", percent:10.0],
            [label:"Three", percent:27.5],
            [label:"Four", percent:17.5],
            [label:"Five", percent:11.0],
            [label:"Six", percent:19.4]
        ]

        // load the data into a dataset
        def dataset = new DefaultPieDataset();
            slices.each { slice ->
            dataset.setValue(slice.label, slice.percent)
         }

         // create the pie chart and stream it back to the client
         def chart = ChartFactory.createPieChart("Pie Chart Demo 1", dataset, true, true, false)
         EncoderUtil.writeBufferedImage(chart.createBufferedImage(800, 600), "png", response.getOutputStream())
    }

}

위 코드를 실행하려면 Grails 애플리케이션의 libs 폴더 밑에 jfreechart-1.0.1.jar 파일과 jcommon-1.0.0.jar 파일을 복사해야 합니다.

Grails 객체-관계 매핑 (GORM)

Q: 일대다(one-to-many) 관계에서, 다(many) 측 객체 집합을 정렬하려면 어떻게 해야 하나요?

Author/Book 예제에서, Book이 Comparable 인터페이스를 구현하게 만든 후 Author의 books를 SortedSet으로 변경하세요:

class Author {
    Long id
    Long version

    def relatesToMany = [ books : Book ]

    String name
    SortedSet books
}

보안

Q: 제 애플리케이션에 보안을 적용하려면 어떻게 하나요?

Grails에서 보안을 처리하는 가장 일반적인 방법은 콘트롤러 인터셉터를 사용하는 것입니다. 선언적인 방식을 사용하고자 한다면 Acegi 같은 것을 이용할 수 있을 것입니다. 이 을 참고하시기 바랍니다.

Labels

 
(None)