커스텀 태그 만들기


1. 라이브러리 임포트



jsp-api.jar



2. Tag Servlet 작성


package tags;


import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;

public class helloTagServlet implements Tag {
  private PageContext pageContext;
  private Tag parentTag;

  public void setPageContext(PageContext pageContext) {
    this.pageContext = pageContext;
  }

  public void setParent(Tag parentTag) {
    this.parentTag = parentTag;
  }

  public Tag getParent() {
    return this.parentTag;
  }


  public int doStartTag() throws JspException {
    try {
      JspWriter out = pageContext.getOut();

      out.print("Hello World!");

    } catch(Exception e) {
      throw new JspException(e.getMessage());
    }
      return SKIP_BODY;
    }

    public int doEndTag() throws JspException {
      return EVAL_PAGE;
    }

  public void release() {}
}


3. tld 작성


<?xml version="1.0" ?>

<taglib 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 
            web-jsptaglibrary_2_0.xsd"
        version="2.0">

  <tlib-version>1.0</tlib-version>
  <jsp-version>2.0</jsp-version>
  <short-name>helloTag</short-name>
  <tag>
    <name>helloTag</name>
    <tag-class>tags.helloTagServlet</tag-class>
    <body-content>empty</body-content>
  </tag>
</taglib>

4. web.xml에 추가


<?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 web-app_2_4.xsd" version="2.4"> <jsp-config> <taglib> <taglib-uri>tags/hello</taglib-uri> <taglib-location>/WEB-INF/lib/hello.tld</taglib-location> </taglib> </jsp-config> </web-app>


5. jsp에 사용


uri web.xml에서 설정한 <taglib-uri>의 값을 설정



<%@ page contentType="text/html; charset=windows-31j"

         import="tags.*" %>


<%@ taglib uri=" tags/hello "

    prefix="hello" %>


<HTML>

<BODY>


<hello:helloTag />

















Posted by tenn
,

[xcode] delegate

iPhone 2012. 4. 24. 16:02

//// FirstView      

액션이 일어남에 따라 핸들링이 있는 부분.

클래스에 델리게이트 선언

액션이 일어나는 클래스의 델리게이션 멤버에  self 대입.


//// SecondView

액션이 일어나는 부분

프로토콜 선언

델리게이트 멤버를가짐





//// First View




// h


#import "SecondViewController.h"


@interface ViewController : UIViewController<SecondViewDelegate>




// m



- (IBAction)btnAction:(id)sender {

    

    SecondViewController *secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondView"];

    

    secondViewController.delegate = self;

    

    [self.navigationController pushViewController:secondViewController animated:YES];

    

}








//// SecondView



///h


@protocol SecondViewDelegate

@required

-(void)done:(NSString *)str;

@end


@interface SecondViewController : UIViewController

@property (strong, nonatomic) id<SecondViewDelegate> delegate;



///m

- (IBAction)btnAction:(id)sender {   // btnAction이 핸들링 될때, 델리게이트의 메소드 호출

    [self.delegate done:self.tf.text];

    [self.navigationController popViewControllerAnimated:YES];

}
















Posted by tenn
,

[xcode] 기본 컨트롤.

iPhone 2012. 4. 20. 11:53



//// 버튼


    UIButton *okBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    okBtn.frame = CGRectMake(61, 210, 200, 30);

    [okBtn setTitle:@"OK Button" forState:UIControlStateNormal];


//// 라벨


    UILabel *label = [[UILabel allocinitWithFrame:CGRectMake(1001010024)];

    label.backgroundColor = [UIColor clearColor];

    label.textColor = [UIColor whiteColor];

    label.text = @"label1";

//// 텍스트 필드


    UITextField *tf = [[UITextField allocinitWithFrame:CGRectMake(101010024)]; 

    tf.backgroundColor = [UIColor blueColor];

    tf.borderStyle = UITextBorderStyleLine;

// CGRectMake의 1, 2인수는 시작점. 3,4인수는 프레임의 크기.


    UITextField *tf1 = [[UITextField allocinitWithFrame:CGRectMake(104010024)];    

    tf1.backgroundColor = [UIColor whiteColor];

    tf1.borderStyle = UITextBorderStyleLine;


    [self.view addSubview:tf];

    [self.view addSubview:tf1];


//// 루프로 컨트롤 생성, 접근


    UITextField *textField;

    for (int i=0; i < 5; i++){

        

        textField =

        [[UITextField allocinitWithFrame:CGRectMake(1010 + 30 * i, 10024)];

        textField.borderStyle = UITextBorderStyleLine;

        textField.tag = i;

  //생성된 컨트롤러의 접근을 위해 태그 붙임.

        [self.view addSubview:textField];


    }

    

    UITextField *tf = [self.view viewWithTag:3];

    tf.text = @"tag access";

    [tf addTarget:self action:@selector(endEditing:) forControlEvents:UIControlEventEditingDidEnd];



- (void) endEditing:(id)sender{

//or (IBAction)

//Code만으로 할때는 void리턴타입이어도 됨. 파라메터에 주의.

NSLog(@"endEditing...");

}










Posted by tenn
,