[DOJO]JSON+JAVA+Netbeans 예제

참고 :
http://www.javapassion.com/handsonlabs/ajaxdojojson/     <<<구버젼 DOJO 수정요함
http://dojotoolkit.org/book/dojo-book-0-9/part-3-programmatic-dijit-and-dojo/ajax-transports/passing-data-json
<<DOJO 신버젼 문서 참고


<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page
    import="java.util.Iterator,
    java.util.List,
    com.esolaria.dojoex.Book,
    com.esolaria.dojoex.BookManager" %>
<%--
    Document   : index
    Created on : 2008. 4. 9, 오후 10:58:39
    Author     : emillekorea
--%>

<%
            List books = BookManager.getBooks();
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <title>Dojo and JSON Example</title>
       
        <!-- SECTION 1 -->
        <style type="text/css">
            @import "http://o.aolcdn.com/dojo/1.0.0/dijit/themes/tundra/tundra.css";
            @import "http://o.aolcdn.com/dojo/1.0.0/dojo/resources/dojo.css";
        </style>
        <script type="text/javascript"
                djConfig="parseOnLoad: true"
                src="http://o.aolcdn.com/dojo/1.0.0/dojo/dojo.xd.js"></script>          
       
        <!-- SECTION 2 -->
        <script type="text/javascript">
            // Load Dojo's code relating to the Button widget
            dojo.require("dijit.form.Button");
        </script>
        <script>
            // Event handler when a user hovers a mouse over
            function trMouseOver(bookId) {
                getBookInfo(bookId);
            }
           
            // Event handler when a user hovers a mouse out
            function trMouseOut(evt) {
                var bookDiv = document.getElementById("bookInfo");
                bookDiv.style.display = "none";
            }
           
            // Invoked from trMoustOver(bookId) function call above
            function getBookInfo(bookId) {
                var params = new Array();
                params['bookId'] = bookId;
               
                dojo.xhrGet({
                    url: "actions/book.jsp",
                    load: populateDiv,
                    handleAs: "json",
                    error: helloError,
                    content: params
                });
            }
           
            // Function call to populate the "bookInfo" div element that is
            // defined at the end of this file.
            function populateDiv(data,ioArgs) {
                var bookDiv = document.getElementById("bookInfo");
                if (!data) {
                    bookDiv.style.display = "none";
                } else {
                bookDiv.innerHTML = "ISBN: " + data.isbn + "<br/>Author: " + data.author ;
                bookDiv.style.display = "";
            }
        }
       
        function helloError(data, ioArgs) {
            alert('Error when retrieving data from the server!');
        }
        </script>
    </head>
   
    <body class="tundra">
    <body>
        <h1><center>Dojo and JSON Example - Move your mouse over the book titles!</center></h1>
       
        <table cellspacing="0" cellpadding="3" style="background-color:lavender; border: solid 1px #CCCCCC">
            <!-- Display each book with Id and it title in a table format -->
            <% for (Iterator iter = books.iterator(); iter.hasNext();) {
                Book book = (Book) iter.next();%>
           
            <!-- Whenever you hover your mouse over and out on a book title,
            trMouseOver() and trMouseOut event handlers get called -->
            <tr onmouseover="trMouseOver(<%=book.getBookId()%>)"
                onmouseout="trMouseOut(<%=book.getBookId()%>)">
                <td><%=book.getTitle()%></td>
            </tr>
            <% } %>
        </table>
       
        <!-- This is the div element that will be populated in the populateDiv
        JavaScript function above, which req object is loaded -->
        <div id="bookInfo" style="display:none;"></div>
    </body>
</html>


-------------------------------------------
<%@ page import="java.util.Iterator,
         java.util.List,
         com.esolaria.dojoex.Book,
         com.esolaria.dojoex.BookManager" %>
action/book.jsp

<%
    String bookIdStr = request.getParameter("bookId");
    int bookId = (bookIdStr == null || "".equals(bookIdStr.trim()))
        ? 0 : Integer.parseInt(bookIdStr);
    Book book = BookManager.getBook(bookId);
    if (book != null) {
        out.println(book.toJSONString());
        System.out.println("itis: " + book.toJSONString());
    }
%>
-----------------------------------------------

package com.esolaria.dojoex;

import org.json.JSONObject;
import org.json.JSONException;

public class Book {
   
    private int bookId;
    private String title;
    private String isbn;
    private String author;
    //private Publisher publisher;
   
    public Book(){
    }
   
    public Book(int bookId, String title, String isbn, String author) {
        this.bookId = bookId;
        this.title = title;
        this.isbn = isbn;
        this.author = author;
        //this.setPublisher(publisher);
    }
   
    public String toJSONString() throws JSONException {
        JSONObject jsonObj = new JSONObject();
        jsonObj.put("bookId", new Integer(this.bookId));
        jsonObj.put("title", this.title);
        jsonObj.put("isbn", this.isbn);
        jsonObj.put("author", this.author);
        // Create a new JSONObject called jsonObj2
        /*
        JSONObject jsonObj2 = new JSONObject();
        jsonObj2.put("name", this.getPublisher().getName());
        jsonObj2.put("address", this.getPublisher().getAddress());
        jsonObj2.put("year", this.getPublisher().getYear());

        // Add the newly created jsonObj2 to jsonObj
        jsonObj.put("publisher", jsonObj2);
        */
        return jsonObj.toString();
    }
   
    public void setBookId(int bookId) {
        this.bookId = bookId;
    }
    public int getBookId() {
        return this.bookId;
    }
   
    public void setTitle(String title) {
        this.title = title;
    }
    public String getTitle() {
        return this.title;
    }
   
    public void setIsbn(String isbn) {
        this.isbn = isbn;
    }
    public String getIsbn() {
        return this.isbn;
    }
   
    public void setAuthor(String author) {
        this.author = author;
    }
    public String getAuthor() {
        return this.author;
    }
    /*
    public Publisher getPublisher() {
        return publisher;
    }

    public void setPublisher(Publisher publisher) {
        this.publisher = publisher;
    }
     */
}
--------------------------------------------------------
package com.esolaria.dojoex;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class BookManager {
   
    private static List books = new ArrayList();
   
    // Initialize List of Book's'
    static {
        books.add(new Book(1, "Crime and Punishment", "0679734503", "Fyodor Dostoevsky"));
        books.add(new Book(2, "The Collected Tales of Nikolai Gogol", "0375706151", "Nikolai Gogol"));
        books.add(new Book(3, "King Rat", "0440145465", "James Clavell"));
        books.add(new Book(4, "The Alchemist", "0062502182", "Paulo Coelho"));
        books.add(new Book(5, "A Tale of Two Cities", "0451526562", "Charles Dickens"));
    }
   
   
    public static Book getBook(int bookId) {
        Book returnValue = null;
        for (Iterator iter = books.iterator(); iter.hasNext();) {
            Book book = (Book) iter.next();
            if (book.getBookId() == bookId) {
                returnValue = book;
                break;
            }
        }
        return returnValue;
    }
   
    public static List getBooks() {
        return books;
    }
   
}
------------------------------------------------------------------------

by 키트 | 2008/04/10 14:57 | Ajax | 트랙백 | 덧글(0)

[JSP2.0]Custom tag with attribute ...by tag file

참고 :
http://java.sun.com/developer/technicalArticles/javaserverpages/JSP20/
http://www.netbeans.org/kb/50/tutorial-taglibrary.html


****WEB-INF/tags/greetings.tag

<%--
    Document   : greetings
    Created on : 2008. 4. 4, 오후 7:24:07
    Author     : emillekorea
--%>

<%@tag description="put the tag description here" pageEncoding="UTF-8"%>

<%-- The list of normal or fragment attributes can be specified here: --%>
<%@attribute name="message"%>

<%-- any content can be specified here e.g.: --%>
<h2>${message}</h2>

**** chat.jsp

<%--
    Document   : chat
    Created on : 2008. 4. 4, 오후 7:25:54
    Author     : emillekorea
--%>

<%@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 prefix="tags" tagdir="/WEB-INF/tags" %>
<HTML>
<HEAD>
<TITLE>JSP 2.0 Examples - Hello World Using a Tag File</TITLE>
</HEAD>
<BODY>
<H2>Tag File Example</H2>
<P>
<B>The output of my first tag file is</B>: <tags:greetings message="안녕 !! 사랑해"/>
</BODY>
</HTML>

by 키트 | 2008/04/06 04:02 | Tag | 트랙백 | 덧글(0)

[DOJO]Sample: Helloworld-CDN

<!--
    Document   : dojo_hello_world
    Created on : 2008. 4. 3, 오후 4:13:14
    Author     : emillekorea
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <title>Dojo: Hello World!</title>
        
        <!-- SECTION 1 -->
        <style type="text/css">
            @import "http://o.aolcdn.com/dojo/1.0.0/dijit/themes/tundra/tundra.css";
            @import "http://o.aolcdn.com/dojo/1.0.0/dojo/resources/dojo.css";
        </style>
        <script type="text/javascript"
                djConfig="parseOnLoad: true"
                src="http://o.aolcdn.com/dojo/1.0.0/dojo/dojo.xd.js"></script>           
        
        <!-- SECTION 2 -->
        <script type="text/javascript">
            // Load Dojo's code relating to the Button widget
            dojo.require("dijit.form.Button");
        </script>
    </head>
    
    <body class="tundra">
        <button dojoType="dijit.form.Button" id="helloButton">
            Hello World!
            <script type="dojo/method" event="onClick">
                alert('You pressed the button');
            </script>
        </button>
    </body>
</html>
by 키트 | 2008/04/04 08:42 | Ajax | 트랙백 | 덧글(0)

[DOJO]Sample Test - CDN

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <title>Sample 1.0.0 xdomain page</title>
    <script type="text/javascript"
        djConfig="isDebug: true"
        src="http://o.aolcdn.com/dojo/1.0.0/dojo/dojo.xd.js"></script>           
             
    <script type="text/javascript">

        Commands = {
            sayHello: function(){
                var status = "Button Clicked at time: " + (new Date());
                dojo.byId("output").innerHTML = status;
                console.debug(status);
            }
        }

        //Put "onload" logic in here.
        dojo.addOnLoad(function(){
            dojo.connect(dojo.byId("testButton"), "onclick", Commands, "sayHello");
        });
    </script>
</head>
<body>

    <h1>Sample Dojo 1.0.0 xdomain page</h1>
    <p>
        <button id="testButton">Click Me</button>
    </p>
    <p id="output">
    </p>
</body>
</html>
by 키트 | 2008/04/04 08:39 | Ajax | 트랙백 | 덧글(0)

NetBeans에서 ImageIcon구현시 문제

new ImageIcon(getClass().getResource("images/1.jpg"));

getClass().getResource()
by 키트 | 2008/01/17 15:40 | 트랙백 | 덧글(0)
<< 이전 페이지 다음 페이지 >>