I have written two JSP pages: outerPage.jsp
and innerPage.jsp
.
The outerPage.jsp
includes innerPage.jsp
.
The innerPage.jsp
has one textfield and one button.
I need to set focus on textFiled in innerPage.jsp
while the page loads.
I wrote JavaScript which is called during body onload of outerPage.jsp
, but it does not work.
Here is the outerPage.jsp
:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j" %>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<html>
<f:view>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Outer Viewer</title>
<meta name="description" content="Outer Viewer" />
</head>
<body id="outerMainBody">
<rich:page id="richPage">
<rich:layout>
<rich:layoutPanel position="center" width="100*">
<a4j:outputPanel>
<f:verbatim><table style="padding: 5px;"><tbody><tr>
<td>
<jsp:include page="innerPage.jsp" flush="true"/>
</td>
</tr></tbody></table></f:verbatim>
</a4j:outputPanel>
</rich:layoutPanel>
</rich:layout>
</rich:page>
</body>
</f:view>
</html>
Here is the innerPage.jsp
:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j" %>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<f:verbatim><html></f:verbatim>
<f:subview id="innerViewerSubviewId">
<f:verbatim><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Inner Viewer </title>
<script type="text/javascript">
//This script does not called during the page loading (onload)
function cursorFocus()
{
alert("Cursor Focuse Method called...");
document.getElementById("innerViewerForm:innerNameField").focus();
alert("Cursor Focuse method end!!!");
}
</script>
</head>
<body onload="cursorFocus();"></f:verbatim>
<h:form id="innerViewerForm">
<rich:panel id="innerViewerRichPanel">
<f:facet name="header">
<h:outputText value="Inner Viewer" />
</f:facet>
<a4j:outputPanel id="innerViewerOutputPanel" >
<h:panelGrid id="innerViewerSearchGrid" columns="2" cellpadding="3" cellspacing="3">
//<%-- Row 1 For Text Field --%>
<h:outputText value="inner Name : " />
<h:inputText id="innerNameField" value=""/>
//<%-- Row 2 For Test Button --%>
<h:outputText value="" />
<h:commandButton value="TestButton" action="test" />
</h:panelGrid>
</a4j:outputPanel>
</rich:panel>
</h:form>
<f:verbatim></body></f:verbatim>
</f:subview>
<f:verbatim></html></f:verbatim>
The cursorFocus()
script is not get called.
Thanks in advance.