struts2-jquery datepicker tag not loading in struts2-jquery tabbedpannel tag

966 views Asked by At

I have a page index.jsp, I've used struts2-jquery tabbedpannel tag in this jsp to display another two JSPs (first.jsp & second.jsp) as tabs.

index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                      "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<sj:head />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Index Page</title>
</head>
<body>
    <sj:tabbedpanel 
        id="remotetabs" 
        selectedTab="0" 
        show="true" 
        hide="'fade'" 
        collapsible="true" 
        sortable="true">

            <sj:tab id="tab1" href="first.jsp" label="First JSP"/>
            <sj:tab id="tab2" href="second.jsp" label="Second JSP"/>

    </sj:tabbedpanel>
</body>
</html>

Another two JSPs contain a form each with struts2-datepicker tag. Here is one of them...

first.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                      "http://www.w3.org/TR/html4/loose.dtd">
<html>
<link rel="stylesheet" type="text/css" href="css/view.css" media="all">


<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>First JSP</title>
</head>


<body>
    <div>
    <s:form action="firstAction" >
            <sj:datepicker 
                key="timeStamp" 
                name="timeStamp"  
                label="Time Stamp" 
                timepicker="true" 
                displayFormat="yy-mm-dd" 
                timepickerFormat="HH:mm"/>
            <s:submit value="Submit"></s:submit>
    </s:form>
    </div>
</body>
</html>

The problem is that, the first time index.jsp is loaded, struts2-jquery datepicker tag on first.jsp works fine, but as I switch to second tab; which will load second.jsp in AJAX (second.jsp contains same code as first.jsp) struts2-jquery datepicker tag on second.jsp doesn't work.

Now, when I switch back to First Tab to display first.jsp, struts2-jquery datepicker tag doesn't work either. It just stops working after first load.

1

There are 1 answers

0
Andrea Ligios On BEST ANSWER

The problem is that you are calling JSP pages, while you should call Struts2 Actions.

Struts2 is MVC. You souldn't call a View from a View, you should instead call a Controller that will dispatch to a View.

The first time, it works because the variables feeding struts and struts-jquery tags in first.jsp and second.jsp are taken from IndexAction.

You should instead define FirstAction and SecondAction and call them through AJAX in the href attribute:

<s:url var="firstActionUrl" action="first" namespace="/" />
<sj:tab id="tab1" href="%{#firstActionUrl}" label="First JSP"/>

<s:url var="secondActionUrl" action="second" namespace="/" />
<sj:tab id="tab2" href="%{#secondActionUrl}" label="Second JSP"/>