이 블로그 검색

2011년 3월 31일 목요일

토글

$(this).next('ul').slideToggle('normal').siblings('ul:visible').slideUp('normal');


$(this).next('ul').slideToggle('normal');
$(this).siblings('ul:visible').slideUp('normal');

첫번째 것 과 두번째 것은 결과가 다르다.

왜냐하면 $(this).siblings('ul:visible').slideUp('normal');을 실행할대 siblings에 $(this).next('ul').slideToggle('normal');에서 visible로 바뀐 ul태그도 포함이 되어버리기 때문이다.

첫번째 것에는
$(this).next('ul').slideToggle('normal').siblings('ul:visible') 여기까지 쿼리가 실행되었을때 $(this).next('ul')값이 아직 ul: not visible이기 때문이다.

2011년 3월 28일 월요일

자바 정렬


아래 두가지 방법이 있다.

java.lang Interface Comparable<T>
java.util Interface Comparator<T>

두 인터페이스를 이용해서 Collections.sort를 이용해 정렬을 할 수가 있는데,
List에 들어가는 객체에 Comparable을 implements함으로써, 정렬을 할 수있게 된다.

방법1. Comparable을 implements한다.

class PersonalInfo implements Comparable<PersonalInfo>{
 
 private String name = null;
 
 private String phoneNumber = null;
 
 public String getName() {
  return name;
 }
 
 public void setName(String name) {
   this.name = name;
 }
 
 public String getPhoneNumber() {
  return phoneNumber;
 }
 
 public void setPhoneNumber(String phoneNumber) {
  this.phoneNumber = phoneNumber;
 }
 
  public boolean getSortingMode() {
  return sortingMode;
 }
 public void setSortingMode(boolean sortingMode) {
  this.sortingMode = sortingMode;
 }
 
 
@Override
 public int compareTo(PersonalInfo o) {
    return name.compareTo( o.getName() );
  }
}

compareTo라는 메소드를 구현해야 하는데, 그 안에 비교하고자 하는 항목을 compareTo를 이용하여
비교해준 후,
Collections.sort()의 파라미터로 PersonalInfo객체가 들어있는 리스트를 넣어주기만 하면 된다.

위와 같은 방법은 편리하나, 여러가지 항목으로 정렬을 해야 할 경우 제약이 좀 있다.

그래서 사용하는 것이,
바로 Comparator 이다.

방법2. Comparator사용.

     Comparator<PersonalInfo> comparator = new Comparator<PersonalInfo>(){
      @Override
      public int compare(PersonalInfo o1, PersonalInfo o2) {      
       return o1.getName().compareTo( o2.getName() );
      }      
     };
     Collections.sort( list, comparator );

와 같은 방법으로 할 수 있다. 여러개의 정렬 항목에 따른 comparator를 만든 후, Collections의 파라미터로 던져주면,
정렬은 더이상 고민하지 않아도 될 것이다.

참고로 Collections.sort()의 documents내용은 다음과 같다.
public static <T extends Comparable<? super T>> void sort(List<T> list)
public static <T> void sort(List<T> list, Comparator<? super T> c)

2011년 3월 25일 금요일

클릭하는 위치에 팝업창띄우기

<script type="text/javascript">
function abspos(e){
    this.x = e.clientX + (document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft);
    this.y = e.clientY + (document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop);
    return this;
}


function itemClick(e){
    var ex_obj = document.getElementById('lay');
    if(!e) e = window.Event;
    pos = abspos(e);
    ex_obj.style.left = pos.x+"px";
    ex_obj.style.top = (pos.y+10)+"px";
    ex_obj.style.display = ex_obj.style.display=='none'?'block':'none';
}
</script>



<div id="lay" style="position:absolute; display:none;">
내용레이어입니다.
</div>

<span onclick="itemClick(event);">클릭</span>
<a href="#" onclick="itemClick(event);">클릭</a>
<!--<input type="button" onclick="itemClick(event);" value="클릭">  -->

onclick 이벤트는 span, div, button에 사용하는 게 옮음.
a태그에서는 사용하지 않는 것이 좋음
a태그에 onclick를 하면 클릭후 화면 제일위로 이동됨

2011년 3월 23일 수요일

스마트폰으로 접근시 모바일홈페이지로 자동이동

<% 
String browser = request.getHeader("User-Agent");
boolean result = false;
if (browser.indexOf("Android") >0) {  // 안드로이드
 result = true;
 } else if (browser.indexOf("iphone","iPod","PPC") > 0) {  // 아이폰등등..
 result = true;
 }
 if (result == true) {
 response.sendRedirect("이동할경로");
 }
%>









<script type="text/javascript">
var mobileKeyWords = new Array('iPhone', 'iPod', 'BlackBerry', 'Android', 'Windows CE', 'LG', 'MOT', 'SAMSUNG', 'SonyEricsson'); 
for (var word in mobileKeyWords){ 
    if (navigator.userAgent.match(mobileKeyWords[word]) != null){ 
        location.href = "http://m.i-sh.co.kr/"; 
        break; 
    } 



</script>

2011년 3월 14일 월요일

JDOQL

  • As described below in the discussion of inequality filters, a query can only have one not-equal filter, and such a query cannot have other inequality filters.
  • In other words, || is only legal in situations where the filters it separates can be combined into a single contains() filter:
  • In other words, || is only legal in situations where the filters it separates can be combined into a single contains() filter:
  •  if a query specifies inequality filters on a property and sort orders on other properties, the property used with the inequality filters must be ordered before the other properties.