install tinymce pada thymeleaf

Coba tinymce pada thymeleaf

Bismillah

Sebelumnya sudah mencoba untuk menggunakan tinymce di html biasa, bagaiama klo di Thymeleaf ?

q> Konsepnya sama dengan menggunakan di html

q> Donwload , extract, kemudian panggil pada file htmlnya

q> Karena thymeleaf disini menggunakan spring boot, maka kita tambahkan registry untuk resourceHandlernya seperti ini :

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {

registry.addResourceHandler("/bootstrap/**").addResourceLocations("classpath:/static/bootstrap/3.1.0/");
registry.addResourceHandler("/jq/**").addResourceLocations("classpath:/static/jquery/");
registry.addResourceHandler("/jqueryui/**").addResourceLocations("classpath:/static/jqueryui/");
registry.addResourceHandler("/images/**").addResourceLocations("classpath:/static/images/");
registry.addResourceHandler("/datepicker/**").addResourceLocations("classpath:/static/datepicker/");
registry.addResourceHandler("/css/**").addResourceLocations("classpath:/static/css/");
registry.addResourceHandler("/tinymce/**").addResourceLocations("classpath:/static/tinymce/");
/*linux*/
//registry.addResourceHandler("/foto/**").addResourceLocations("file:///home/saifi/Desktop/foto/");
/*windows*/


}

q> Ini coding untuk htmlnya :


<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<title>Coba TinyMce</title>
<link rel="stylesheet" th:href="@{/bootstrap/css/bootstrap.min.css}" />
<script type="text/javascript" th:src="@{/bootstrap/js/bootstrap.min.js}"></script>
<script type="text/javascript" th:src="@{/tinymce/js/tinymce/tinymce.min.js}"></script>

<script type="text/javascript">
tinymce.init({
selector: '#mytextarea',
images_upload_base_path: '/some/basepath'
});
</script>
</head>
<body>

<div th:include="header :: header"></div>
<div class="container">
<h1 th:inline="text">Coba TinyMce</h1>
<form action="" th:action="@{/soal/processtiny/}" method="post">
<textarea id="mytextarea" name="data" rows="" cols=""></textarea><br/>
<input type="submit" value="Kirim" class="btn btn-success" />
</form>
<label th:text="${hasil}">tes</label>

</div>

</body>
</html>

q> Dan ini untuk controllernya :

@RequestMapping(value = "/cobatiny", method = RequestMethod.GET)
public String cobaTinyMce(){
return "cobatiny";
}
@RequestMapping(value = "/processtiny", method = RequestMethod.POST)
public String processTiny(@RequestParam("data") String data, Model model){
model.addAttribute("hasil", data);
return "cobatiny";
}

q> Dan hasilnya adalah :
coba_tinymce_thymeleaf

 

Alhamdulillah

Published by

saifiahmada

Begin a big Process with a bit trying

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s