install tinymce pada thymeleaf | java php laravel linux mysql sql bootstrap html css query java php laravel linux mysql sql bootstrap html css query: install tinymce pada thymeleaf

Wednesday, June 1, 2016

install tinymce pada thymeleaf

Coba tinymce pada thymeleaf

Bismillah

Sebelumnya sudah mencoba untuk menggunakan tinymce di html biasa ( tinymce pada html ), 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 :

[sourcecode language="java"]@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*/


}[/sourcecode]

q> Ini coding untuk htmlnya :

[sourcecode language="java"]

<!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>

[/sourcecode]

q> Dan ini untuk controllernya :


[sourcecode language="java"]@RequestMapping(value = "/cobatiny", method = RequestMethod.GET)
public String cobaTinyMce(){
return "cobatiny";
}[/sourcecode]


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

q> Dan hasilnya adalah :
coba_tinymce_thymeleaf



Alhamdulillah

No comments:

Post a Comment

saifiahmada.com adalah blog belajar programming Indonesia, membahas lengkap materi bahasa pemrograman: code HTML, CSS, Bootstrap, Desain, PHP, MySQL, coding Java, Query, SQL, dan dunia linux