Page List

Search on the blog

2013年1月22日火曜日

Learn Struts(1)

For some reason, I decided to learn a popular Java MVC framework "Struts." Maybe it's because I'm now engaged in a project concerning the framework, or maybe I just think that I should be familiar with at least one famous framework...

Anyway let's get started. This is the first day, so I'll start it with an easy task.

Question
How does the focus property in html:tag work?

Answer
I just created a simple jsp and checked it.
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<html:html>
<head>
<title>HTML Tags Test</title>
</head>
<body>
<html:form action="/auth" focus="id">
    ID: <html:text property="id" size="16" /><br/>
    PASS: <html:text property="pass" size="16" /><br/>
    <html:submit property="submit" value="submit" />
    <html:reset value="reset" />
</html:form>
</body>
</html:html>
The above JSP yields the following HTML:
<html>
<head>
<title>HTML Tags Test</title>
</head>
<body>
<form name="testForm" method="post" action="/struts/auth.do">
    ID: <input type="text" name="id" size="16" value=""><br/>
    PASS: <input type="text" name="pass" size="16" value=""><br/>
    <input type="submit" name="submit" value="submit">
    <input type="reset" value="reset">
</form>
<script type="text/javascript" language="JavaScript">
  <!--
  var focusControl = document.forms["testForm"].elements["id"];

  if (focusControl != null && focusControl.type != "hidden" && !focusControl.disabled && focusControl.style.display != "none") {
     focusControl.focus();
  }
  // -->
</script>

</body>
</html>
It added some javascript code. So this is how it works.

0 件のコメント:

コメントを投稿