onload script does not work in subview page in JSF

Posted by jackrobert on Stack Overflow See other posts from Stack Overflow or by jackrobert
Published on 2010-05-18T05:39:05Z Indexed on 2010/05/18 6:10 UTC
Read the original article Hit count: 789

Filed under:
|
|
|

Hi,

Here i write two jsp page like outerPage.jsp and innerPage.jsp

The outer page include innerPage.jsp

The inner page have one textfield and one button..

I need focus for textFiled while page loading(innerPage.jsp).. I write a javascript, but not work it...

The code is

outerPage.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@ 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: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>

innerPage.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@ 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: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 does not called... Here i need cursor focus for textFiled after display the page ...

Thanks in advance.

© Stack Overflow or respective owner

Related posts about onload

Related posts about JavaScript