【发布时间】:2016-10-07 17:18:28
【问题描述】:
我想知道当我单击按钮时是否可以调用托管 bean 中存在的方法(该按钮是用 Thymeleaf 创建的)。
谢谢
【问题讨论】:
标签: ejb thymeleaf managed-bean
我想知道当我单击按钮时是否可以调用托管 bean 中存在的方法(该按钮是用 Thymeleaf 创建的)。
谢谢
【问题讨论】:
标签: ejb thymeleaf managed-bean
我不知道是否有直接做的选项,我不这么认为。但解决方案可能更简单:为什么不将您的按钮提交到执行此方法的端点?
<button onclick="execute()">Click me</button>
<script>
function execute() {
//$.get() or
$.post( "/the/endpoint", function(data) {
$('#test').html(data);
});
}
</script>
那么/the/endpoint就是你的@Requestmethod,它在内部执行你想要的方法:
@Controller
public class YourController {
@GET
@Path("/the/endpoint")
public Response executeMethod() {
yourMethod(); //Executes your method
return Response.status(200);
}
}
【讨论】: