AdobeのWebサイトの記事に従って、単純なサービスレイヤーインターフェイスを作成しようとしています(参照用にコードヘッダーにリンクが表示されています)。テンプレート/コンポーネントに基づいてページを読み込もうとすると、エラーが発生します: メソッド [メソッド名] は、タイプ [コンポーネント名]_jsp に対して未定義です。public でアクセス修飾子を使用せず、異なる署名と戻り値の型を使用して、メソッドを呼び出し元のコードの上に移動し、常に同じ結果を得る、より単純な 1 行のメソッドを使用してみました。メソッド名をコメントアウトし、中括弧で囲まれたブロックとしてコードを含めるだけで、コンパイルは成功します。これは CQ/AEM v5.6.1 では不可能ですか、それとも何か問題がありますか?
コード全体と例外を以下に示します (簡単にするために、さまざまな実験バージョンをコメントアウトし、元の getPath(...) メソッドを省略しています)。よろしくお願いいたします。
<%--
apipage component: implements service layer pages
see: http://blogs.adobe.com/contentmanagement/2012/08/19/how-to-integrate-with-other-web-services-without-creating-osgi-packages/
--%><%
%><%@include file="/libs/foundation/global.jsp"%>
<%@page import="org.apache.commons.httpclient.HttpClient,
org.apache.commons.httpclient.params.HttpClientParams,
org.apache.commons.httpclient.DefaultHttpMethodRetryHandler,
org.apache.commons.httpclient.methods.PostMethod,
org.json.JSONObject"
%><%@page session="false" %><%
%><%
if (request.getParameter("action") != null) {
if (request.getParameter("action").equals("getFields") &&
request.getParameter("param1") != null &&
request.getParameter("param2") != null) {
//response.setContentType("application/json");
// out.write(getPath((String)request.getParameter("param1"), (String)request.getParameter("param2"));
String str1 = "param1";
String str2 = "param2";
//out.write(getPath(str1, str2));
int i = doNothing();
}
} else {
response.setContentType("application/json");
out.write("{\"error\":\"error\"}");
}
/*public*/ int doNothing() {
return 1;
}
%>
Error during include of component '/apps/trp/components/layouts/apipage'
Error Message:
org.apache.sling.api.scripting.ScriptEvaluationException: org.apache.sling.scripting.jsp.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 24 in the jsp file: /apps/trp/components/layouts/apipage/apipage.jsp
The method doNothing() is undefined for the type apipage_jsp
21: String str1 = "param1";
22: String str2 = "param2";
23: //out.write(getPath(str1, str2));
24: int i = doNothing();
25: }
26: } else {
27: response.setContentType("application/json");
An error occurred at line: 31 in the jsp file: /apps/trp/components/layouts/apipage/apipage.jsp
Syntax error on token "int", new expected
28: out.write("{\"error\":\"error\"}");
29: }
30:
31: /*public*/ int doNothing() {
32: return 1;
33: }
34:
An error occurred at line: 31 in the jsp file: /apps/trp/components/layouts/apipage/apipage.jsp
doNothing cannot be resolved to a type
28: out.write("{\"error\":\"error\"}");
29: }
30:
31: /*public*/ int doNothing() {
32: return 1;
33: }
34:
An error occurred at line: 31 in the jsp file: /apps/trp/components/layouts/apipage/apipage.jsp
Syntax error, insert ";" to complete Statement
28: out.write("{\"error\":\"error\"}");
29: }
30:
31: /*public*/ int doNothing() {
32: return 1;
33: }
34:
An error occurred at line: 32 in the jsp file: /apps/trp/components/layouts/apipage/apipage.jsp
Void methods cannot return a value
29: }
30:
31: /*public*/ int doNothing() {
32: return 1;
33: }
34:
35: /*
Processing Info:
Page = /content/trp/en/AfrescoAPI
Resource Path = /content/trp/en/AfrescoAPI/jcr:content
Cell = apipage
Cell Search Path = apipage
Component Path = /apps/trp/components/layouts/apipage
Sling Request Progress:
0 (2013-11-14 10:41:01) TIMER_START{Request Processing}
0 (2013-11-14 10:41:01) COMMENT timer_end format is {<elapsed msec>,<timer name>} <optional message>
0 (2013-11-14 10:41:01) LOG Method=GET, PathInfo=/content/trp/en/AfrescoAPI.html
0 (2013-11-14 10:41:01) TIMER_START{ResourceResolution}
0 (2013-11-14 10:41:01) TIMER_END{0,ResourceResolution} URI=/content/trp/en/AfrescoAPI.html resolves to Resource=JcrNodeResource, type=cq:Page, superType=null, path=/content/trp/en/AfrescoAPI
0 (2013-11-14 10:41:01) LOG Resource Path Info: SlingRequestPathInfo: path='/content/trp/en/AfrescoAPI', selectorString='null', extension='html', suffix='null'
0 (2013-11-14 10:41:01) TIMER_START{ServletResolution}
0 (2013-11-14 10:41:01) TIMER_START{resolveServlet(JcrNodeResource, type=cq:Page, superType=null, path=/content/trp/en/AfrescoAPI)}
0 (2013-11-14 10:41:01) TIMER_END{0,resolveServlet(JcrNodeResource, type=cq:Page, superType=null, path=/content/trp/en/AfrescoAPI)} Using servlet /libs/foundation/components/primary/cq/Page/Page.jsp
0 (2013-11-14 10:41:01) TIMER_END{0,ServletResolution} URI=/content/trp/en/AfrescoAPI.html handled by Servlet=/libs/foundation/components/primary/cq/Page/Page.jsp
0 (2013-11-14 10:41:01) LOG Applying Requestfilters
0 (2013-11-14 10:41:01) LOG Calling filter: org.apache.sling.bgservlets.impl.BackgroundServletStarterFilter
0 (2013-11-14 10:41:01) LOG Calling filter: org.apache.sling.i18n.impl.I18NFilter
0 (2013-11-14 10:41:01) LOG Calling filter: org.apache.sling.rewriter.impl.RewriterFilter
0 (2013-11-14 10:41:01) LOG Calling filter: com.day.cq.wcm.designimporter.CanvasPageDeleteRequestFilter
0 (2013-11-14 10:41:01) LOG Calling filter: com.adobe.cq.history.impl.HistoryRequestFilter
0 (2013-11-14 10:41:01) LOG Calling filter: com.day.cq.wcm.core.impl.WCMRequestFilter
0 (2013-11-14 10:41:01) LOG Calling filter: com.adobe.granite.optout.impl.OptOutFilter
0 (2013-11-14 10:41:01) LOG Calling filter: com.day.cq.theme.impl.ThemeResolverFilter
0 (2013-11-14 10:41:01) LOG Calling filter: com.day.cq.wcm.foundation.forms.impl.FormsHandlingServlet
0 (2013-11-14 10:41:01) LOG Calling filter: org.apache.sling.engine.impl.debug.RequestProgressTrackerLogFilter
0 (2013-11-14 10:41:01) LOG Calling filter: com.day.cq.wcm.mobile.core.impl.redirect.RedirectFilter
0 (2013-11-14 10:41:01) LOG RedirectFilter did not redirect (MobileUtil.isMobileResource() returns false)
0 (2013-11-14 10:41:01) LOG Calling filter: com.day.cq.wcm.core.impl.warp.TimeWarpFilter
0 (2013-11-14 10:41:01) LOG Calling filter: com.day.cq.wcm.core.impl.AuthoringUIModeServiceImpl
0 (2013-11-14 10:41:01) LOG Applying Componentfilters
0 (2013-11-14 10:41:01) LOG Calling filter: com.day.cq.personalization.impl.TargetComponentFilter
0 (2013-11-14 10:41:01) LOG Calling filter: com.day.cq.wcm.core.impl.WCMComponentFilter
0 (2013-11-14 10:41:01) LOG Calling filter: com.day.cq.wcm.core.impl.WCMDebugFilter
0 (2013-11-14 10:41:01) TIMER_START{/libs/foundation/components/primary/cq/Page/Page.jsp#0}
0 (2013-11-14 10:41:01) LOG Including resource JcrNodeResource, type=trp/components/layouts/apipage, superType=null, path=/content/trp/en/AfrescoAPI/jcr:content (SlingRequestPathInfo: path='/content/trp/en/AfrescoAPI/jcr:content', selectorString='null', extension='html', suffix='null')
0 (2013-11-14 10:41:01) TIMER_START{resolveServlet(JcrNodeResource, type=trp/components/layouts/apipage, superType=null, path=/content/trp/en/AfrescoAPI/jcr:content)}
16 (2013-11-14 10:41:01) TIMER_END{16,resolveServlet(JcrNodeResource, type=trp/components/layouts/apipage, superType=null, path=/content/trp/en/AfrescoAPI/jcr:content)} Using servlet /apps/trp/components/layouts/apipage/apipage.jsp
16 (2013-11-14 10:41:01) LOG Applying Includefilters
16 (2013-11-14 10:41:01) LOG Calling filter: com.day.cq.personalization.impl.TargetComponentFilter
16 (2013-11-14 10:41:01) LOG Calling filter: com.day.cq.wcm.core.impl.WCMComponentFilter
16 (2013-11-14 10:41:01) LOG Calling filter: com.day.cq.wcm.core.impl.WCMDebugFilter
16 (2013-11-14 10:41:01) TIMER_START{/apps/trp/components/layouts/apipage/apipage.jsp#1}
156 (2013-11-14 10:41:01) LOG SCRIPT ERROR: org.apache.sling.scripting.jsp.jasper.JasperException: Unable to compile class for JSP: //An error occurred at line: 24 in the jsp file: /apps/trp/components/layouts/apipage/apipage.jsp/The method doNothing() is undefined for the type apipage_jsp/21: String str1 = "param1";/22: String str2 = "param2";/23: //out.write(getPath(str1, str2));/24: int i = doNothing();/25: }/26: } else {/27: response.setContentType("application/json");///An error occurred at line: 31 in the jsp file: /apps/trp/components/layouts/apipage/apipage.jsp/Syntax error on token "int", new expected/28: out.write("{\"error\":\"error\"}");/29: }/30: /31: /*public*/ int doNothing() {/32: return 1;/33: }/34: ///An error occurred at line: 31 in the jsp file: /apps/trp/components/layouts/apipage/apipage.jsp/doNothing cannot be resolved to a type/28: out.write("{\"error\":\"error\"}");/29: }/30: /31: /*public*/ int doNothing() {/32: return 1;/33: }/34: ///An error occurred at line: 31 in the jsp file: /apps/trp/components/layouts/apipage/apipage.jsp/Syntax error, insert ";" to complete Statement/28: out.write("{\"error\":\"error\"}");/29: }/30: /31: /*public*/ int doNothing() {/32: return 1;/33: }/34: ///An error occurred at line: 32 in the jsp file: /apps/trp/components/layouts/apipage/apipage.jsp/Void methods cannot return a value/29: }/30: /31: /*public*/ int doNothing() {/32: return 1;/33: }/34: /35: /*/
156 (2013-11-14 10:41:01) TIMER_END{140,/apps/trp/components/layouts/apipage/apipage.jsp#1}
172 (2013-11-14 10:41:01) LOG Found processor for post processing ProcessorConfiguration: {contentTypes=[text/html],order=-1, active=true, valid=true, processErrorResponse=true, pipeline=(generator=Config(type=htmlparser, config={}), transformers=(Config(type=linkchecker, config={}), Config(type=mobile, config=JcrPropertyMap [node=node /libs/cq/config/rewriter/default/transformer-mobile, values={component-optional=true, jcr:primaryType=nt:unstructured}]), Config(type=mobiledebug, config=JcrPropertyMap [node=node /libs/cq/config/rewriter/default/transformer-mobiledebug, values={component-optional=true, jcr:primaryType=nt:unstructured}]), Config(type=contentsync, config=JcrPropertyMap [node=node /libs/cq/config/rewriter/default/transformer-contentsync, values={component-optional=true, jcr:primaryType=nt:unstructured}]), serializer=Config(type=htmlwriter, config={}))}
172 (2013-11-14 10:41:01) TIMER_END{172,Request Processing} Dumping SlingRequestProgressTracker Entries