포함된 사용자 지정표에 동적인 내용(중첩된 태그)을 렌더링되지 않았습니다

StackOverflow https://stackoverflow.com/questions/49267

  •  09-06-2019
  •  | 
  •  

문제

포함된 사용자 지정표에 동적인 내용(중첩된 태그)을 렌더링되지 않았습니다.

내가 있는 페이지를 가져오는 동적 콘텐츠에 자바빈과를 전달합체의 목록을 사용자 정의 태그를 처리를 위해 html.각 객체가 무리의 html 을 출력을 포함하는 두 번째 사용자 정의하는 태그를 나는 또한 렌더링됩니다.문제는 태그를 호출로 렌더링되 plaintext.

예 될 수도 있습니다.

1 정보를 데이터베이스에서 반환하는 페이지를 통해 자바빈.이 정보를 전송하여 사용자 지정표에 대한 출력.

<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*

이로 괜찮다고 예상대로

<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*

중요한 통지를 렌더링되지는 견적 태그를 처리되지 않으며 단순히 삽입된 문자열을 넣어 plain text/html 태그입니다.

<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>

<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>

이와 함께 할 수 있는 프로세서와 사전 프로세서 그러나 내가 아니하는 방법에 대해 확실 이 작업을 확인합니다.

도움이 되었습니까?

해결책

<bodycontent>JSP</bodycontent>

는 충분하지 않습니다.당신이해야 할 다음과 같 soimething

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 번역가를 구문 분석합니다.

당신이 사용할 수 있습 regexp 귀하의 경우에는 시도하거나 재설계하는 코드에서는 방법을 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>

I whould 가 regexp.

다른 팁

내가 될 경향이 변경"아키텍처의 태그"에서는 데이터가 당신을 달성하지 않아야에 의해 태그의 내부에는 클래스는 그대로"마크업"한 페이지(하지만 무명 그것이 가능한 평가 프로그램의 실 JSP Servlet engine).

당신이 어떤 것도 더 이내에 표준 절차를 사용하는 것이"태그 협력으로" BodyTagSupport 클래스를 확장하고 돌아 EVAL_BODY_BUFFERED 에 doStartTag()메소드는 반복하는 프로세스는 몸 그리고/또는 개체의 공유 와 같은 저장 retrived 데이터에서 응용 프로그램 계층의 세션이나 세션에 이용자에게 있습니다.

oracle j2ee 튜토리얼의 사용자 태그 자세한 내용은.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top