Unable to Create Page from a Template That Uses the Attachments Macro

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

症状

When attempting to create a page from a Confluence Page Template that contains the {attachments} macro and one or more page template variables, Confluence is unable to create the page and an error message is generated after the Insert Variables button is selected.

The error message generated is similar to this:

2010-02-01 12:04:09,274 ERROR [http-8080-11] [atlassian.confluence.servlet.ConfluenceServletDispatcher] sendError Could not execute action
 -- url: /pages/doenterpagevariables.action | userName: admin | referer: http://localhost:8080/pages/createpage-entervariables.action
java.lang.ClassCastException: com.atlassian.confluence.pages.Draft cannot be cast to com.atlassian.confluence.pages.AbstractPage
	at com.atlassian.confluence.pages.persistence.dao.hibernate.HibernateAbstractPageDao.getAbstractPageById(HibernateAbstractPageDao.java:17)
	at sun.reflect.GeneratedMethodAccessor449.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:304)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
	at $Proxy33.getAbstractPageById(Unknown Source)
	at com.atlassian.confluence.pages.DefaultPageManager.getAbstractPage(DefaultPageManager.java:115)
	at sun.reflect.GeneratedMethodAccessor448.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	...
        ...

原因

This occurs because the {attachments} macro assumes that it is only ever rendered in the context of a Confluence Page. The macro causes the error when it is rendered in the "Draft" mode required for the user to enter in the page template variable values.

回避策

A suggested workaround for this problem is to write a user macro that includes the {attachments} macro in pages, but does not include the {attachments} macro in drafts. Information on creating user macros can be found in the Confluence Writing User Macros guide. The page templates can be updated to use this new user macro, instead of using the {attachments} macro directly.

Here is an example of a user macro that would solve this problem in Confluence versions 3.x and below:

#if ($content.getClass().getName().equals("com.atlassian.confluence.pages.Draft"))
*NOTE:* The Confluence \{attachments\} macro will be included here when the page is created.
#else
{attachments}
#end

When creating and saving the macro, make sure that the Output is set to Macro generates wiki markup.

For Confluence versions 4.x and above:

## @noparams
#if ($content.getClass().getName().equals("com.atlassian.confluence.pages.Draft"))
*NOTE:* The Confluence \{attachments\} macro will be included here when the page is created.
#else
<ac:macro ac:name="attachments" />
#end

Last modified on Mar 30, 2016

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.