vendredi 27 février 2015

Can I use a jsp:include to include an entire JSP page as tab content?

I'm trying to define JSP pages as content for my tabs using the "jsp:include" - like this (Note: "page0.jsp")...



<ul id="smTabs" class="nav nav-tabs" style="margin-bottom: 15px;">
<li class="active">
<a href="/#page0" data-toggle="tab">Page0</a>
</li>
-
-
-
<div id="smTabContent" class="tab-content">
<div class="tab-pane fade active in" id="page0">
<jsp:include page="page0.jsp" />
</div>


The problem:


When the user clicks on a tab, the "included" (i.e., "jsp:include") JSP page form fields are empty because the controller has not been initialized.


QUESTION:


What "href=" value will succeed in both revealing the tab contents (e.g., page0.jsp) and, as well, initialize the controller so the page is displayed properly with data?


(sort of a corollary question - what "href=" value or technique will allow this page to be navigated to from another page?)


Thanks for any help.


Here's what the empty form for page0.jsp looks like...


enter image description here


Here is what it should look like...


enter image description here






BELOW IS EXTRA INFORMATION IF INTERESTED...


Here is the tabbedPage.jsp



<%@taglib prefix="form" uri="http://ift.tt/IED0jK" %>
<%@taglib prefix="c" uri="http://ift.tt/QfKAz6" %>
<%@taglib prefix="spring" uri="http://ift.tt/18bwTB1" %>
<%@taglib prefix="fmt" uri="http://ift.tt/1bRkrVx" %>

<br/><br/><br/>

<div class="page-header"><h1>Tabbed Page Management</h1></div>

<div class="bs-component">
<ul id="smTabs" class="nav nav-tabs" style="margin-bottom: 15px;">
<li class="active">
<a href="/#page0" data-toggle="tab">Page0</a>
</li>
<li>
<a href="/#page1" data-toggle="tab">Page1</a>
</li>
<li>
<a href="/#page2" data-toggle="tab">Page2</a>
</li>
</ul>
<div id="smTabContent" class="tab-content">
<div class="tab-pane fade active in" id="page0">
<h4>${page0FormBean}</h4>
<jsp:include page="page0.jsp" />
</div>
<div class="tab-pane fade" id="page1">
<h4>${page1FormBean}</h4>
<jsp:include page="page1.jsp" />
</div>
<div class="tab-pane fade" id="page2">
<h4>${page2FormBean}</h4>
<jsp:include page="page2.jsp" />
</div>
</div>
</div>


here is the controller for "tabbedPage.jsp"...: TabbedPageController.java



import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@Scope("session")
public class TabbedPageController
{
private static final Logger LOG = Logger.getLogger("TabbedPageController");

@RequestMapping(value = {"/tabbedPage"}, method = RequestMethod.GET)
public String tabbedPage(ModelMap model, HttpSession session)
{
LOG.info("_________________________tabbedPage_________________________entering...");

return "tabbedPage";
}

}


Here is page0.jsp (one of the JSP pages included...i.e., via "jsp:include")



<%@taglib prefix="c" uri="http://ift.tt/1gmwKNi" %>
<%@taglib prefix="form" uri="http://ift.tt/IED0jK" %>
<%@taglib prefix="spring" uri="http://ift.tt/18bwTB1" %>
<%@taglib prefix="fmt" uri="http://ift.tt/1bRkrVx" %>

<br/><br/><br/>
<div class='panel panel-primary'>
<div class='panel-heading'>
<h2 class='panel-title'>Page0</h2>
</div>
</div>

<form:form id="page0Form" modelAttribute="page0FormBean" method="post">

<div class="form-group row-fluid">
<label class='col-xs-6 control-label' for='formFieldA'>Page0's Form Field A</label>
<div class='col-xs-6'>
<input class='form-control' type='text' id='formFieldA' value='${page0FormBean.formFieldA}' />
</div>
</div>

<div class="form-group row-fluid">
<label class='col-xs-6 control-label' for='formFieldB'>Page0's Form Field B</label>
<div class='col-xs-6'>
<input class='form-control' type='text' id='formFieldB' value='${page0FormBean.formFieldB}' />
</div>
</div>

<div class="form-group row-fluid">
<label class='col-xs-6 control-label' for='formFieldC'>Page0's Form Field C</label>
<div class='col-xs-6'>
<input class='form-control' type='text' id='formFieldC' value='${page0FormBean.formFieldC}' />
</div>
</div>

</form:form>


here is the controller for "page0.jsp"...: Page0Controller.java



import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.apache.log4j.Logger;
import java.io.Serializable;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.servlet.ModelAndView;

@Controller
@Scope("session")
public class Page0Controller implements Serializable
{

private static final Logger LOG = Logger.getLogger("Page0Controller");
private static final long serialVersionUID = 1602123387257827883L;

@RequestMapping(value = "/page0", method = RequestMethod.GET)
public ModelAndView page0(ModelMap model)
{
LOG.info("____________________page0___________________entering...");
Page0FormBean page0FormBean = new Page0FormBean("page0fieldavalue", "page0fieldbvalue", "page0fieldcvalue");
model.addAttribute("page0FormBean", page0FormBean);

return new ModelAndView("tabbedPage", "page0FormBean", page0FormBean);
}
}


here is the "form bean" used by "page0.jsp"...: Page0FormBean.java



public class Page0FormBean
{
private String formFieldA;
private String formFieldB;
private String formFieldC;

public Page0FormBean(String formFieldA, String formFieldB, String formFieldC)
{
this.formFieldA = formFieldA;
this.formFieldB = formFieldB;
this.formFieldC = formFieldC;
}

public String getFormFieldA()
{
return formFieldA;
}
public void setFormFieldA(String formFieldA)
{
this.formFieldA = formFieldA;
}

public String getFormFieldB()
{
return formFieldB;
}
public void setFormFieldB(String formFieldB)
{
this.formFieldB = formFieldB;
}

public String getFormFieldC()
{
return formFieldC;
}
public void setFormFieldC(String formFieldC)
{
this.formFieldC = formFieldC;
}

@Override
public String toString()
{
return "Page0FormBean{" + "formFieldA=" + formFieldA + ", formFieldB=" + formFieldB + ", formFieldC=" + formFieldC + '}';
}

}

Aucun commentaire:

Enregistrer un commentaire