忍者ブログ
まにょのITメモ
[1]  [2]  [3]  [4]  [5]  [6
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。


<html>
    <head>
        <title>お薬一覧</title>
<script language="javascript">

<!--

// クラス定義
var RowInfo = function(sortKey, rowObj) {
 this.sortKey = sortKey;
 this.rowObj = rowObj;
 this.toString = function() {
     window.alert(this.sortKey + " " + this.rowObj.innerText);
 };
}

function sample(tableName){
 this.table = document.getElementById(tableName);
 this.tbody = this.table.getElementsByTagName('tbody')[0];
 this.rows = this.tbody.getElementsByTagName('tr');
 this.cells = this.tbody.getElementsByTagName('td');

 this.thead = this.table.getElementsByTagName('thead')[0];
 this.headers = this.thead.getElementsByTagName('th');

 for(i=0; i<this.headers.length; i++){
alert(1);
alert(this.headers[i].innerText);
//  this.headers[i].addEvent('click', function(i){alert(i)});
alert(2);
//   this.headers[i].addEvent('mouseover',function(i){this.headers[i].addClass(this.options.overCl)}.pass(i,this));
//   this.headers[i].addEvent('mouseout',function(i){this.headers[i].removeClass(this.options.overCl)}.pass(i,this));
//   this.headers[i].setStyle('cursor','pointer');
 }
alert(3);
 // ヘッダーにonClickを埋め込む
// for(i=0; i<this.headers.length; i++){
//  var header = this.headers[i];
//  alert(header.innerText);
//  var onClickAttr = document.createAttribute("onclick");
//  onClickAttr.nodeValue ="alert()";
//  header.setAttributeNode(onClickAttr);
//  alert(77777);
// }

 // オブジェクトの配列
 var rowObjList = new Array();

 // 全行の情報をリストにつめる
 for(i=0; i<this.rows.length; i++){
  var row = this.rows[i];
  // カラムの2つ目の値を取得する。
  var cellValue = row.getElementsByTagName('td')[0];
  rowObjList.push(new RowInfo(cellValue.innerText, row));
 }

 // ソート処理を実施
 rowObjList.sort(compare);

 for(i =0; i<rowObjList.length; i++){
  var newRow = rowObjList[i].rowObj;
  this.tbody.appendChild(newRow);
 }
}

//数値を取得
function getNum(num){
  if( num.match(/^(\-?((\d{1,3}(,\d\d\d)+)|\d+)(\.\d+)?)(.*)$/i) ){
    nn = RegExp.$1;
    nv = RegExp.$6;
    if(nn == ''){
       nn = '0';
    }
    return(new Array(nn,nv));
  }else{
    return(new Array('0',num));
  }
}


function compare(a1, b1){
    if(1){
      a1 = Number(a1.sortKey);
      b1 = Number(b1.sortKey);
    }else{
      a1 = String(a1.sortKey);
      b1 = String(b1.sortKey);
    }
    if(0){
      return a1 > b1 ? -1 : a1 < b1 ? 1 : 0;
    }else{
      return a1 < b1 ? -1 : a1 > b1 ? 1 : 0;
    }
}
//-->
</script>
    </head>
    <body>
           <input type="button" name="add" value="追加" onclick="sample('tableId')">
        <table id="tableId" border="1">
   <thead>
          <tr>
     <th>No</th><th>名前</th><th>単価</th>
       </tr>
   </thead>
   <tbody>
          <tr>
     <td>20</td><td>りんご</td><td>500</td>
          </tr>
       <tr>
     <td>5</td><td>みかん</td><td>250</td>
          </tr>
       <tr>
     <td>3</td><td>ぶどう</td><td>750</td>
          </tr>
    <tr>
     <td>10</td><td>とまと</td><td>150</td>
          </tr>
    <tr>
     <td>a</td><td>白菜</td><td>800</td>
          </tr>
   </tbody>
        </table>
    </body>
</html>

PR


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4">

    <!-- ====================================================== -->
    <!--                 コンテキスト定義の読み込み設定                                       -->
    <!-- ====================================================== -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:applicationContext.xml
           ,classpath:action-servlet.xml
        </param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- ====================================================== -->
    <!--                 Hibernate遅延設定(Lazy)                 -->
    <!-- ====================================================== -->
    <filter>
        <filter-name>hibernateFilter</filter-name>
        <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
        <init-param>
            <param-name>sessionFactoryBeanName</param-name>
            <param-value>sessionFactory</param-value>
        </init-param>
        <init-param>
            <param-name>singleSession</param-name>
            <param-value>false</param-value>
        </init-param>
        <init-param>
            <param-name>flushMode</param-name>
            <param-value>AUTO</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>hibernateFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!-- ====================================================== -->
    <!--                 文字エンコーディング設定                                                       -->
    <!-- ====================================================== -->
    <filter>
        <filter-name>CharacterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>CharacterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>


    <!-- ====================================================== -->
    <!--                       Struts設定                                                              -->
    <!-- ====================================================== -->
    <servlet>
        <servlet-name>action</servlet-name>
        <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
        <init-param>
            <param-name>config</param-name>
            <param-value>/WEB-INF/struts-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>


    <!-- ====================================================== -->
    <!--                       DWR設定(Ajax)                    -->
    <!-- ====================================================== -->
    <servlet>
        <servlet-name>dwr-invoker</servlet-name>
        <servlet-class>org.directwebremoting.spring.DwrSpringServlet</servlet-class>
        <load-on-startup>2</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>dwr-invoker</servlet-name>
        <url-pattern>/dwr/*</url-pattern>
    </servlet-mapping>


    <!-- ====================================================== -->
    <!--                 セッションタイムアウト設定(分)                 -->
    <!-- ====================================================== -->
    <session-config>
        <session-timeout>5</session-timeout>
    </session-config>


    <!-- ====================================================== -->
    <!--                     welcomeページ設定                                                    -->
    <!-- ====================================================== -->
    <welcome-file-list>
        <welcome-file>pages/index.jsp</welcome-file>
    </welcome-file-list>


    <!-- ====================================================== -->
    <!--                     Strutsカスタムタグ                                                       -->
    <!-- ====================================================== -->
    <jsp-config>
        <taglib>
            <taglib-uri>/tags/struts-bean</taglib-uri>
            <taglib-location>/WEB-INF/tld/struts-bean.tld</taglib-location>
        </taglib>

        <taglib>
            <taglib-uri>/tags/struts-html</taglib-uri>
            <taglib-location>/WEB-INF/tld/struts-html.tld</taglib-location>
        </taglib>

        <taglib>
            <taglib-uri>/tags/struts-logic</taglib-uri>
            <taglib-location>/WEB-INF/tld/struts-logic.tld</taglib-location>
        </taglib>

        <taglib>
            <taglib-uri>/tags/struts-nested</taglib-uri>
            <taglib-location>/WEB-INF/tld/struts-nested.tld</taglib-location>
        </taglib>

        <taglib>
            <taglib-uri>/tags/struts-tiles</taglib-uri>
            <taglib-location>/WEB-INF/tld/struts-tiles.tld</taglib-location>
        </taglib>
    </jsp-config>
</web-app>


<?xml version="1.0" encoding="Shift_JIS"?>
<project name="project" default="all" basedir=".">
 <property name="source" value="./src" />
    <property name="build" value="./classes" />

 <path id="classpath">
  <pathelement location="./lib/commons-lang.jar"/>
  <pathelement location="./lib/poi-2.5.1.jar"/>
  <pathelement location="./lib/velocity-dep-1.5.jar"/>
 </path>

 <target name="all" depends="compile,execute"
        description="コンパイルを実行する" />

 <target name="compile">
  <echo message="コンパイル開始..." />
      <javac srcdir="${source}"
             destdir="${build}"
             debug="on" >
              <classpath>
                      <fileset refid="classpath" />
              </classpath>
      </javac>
        <echo message="コンパイル完了..." />
 </target>

 <target name="execute">
  <echo message="実行開始..." />
  <java classname="CreateSqlBach" classpath="${build}" classpathref="classpath"/>
  <echo message="実行完了..." />
 </target>
</project>

<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<html>
    <head>
        <title>お薬一覧</title>
 <style type="text/css">
   <!--
     #suggest div{
       position: absolute;
       background-color: #FFFFFF;
       border: 1px solid #CCCCFF;
       width: 252px;
     }
     #suggest div.div {
       padding: 1px;
       display: block;
       width: 250px;
       overflow: hidden;
       white-space: nowrap;
     }
     #suggest div.div.select{
       color: #FFFFFF;
       background-color: #3366FF;
     }
     #suggest div.div.over{
       background-color: #99CCFF;
     }
     #suggest div.strong{
       font-weight: bold;
     }
     -->
 </style>
    <script type="text/javascript" src="./js/suggest.js"></script>
<script language="javascript"><!--


// テーブルのレコード数を保持
var rowCount = 0;
// Suggestを作成

<bean:define id="jsonMedicineList" name="registInventoryForm" property="jsonMedicineList"/>
var list = <%=jsonMedicineList%>;

function createRowObj(cellLists){
    var table = document.getElementById("table");
    var row = table.insertRow(-1);

    for (var i=0; i<cellLists.length; i++) {
        var cellName = cellLists[i];
        var cell = row.insertCell(-1);
        var text = document.createElement("input");
        text.type = "text";
        text.id = cellName+rowCount;
        text.name = "medicineData["+rowCount+"]."+cellName;
        cell.appendChild(text);
    }

     // Suggestを作成する
    var row2 = table.insertRow(-1);
    var cell3 = row2.insertCell(-1);
    var div = document.createElement("div");
    div.id = "suggest"+rowCount;
    cell3.appendChild(div);

    aaaa(rowCount);

    rowCount++;
}

function addItem() {
    var cellLists = new Array("name", "num");
    createRowObj(cellLists);
//    var table = document.getElementById("table");
//    var row = table.insertRow(-1);
//    var cell1 = row.insertCell(-1);

    // 名前カラムのテキストボックスを追加する
//    var text1 = document.createElement("input");
//    text1.type = "text";
//    text1.name = "medicineData["+rowCount+"].name";
//    cell1.appendChild(text1);

//    var cell2 = row.insertCell(-1);
    // 単価カラムのテキストボックスを追加する
//    var text2 = document.createElement("input");
//    text2.type = "text";
//    text2.name = "medicineData["+rowCount+"].num";
//    cell2.appendChild(text2);

    // Suggestを作成する
//    var row2 = table.insertRow(-1);
//    var cell3 = row2.insertCell(-1);
//    var div = document.createElement("div");
//    div.id = "suggest"+rowCount;
//    cell3.appendChild(div);

    //
//    aaaa(rowCount);

//    rowCount++;
}

function delItem() {
    var table = document.getElementById("table");
    table.deleteRow(-1);
}

function aaaa(num){
    new Suggest.Local("name"+num, "suggest"+num, list, {ignoreCase: false, prefix: true, highlight: true});
}

function sss() {

    // var rowCount = <%= request.getAttribute("count")%>;

    // 空行を作成する
    addItem();
}
//-->
</script>
    </head>
    <body onload="sss()">
        <html:form action="/medicine" >
            <input type="button" name="add" value="追加" onclick="addItem()">
            <input type="button" name="delete" value="削除" onclick="delItem()">
            <div id="suggest">
                <table id="table" border="1">
                    <tr>
                        <th>名前</th>
                        <th>単価</th>
                    </tr>
                </table>
            </div>
            <input type="submit" name="send" value="送信">
        </html:form>
    </body>
</html>

■Sample2.java
================================================
package jp.co.sample;

import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;


public class Sample2 {

    private static Logger logger = Logger.getLogger(Sample2.class);
    private static String LOG4J_DEFAULT_FILE = "log4j.xml";

    public static void main(String[] args) {
        // 設定ファイル読み込み
        DOMConfigurator.configure(ClassLoader.getSystemResource(LOG4J_DEFAULT_FILE));

        if (logger.isInfoEnabled()){
            logger.info("INFO");
        }

        if (logger.isDebugEnabled()){
            logger.debug("DEBUG");
        }
    }
}
================================================



■log4j.xml
================================================
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!--  debugにtrueにするとログファイル定義を読み込み時に設定の詳細が表示される -->
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">

    <!-- ログレベルについて -->
    <!-- ALL < TRACE < DEBUG < INFO <WARN < ERROR < FATAL < OFF -->

    <!-- 動作を「非同期」にする -->
    <appender name="ASYNC_LOG" class="org.apache.log4j.AsyncAppender">
        <param name="Threshold" value="debug" />
        <param name="BufferSize" value="128" />
        <!-- 非同期にしたい Appenderを指定する-->
        <appender-ref ref="FILE" />
    </appender>

    <!-- ログをファイルに出力する為のAppender -->
    <!-- ※ログローテーションは行わない -->
    <appender name="FILE" class="org.apache.log4j.FileAppender">
        <!-- 『File』ファイル出力する為のAppender -->
        <param name="File" value="log.txt" />
        <!-- 『Append』追加モードか否かを指定 -->
        <!-- true:追加モード   false:新規 -->
        <!-- 指定しない場合はtrue:追加モードみたい -->
        <param name="Append" value="true" />
        <!-- 『BufferedIO』バッファリングをするか否かを指定 -->
        <!-- true:バッファリングする   false:バッファリングしない -->
        <!-- 指定しない場合はfalse:バッファリングしないらしい・・・ 未確認 -->
        <param name="BufferedIO" value="true" />
        <!-- 『BufferSize』バッファサイズを指定する -->
        <!-- FileAppenderクラスの初期値として"8192"が指定されている -->
        <param name="BufferSize" value="8192" />
        <!-- 『Threshold』レベルを指定(appendの共通オプション) -->
        <!-- レベルを指定し、そのレベル以下だと出力しないようにする -->
        <param name="Threshold" value="debug" />
        <!-- レイアウトを指定する【必須項目】 -->
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{yyyy/MM/dd HH:mm:ss:SSS} %p:%r:%c:%m%n" />
        </layout>
    </appender>

    <!-- コンソールにログを出力するためのAppender -->
    <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
        <param name="Threshold" value="debug" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{yyyy/MM/dd HH:mm:ss:SSS} %p:%r:%c:%m%n" />
        </layout>
    </appender>

    <!-- ログ出力対象を指定する -->
    <logger name="jp.co.sample">
        <level value="info" />
        <appender-ref ref="FILE" />
        <appender-ref ref="CONSOLE" />
    </logger>

    <!-- root 要素は使用しない -->
    <root>
        <level value="OFF" />
        <!-- <appender-ref ref="CONSOLE" /> -->
    </root>

</log4j:configuration>
===============================================

196d4bb1.jpeg



%n    改行
忍者ブログ * [PR]