cancel
Showing results for 
Search instead for 
Did you mean: 

How to set focus on a simple Java form

Former Member
0 Kudos

Hi Experts,

I am customizing change password screen. In the screen there are three fields namely Old Password, New Password and Confirm New Password. For this purpose, I have created iView, Page and Role. My requirement is as below: Whenever change password screen is called, the cursor should be on Old Password. For this purpose, I have to make changes in the JSP. My JSP looks like:



<%@ taglib uri="UM" prefix="UM" %>
<%@ include file="proxy.txt" %>
<%@page import="com.sap.security.api.IUser"%>
<%@page import="com.sap.security.api.IUserAccount"%>
<%@page import="com.sap.security.api.logon.ILoginConstants"%>
 
<jsp:useBean id="user"
			 class="com.sap.security.core.admin.UserBean"
			 scope="request"/>
<jsp:useBean id="userAccount"
			 class="com.sap.security.core.admin.UserAccountBean"
			 scope="request"/>
<jsp:useBean id="error"
			 class="com.sap.security.core.util.ErrorBean"
			 scope="request"/>
<jsp:useBean id="info"
			 class="com.sap.security.core.util.InfoBean"
			 scope="request"/>
<%-- end page attribute setting--%>
<body>
<% IUser performer = proxy.getActiveUser();
   boolean toDisable = false;
   IUserAccount[] account = performer.getUserAccounts();
   String logonId = "";
   if ( account.length > 0 ) {
	   logonId = account[0].getLogonUid();
   }   
   if ( !UserAdminCustomization.isPasswordChangeAllowed() ) {
	   toDisable = true;
   } else {	
	   if ( account.length > 0 ) {
		   if (UserAdminFactory.isAttributeReadOnly(account[0].getUniqueID(), ILoginConstants.LOGON_PWD_ALIAS)) {
			   toDisable = true; 
		   }      
	   }
   }
 
   String altmin = userAdminLocale.get("MINIMIZE_THIS_SECTION");
   String altmax = userAdminLocale.get("MAXIMIZE_THIS_SECTION");
%>
 
<%-- start html--%>
<%--  used in Portal environment, no header, only body --%>
 
<%if (!inPortal) {%>
<body leftmargin="400" topmargin="400" marginheight="400" bgcolor="white" onload="focusmethod" >
<%}%>
 
<script>
  function checkPassword(action) {
	var frm = document.forms["passwordmodify"];
	var oldpswd = frm.elements["<%=userAccount.oldpassword%>"];
	var newpswd = frm.elements["<%=userAccount.password%>"];
	var pswdconfirm = frm.elements["<%=userAccount.passwordconfirm%>"];
	if ( oldpswd.value == "" || newpswd.value == "" || pswdconfirm.value == "" ) {
		var msg = "<%=userAdminLocale.get("FILL_IN_PSWDS")%>";
		alert(msg);
		return false;
	} else {
		if ( newpswd.value != pswdconfirm.value ) {
			alert("<%=userAdminLocale.get("PASSWORDS_MISMATCH")%>");
			return false;
		} else {
			actionTag = document.createElement("input");
			actionTag.setAttribute("name", action);
			actionTag.setAttribute("type", "hidden");
			actionTag.setAttribute("value", "");
			frm.appendChild(actionTag);
			frm.submit();
		}
	}
  }
  function focusmethod{
  	document.all(userAccount.oldpassword).focus();
  }
</script>
<table  height="500%" cellspacing="0" cellpadding="0" bgcolor="yellow" border="0">
<tr>
 
<!-- Start Middle 780pxl Content space -->
	<td  height="100%" valign="middle" class="TB_CNT_BG">
<!-- Start Content -->
<table cellpadding="0" cellspacing="0" border="0" bgcolor="#FFFFFF" height="100%">
 
	<tr>
	<!-- Start Transactional Content -->
	<td  valign="top">
 
<form id="passwordmodify" name="passwordmodify" method="post" action="<%=userAdminAlias%>">
 
<!-- Start Section Header -->
<!-- End Section Header -->
 
<table cellpadding="0" cellspacing="0" border="0">
  <tr><td><IMG height="5" src="<%=webpath%>layout/sp.gif"  border="0" alt=""></td></tr>
</table>
 
<!-- Start Section Description -->
<% if ( info.isInfo() ) { %>
<!-- Start Confirm Msg-->
<table align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF"  border="0">
  <tr><td  class="TX_CFM_XSB">
	<img src="<%=webpath%>layout/ico12_msg_success.gif"  height="12" border="0" /> 
	<span tabindex="0"><UM:encode><%=userAdminMessages.print(info.getMessage())%></UM:encode></span>
  </td></tr>
</table>
<!-- End Confirm Msg -->
<% } %>
 
<% if ( error.isError() ) { %>
<!-- Start Error Msg-->
<table align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF"  border="0">
  <tr><td  class="TX_ERROR_XSB">
	<img src="<%=webpath%>layout/ico12_msg_error.gif"  height="12" border="0" /> 
	<span tabindex="0"><UM:encode>hello sorry</UM:encode></span>
  </td></tr>
</table>
<!-- End Error Msg -->
<% } %>
 
<table cellpadding="0" cellspacing="0" border="0">
  <tr><td><IMG height="8" src="<%=webpath%>layout/sp.gif"  border="0" alt=""></td></tr>
</table>
 
<table cellpadding="0" cellspacing="1" border="0" bgcolor="#FFFFFF" class="SEC_TB_BDR" align="center">
  <tr><td class="TBLO_XXS_L">
	  <table id="cb-hd" border="0" cellpadding="0" cellspacing="0">
	  <tr class="TBDATA_CNT_EVEN_BG">
		<td class="TBDATA_XSB_NBG" tabIndex="0" width="200%"> <%=userAdminLocale.get("USER_PSWD")%></td>
			<td class="BGCOLOR_ICONOPEN" align="right" >
			<img id="cb-exp"
				 tabIndex="0"
				 src="<%=webpath%>layout/icon_open.gif"                 
				 height="15"
				 border="0"
				 alt="<%=altmin%>"
				 
				 class="IMG_BTN"></td>
	  </tr>
	</table>
  </td></tr>
  <tr><td class="TBDATA_CNT_ODD_BG"><div id="cb-bd">
	<TABLE cellpadding="2" cellspacing="0" border="0" bgcolor="#FFFFFF" id="h0">
	  <tr><td colspan="2"><IMG height="2" src="<%=webpath%>layout/sp.gif"  border="0" alt=""></td></tr>
	  <% if (toDisable) { %>
	  <tr><td colspan="2"><span tabindex="0"><%=userAdminLocale.get("PASSWORD_CHANGE_PROHIBITED")%></span></td></tr>
	  <% } %>
	  <tr><td colspan="2"><input type="hidden" name="<%=user.uidId%>" value="<%=util.filteringSpecialChar(performer.getUniqueID())%>"></td></tr>
	  <tr><td colspan="2"><input type="hidden" name="<%=userAccount.logonuid%>" value="<%=util.filteringSpecialChar(logonId)%>"></td></tr>
	  <tr>
		<td class="TBLO_XXS_R" nowrap>
		  <% if ( toDisable ) { %>
		  <% if ( spanTitle.length() > 0 ) spanTitle.delete(0, spanTitle.length());
			 spanTitle.append(userAdminLocale.get("OLD_PASSWORD")).append(" ");
			 spanTitle.append(userAccount.getOldPassword()).append(" ");
			 spanTitle.append(userAdminLocale.get("NOT_AVAILABLE")); %>          
		  <span title="<%=spanTitle.toString()%>" tabindex="0"><LABEL 
 
FOR="<%=userAccount.oldpassword%>"><%=userAdminLocale.get("OLD_PASSWORD")%>:</LABEL></span>
		  <% } else {  %>
		  <LABEL FOR="<%=userAccount.oldpassword%>"><%=userAdminLocale.get("OLD_PASSWORD")%>:</LABEL>
		  <% } %>
		</td>
		<td class="TX_XS" nowrap>
		  <input id="<%=userAccount.oldpassword%>"
				 name="<%=userAccount.oldpassword%>"
				 value="<%=userAccount.getOldPassword()%>"
				 type="password"
				 size="20"
				 style="width: 2in"
				 ><% if (toDisable) {%>disabled<%}%>></td>
	  </tr>
	  <tr>
		<td class="TBLO_XXS_R" nowrap>
		  <% if ( toDisable ) { %>
		  <% if ( spanTitle.length() > 0 ) spanTitle.delete(0, spanTitle.length());
			 spanTitle.append(userAdminLocale.get("NEW_PASSWORD")).append(" ");
			 spanTitle.append(userAccount.getPassword()).append(" ");
			 spanTitle.append(userAdminLocale.get("NOT_AVAILABLE")); %>          
		  <span title="<%=spanTitle.toString()%>" tabindex="0"><LABEL 
 
FOR="<%=userAccount.password%>"><%=userAdminLocale.get("NEW_PASSWORD")%>:</LABEL></span>
		  <% } else {  %>
		  <LABEL FOR="<%=userAccount.password%>"><%=userAdminLocale.get("NEW_PASSWORD")%>:</LABEL>
		  <% } %>
		</td>
		<td class="TX_XS" nowrap>
		  <input id="<%=userAccount.password%>"
				 name="<%=userAccount.password%>"
				 value="<%=userAccount.getPassword()%>"
				 type="password"
				 size="20"
				 style="width: 2in"
				 ><% if (toDisable) {%>disabled<%}%>></td>
	  </tr>
	  <tr>
		<td class="TBLO_XXS_R" nowrap>
		  <% if ( toDisable ) { %>
		  <% if ( spanTitle.length() > 0 ) spanTitle.delete(0, spanTitle.length());
			 spanTitle.append(userAdminLocale.get("PASSWORD_CONFIRM")).append(" ");
			 spanTitle.append(userAccount.getPasswordConfirm()).append(" ");
			 spanTitle.append(userAdminLocale.get("NOT_AVAILABLE")); %>          
		  <span title="<%=spanTitle.toString()%>" tabindex="0"><LABEL 
 
FOR="<%=userAccount.passwordconfirm%>"><%=userAdminLocale.get("PASSWORD_CONFIRM")%>:</LABEL></span>
		  <% } else {  %>
		  <LABEL FOR="<%=userAccount.passwordconfirm%>"><%=userAdminLocale.get("PASSWORD_CONFIRM")%>:</LABEL>
		  <% } %>
		</td>
		<td class="TX_XS" nowrap>
		  <input id="<%=userAccount.passwordconfirm%>"
				 name="<%=userAccount.passwordconfirm%>"
				 value="<%=userAccount.getPasswordConfirm()%>"
				 type="password"
				 size="20"
				 style="width: 2in"
				 ><% if (toDisable) {%>disabled<%}%>></td>
	  </tr>
	</table></div>
  </td></tr>
</table>
<!-- end data table -->
 
<table cellpadding="0" cellspacing="0" border="0">
  <tr><td><IMG height="30" src="<%=webpath%>layout/sp.gif"  border="0" alt=""></td></tr>
</table>
 
<!-- Start Page Action Buttons -->
<table  border="0" cellpadding="0" cellspacing="0">
  <tr><td  align="left" class="TBLO_XXS_L" nowrap>
	<% String apply = " "+userAdminLocale.get("APPLY")+" ";
	   String clear = " "+userAdminLocale.get("CLEAR")+" ";
		%>
	<input type="button"
		   name="<%=UserAdminLogic.performUserPswdChangeAction%>"
		   value="<%=apply%>"
		   class="BTN_LB"
		   onClick="checkPassword('<%=UserAdminLogic.performUserPswdChangeAction%>')"> 
	<input type="reset"
		   name="clear"
		   value="<%=clear%>"
		   class="BTN_LN"> 
           
  </td></tr>
</table>
</form>
<!-- End Page Action Buttons -->
</td></tr></table>
</td></tr></table>
</body>
<!-- end content -->
 
<%@ include file="contextspecific_includes_bottom.txt" %>
 

However using above JSP I am unable to set foucs on Old Password. The relevant code for setting foucs is


<%if (!inPortal) {%>
<body leftmargin="400" topmargin="400" marginheight="400" bgcolor="blue" onload="focusmethod" >
<%}%>
 
<script>
  function checkPassword(action) {
	var frm = document.forms["passwordmodify"];
	var oldpswd = frm.elements["<%=userAccount.oldpassword%>"];
	var newpswd = frm.elements["<%=userAccount.password%>"];
	var pswdconfirm = frm.elements["<%=userAccount.passwordconfirm%>"];
	if ( oldpswd.value == "" || newpswd.value == "" || pswdconfirm.value == "" ) {
		var msg = "<%=userAdminLocale.get("FILL_IN_PSWDS")%>";
		alert(msg);
		return false;
	} else {
		if ( newpswd.value != pswdconfirm.value ) {
			alert("<%=userAdminLocale.get("PASSWORDS_MISMATCH")%>");
			return false;
		} else {
			actionTag = document.createElement("input");
			actionTag.setAttribute("name", action);
			actionTag.setAttribute("type", "hidden");
			actionTag.setAttribute("value", "");
			frm.appendChild(actionTag);
			frm.submit();
		}
	}
  }
  function focusmethod{
  	document.all(userAccount.oldpassword).focus();
  }
</script>

Could you please suggest me what is going wrong with my code.

Regards,

RK

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

My guess is that instead of


  function focusmethod{
    document.all(userAccount.oldpassword).focus();
  }

it should be


  function focusmethod{
    document.all("<%=userAccount.oldpassword%>").focus();
  }

Moreover, at least in MY Internet Explorer (version 6.0), you have to use


<body leftmargin="400" topmargin="400" marginheight="400" bgcolor="white" onload="focusmethod()" >

instead of


<body leftmargin="400" topmargin="400" marginheight="400" bgcolor="white" onload="focusmethod" >

Regards,

Jens

P.S.: As a final note, you should try not to use document.all because then your page will not work in any browser except Internet Explorer.

Former Member
0 Kudos

Hi,

u should write the Java script function like this


function focusmethod(){
.
.
.
  }

Regards,

Beevin.