返回列表 发帖

[原创] [原创]Grails+FCKeditor

Grails中配置FCKeditor时,需要下载FCK的插件才能进行使用。
1)创建一个web工程:grails create-app FCKDemo
2)进入FCKDemo的目录:cd FCKDemo
3)安装FCKeditor插件:grails install-plugin fck-editor
几分钟后安装完毕,grails会新建一个文件夹FCKDemo\plugins,在该文件夹下放置下载的插件。
4)在FCKDemo\grails-app\conf下修改Config.groovy,在其最后添加一行:web.app.context.path=FCKDemo 因为项目的名称为FCKDemo,因此其代表web工程名称。
5)创建一个Domain Classgrails create-domain-class Article
编辑Article.groovy文件:
   class Article {
      String title
      String content
      Date CurrentDate

      static constraints = {
          title (blank:false)
         content (blank:false,maxLength:2048)
      }
}
6)生成ArticleController和页面:grails generate-all Article
(7) 修改FCKDemo\grails-app\views\articlecreate.gsp
将:
                            <tr class="prop">
                                <td valign="top" class="name">
                                    <label for="content">Content:</label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean:article,field:'content','errors')}">
                                    <input type="text" id="content" name="content" value="${fieldValue(bean:article,field:'content')}"/>
                                </td>
                            </tr>
改为:
                            <tr class="prop">
                                <td valign="top" class="name">
                                    <label for="content">Content:</label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean:article,field:'content','errors')}">
                                    <fck:editor id='content' name='content' height="400" >${article.content}</fck:editor>
                                </td>
                            </tr>

修改FCKDemo\grails-app\views\articleeditor.gsp
将:
                            <tr class="prop">
                                <td valign="top" class="name">
                                    <label for="content">Content:</label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean:article,field:'content','errors')}">
                                    <input type="text" id="content" name="content" value="${fieldValue(bean:article,field:'content')}"/>
                                </td>
                            </tr>
改为:
                            <tr class="prop">
                                <td valign="top" class="name">
                                    <label for="content">Content:</label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean:article,field:'content','errors')}">
                                    <fck:editor id='content' name='content' height="400" >${article.content}</fck:editor>
                                </td>
                            </tr>

8)部署web工程:grails run-app
在浏览器下输入:http://localhost:8080/FCKDemo

测试创建一个article的页面

编辑该页面

Update后的结果

附件:
天行健,君子以自强不息
地势坤,君子以厚德载物
   黑色海岸线欢迎您

返回列表 回复 发帖