2008-09-08 4 views
0

동적 내용 (중첩 태그)의 포함 된 사용자 정의 태그가 렌더링되지 않습니다.동적 내용 (중첩 태그)에 포함 된 사용자 정의 태그가 렌더링되지 않음

javabean에서 동적 컨텐트를 가져 와서 html로 처리하기 위해 사용자 목록에 객체 목록을 전달하는 페이지가 있습니다. 각 개체에는 출력 할 html 묶음이 있습니다.이 html에는 렌더링되고 싶은 두 번째 사용자 정의 태그가 있습니다. 문제는 태그 호출이 일반 텍스트로 렌더링된다는 것입니다.

예를 들어 나에게 도움이 될 수 있습니다.

1 데이터베이스에서 정보를 가져 와서 javabean을 통해 페이지로 반환하십시오. 이 정보를 사용자 정의 태그로 보내 출력하십시오.

<jsp:useBean id="ImportantNoticeBean" scope="page" class="com.mysite.beans.ImportantNoticeProcessBean"/> <%-- Declare the bean --%> 
<c:forEach var="noticeBean" items="${ImportantNoticeBean.importantNotices}"> <%-- Get the info --%> 
    <mysite:notice importantNotice="${noticeBean}"/> <%-- give it to the tag for processing --%> 
</c:forEach> 

이 태그해야 같은 상자 DIV 너무

*SNIP* class for custom tag def and method setup etc 
out.println("<div class=\"importantNotice\">"); 
out.println(" " + importantNotice.getMessage()); 
out.println(" <div class=\"importantnoticedates\">Posted: " + importantNotice.getDateFrom() + " End: " + importantNotice.getDateTo()</div>"); 
out.println(" <div class=\"noticeAuthor\">- " + importantNotice.getAuthor() + "</div>"); 
out.println("</div>"); 
*SNIP* 

이 미세 렌더링하고, 상기 실시 예에서, 예를 들면, I가 있었다 경우

<div class="importantNotice"> 
    <p>This is a very important message. Everyone should pay attenton to it.</p> 
    <div class="importantnoticedates">Posted: 2008-09-08 End: 2008-09-08</div> 
    <div class="noticeAuthor">- The author</div> 
</div> 

2 예상대로 출력 importantNotice.getMessage()에 사용자 정의 태그가 있습니다. 문자열 :

*SNIP* "This is a very important message. Everyone should pay attenton to it. <mysite:quote author="Some Guy">Quote this</mysite:quote>" *SNIP* 

중요한주의 사항은 잘 나타내지 만 견적 태그는 처리되지 않고 단순히 문자열에 삽입되어 일반 text/html 태그로 지정됩니다.

<div class="importantNotice"> 
    <p>This is a very important message. Everyone should pay attenton to it. <div class="quote">Quote this <span class="authorofquote">Some Guy</span></div></p> // or wahtever I choose as the output 
    <div class="importantnoticedates">Posted: 2008-09-08 End: 2008-09-08</div> 
    <div class="noticeAuthor">- The author</div> 
</div> 

<div class="importantNotice"> 
    <p>This is a very important message. Everyone should pay attenton to it. <mysite:quote author="Some Guy">Quote this</mysite:quote></p> 
    <div class="importantnoticedates">Posted: 2008-09-08 End: 2008-09-08</div> 
    <div class="noticeAuthor">- The author</div> 
</div> 

보다는

나는이 프로세서 및 사전 프로세서과 관련이있다하지만 난이 일을 만드는 방법에 대해 확실하지 오전 알고있다. 그냥

<bodycontent>JSP</bodycontent> 

를 사용

답변

1

충분하지 않습니다.

JspFragment body = getJspBody(); 
StringWriter stringWriter = new StringWriter(); 
StringBuffer buff = stringWriter.getBuffer(); 
buff.append("<h1>"); 
body.invoke(stringWriter); 
buff.append("</h1>"); 
out.println(stringWriter); 

(예 : SimpleTag doTag 메서드의 경우)을 렌더링해야합니다.

그러나 질문의 ​​코드에서 내부 태그는 JSP의 일부로 렌더링되지 않지만 일부 임의의 문자열로 표시되는 것으로 나타났습니다. 나는 당신이 JSP 번역자가 그것을 파싱하도록 강요 할 수 있다고 생각하지 않는다.

당신은 귀하의 경우 정규 표현식을 사용하거나이 같은 JSP를하는 방식으로 코드를 재 설계를 시도 할 수 있습니다 :

<jsp:useBean id="ImportantNoticeBean" scope="page class="com.mysite.beans.ImportantNoticeProcessBean"/> 
<c:forEach var="noticeBean" items="${ImportantNoticeBean.importantNotices}"> 
    <mysite:notice importantNotice="${noticeBean}"> 
     <mysite:quote author="Some Guy">Quote this</mysite:quote> 
     <mysite:messagebody author="Some Guy" /> 
    </mysite:notice> 
</c:forEach> 

나는 정규 표현식으로 이동 whould.

0

달성하고자하는 데이터가 페이지 내부에있는 "마크 업"이므로 클래스 내부의 태그가되어서는 안된다는 점에서 "태그 지정의 아키텍처"를 변경하려고합니다 (obscurity JSP Servlet 엔진의 평가 프로그램 스레드를 얻을 수 있습니다.

당신은 아마 BodyTagSupport 클래스 확장과 함께 "협력 태그"를 사용하고 및/또는 목적은 자궁강 저장하기로 공유 시체를 처리 반복 JSP가 포워드 될때까지() 메소드에 EVAL_BODY_BUFFERED을 반환 표준 절차 내에서 더 이상 찾아 낼 것입니다 무엇 세션의 응용 프로그램 계층 또는 사용자의 세션에있는 데이터

자세한 내용은 oracle j2ee custom tags tutorial을 참조하십시오.