Issue
I have a main page with header, footer, left panel and main content. I want to dynamically change main content on click of left panel. For this I am using ajax call, ajax will call controller and controller will return jsp which I will replace in main content.
But the problem I am facing is that I am getting JSP properly if I am using purely html coding but if I use spring form it is not working.
Do I need to declared taglib in all jsp or only in Dashboard jsp.
If I declare taglib in all child jsp then it not working and I do not declare then form:input do not render in to html
Can we return jsp in ajax call to replace with main content because here it says only @ResponseBody (JSON) can be used in ajax call.
I am using ajax call because I don't want to reload all my header, footer and left panel because they will always remain same.
Ajax code
<script type="text/javascript">
$(".ldMainContent").click(function(){
var actionName = this.id;
actionName = "${pageContext.request.contextPath}/sadmin/forward/"+actionName;
$.ajax({
url:actionName,
type:"POST",
data:"URL",
success:function(result){
$("#mainContent").html(result);
}
});
});
</script>
I am using bootstrap in design
Solution
The content can be loaded using jQuery's load method.
The code will be
$(".ldMainContent").click(function(){
var actionName = this.id;
actionName = "${pageContext.request.contextPath}/sadmin/forward/"+actionName;
$("#mainContent").load(actionName);
})
In your controller don't have @ResponseBody
it is used to return object as JSON or XML. The controller should return a view for the JSP page which should only have the content that you want inside the mainContent
.
Do I need to declared taglib in all jsp or only in Dashboard jsp.
Yes you have to declare the taglibs which ever jsp file you are using the tags.
Answered By - Karthikeyan Vaithilingam
Answer Checked By - Candace Johnson (JavaFixing Volunteer)