Create a new page from a template, all matching instances of $(form-element-name) are replaced in the template text with the submitted form values.

There is one required form-element-name (handler parameter), newPageName this (obviously) will be used as the name of the new page.

If the newPageName already exists, this handler simply returns a message stating that. It does not by default auto-increment a suffix for the page. If you set a handler parameter named autoIncrement it will begin suffixing newPageName with a number until it finds an unused page name.

Originally available in the McKessonApsWikiPlugins, known to work with post-2.1.127.

This handler is now part of the CeryleWikiPlugins. If using the earlier version from the McKessonApsWikiPlugins the path will be "com.mckessonaps.jspwiki.handler.newpage.NewPageHandler". If downloaded as part of the current CeryleWikiPlugins the path will be "org.ceryle.wiki.handler.NewPageHandler".

If the path is specified as part of the comma-separated values of the jspwiki.plugin.searchPath property found in $WIKI_HOME/WEB-INF/jspwiki.properties, you won't need to fully qualify the plugin when used (i.e., just use "NewPageHandler").

Parameters#

newPageName
required, If the newPageNamePrefix+newPageName already exists, this handler simply returns a message stating that unless autoIncrement is set.
autoIncrement
If this parameter is present the handler will suffix the newPageNamePrefix+newPageName with a # until it finds an unused page name, # starts at '1'.
newPageNamePrefix
Prepends this value to the newPageName, useful if you want all created pages to have the same prefix.

The NewPageHandler could be considered a general purpose replacement for the BugReportHandler.


Example Use-Case: Create a TODO item page via a form.#

[{FormSet form='newTodoForm'}]

[{FormOutput form='newTodoForm' handler='NewPageHandler' 

$(description)

----
[TODO] [$(priority)]

}]

[{FormOpen form='newTodoForm'}]

;__Priority__: [{FormSelect name='priority' value='HIGH;*MEDIUM;LOW'}]  
;__TODO Name__: [{FormInput name='newPageName' type='text' size=50}] 
;__Description__:[{FormTextarea name='description' rows=6 cols=50}]

![{FormInput name='createNewTaskButton' type='submit' value='New TODO'}] 

[{FormClose}]



Very useful! I would like to use just a fixed prefix and an automatically calculated numeric postfix, like in the pages generate by the TODO plugin. With the current version I was forced to create a text input area just to fullfil the requirement. It would be nice to remove the hard requirement on newPageName if the autoIncrement and newPagePrefix were set.

-- NascifAbousalhNeto


Question: is there an easy way to insert the value of standard wiki variables, e.g. $(username) ? --DF

Dunno, but the developer might want to look at VariableManager.expandVariables(). I don't like the fact that people are inventing their own ways of marking variables. It creates confusion. --JanneJalkanen

Mmm, probably the reason for this syntax is that the wiki engine currently doesnt support calls to a plugin or variable (e.g. [{$variable}]) nested inside the body of another plugin. Which creates an important limitation w.r.t. what info can be put inside the body of a plugin.
E.g. the TablePlugin tries to solve this with a clumsy escape character concept; this plugin uses an alternative variable syntax. I this worth to be put as a new idea? --DF

Certainly. It would be a good idea to use the SubmitNewIdea -page, because then the idea would be trackable - otherwise it might be easily forgotten in the WikiMess. --JanneJalkanen
mission accomplished : see IdeaSupportNestedPluginsInsideTheBodyOfAPlugin


Ok, showing my naiveté in programming. ;) Would it be possible to use this plugin inside of a jspwiki.specialPage JSP page (say AddPage.jsp) as a way of using container managed security to prevent access to the add new page form? --Thanks!

Yes. See PluginTag. Or in this case, probably TranslateTag would be a smarter choice (you want to insert multiple tags).

Sorry to clutter this page with my questions, but could someone look at the related question (first question) on the StupidQuestions page. I can put the new jsp page inside of a current wiki page, but if I access it directly it doesn't work.

11/07/05 I have been playing around with this plugin. It starts to have problems when there is an page being built that attempts to use a plugin. Plugin to create a page that needs a plugin. I managed to get around it.. but it is ugly. Seems like it might be easier to set a "Pay no attention to the man behind the curtain" tag at the beginning of the page definition section so the general Wiki-translation is skipped. RS
At this time (v2.3.41 and before) do not allow nested plugins. There is a patch howver that might allow you what you want. I do not think that the ramifications of nested plugins has been fully thought thru at this time though. See the patch attached to Bug Translator Reader Doesnt Allow Nested Plugins. I'm thinking that merging that patch into CVS head is maybe okay? I cannot think of a technical reason why nested plugins should be disallowed. Janne? Anyone? Any reason to not accept that patch? --JohnV

handle not found#

I tested in JSPWiki v2.2.33 and v2.4.6-beta I just copied the example above and got
 Could not find plugin NewPageHandler 
aren't the forms plugins included? where can I look at to try to find the problem? I put the jar with McKessonApsWikiPlugins in the WEB-INF/lib and restared the appl. However I thought this code was already included in the distribution.

--Adler


Hello - I changed the value from
'NewPageHandler'
to
'com.mckessonaps.jspwiki.handler.newpage.NewPageHandler'
This works for me with JSPWiki v2.2.33.

-- Leonardo Graf


Hi,

i patched a bug concerning UTF-8 (Umlaute in Pagenames and InputFields where not handled correctly), and added support for inlinded plugins -> simply use ({ }) instead of the normal plugin syntax within the plugin body. This is a fix for 2.2, inlinde plugin syntax within the plugin body of another plugin in 2.4 works i think.

see NewPageHandler.java(info)

--ChristophSauer 14-Sep-2006

example of inlined plugin syntax

[{FormOutput form='newTodoForm' handler='com.mckessonaps.jspwiki.handler.NewPageHandler' 

({Image src = 'logo.jpg'})

Damned Umlaute: München, Nürnberg

mail: $(mail)
}]


ContributedFormHandlers


I am getting the following error trying to run the NewPageHandler. I am running JSPWiki 2.4.53.

Is there support for the NewPageHandler for the latest JSPWiki?

2006-09-21 14:52:18,711 [http-8080-Processor25] INFO com.ecyrd.jspwiki.plugin.PluginManager test:http://mainframewiki:8080/test/Wiki.jsp - Plugin failed while executing:
java.lang.NoSuchMethodError: com.ecyrd.jspwiki.WikiPage: method <init>(Ljava/lang/String;)V not found
	at com.mckessonaps.jspwiki.handler.newpage.NewPageHandler.saveNewPage(NewPageHandler.java:108)
	at com.mckessonaps.jspwiki.handler.newpage.NewPageHandler.execute(NewPageHandler.java:64)
	at com.ecyrd.jspwiki.plugin.PluginManager.execute(PluginManager.java:368)
	at com.ecyrd.jspwiki.forms.FormOutput.execute(FormOutput.java:123)
	at com.ecyrd.jspwiki.plugin.PluginManager.execute(PluginManager.java:368)
	at com.ecyrd.jspwiki.parser.PluginContent.getText(PluginContent.java:84)
	at org.jdom.output.XMLOutputter.printTextRange(XMLOutputter.java(Compiled Code))
	at org.jdom.output.XMLOutputter.printElement(XMLOutputter.java(Compiled Code))
	at org.jdom.output.XMLOutputter.printContentRange(XMLOutputter.java(Compiled Code))
	at org.jdom.output.XMLOutputter.outputElementContent(XMLOutputter.java:445)
	at com.ecyrd.jspwiki.render.XHTMLRenderer.getString(XHTMLRenderer.java:61)
	at com.ecyrd.jspwiki.render.RenderingManager.getHTML(RenderingManager.java:248)
	at com.ecyrd.jspwiki.render.RenderingManager.getHTML(RenderingManager.java:285)
	at com.ecyrd.jspwiki.WikiEngine.textToHTML(WikiEngine.java:1365)
	at com.ecyrd.jspwiki.WikiEngine.getHTML(WikiEngine.java:1311)
	at com.ecyrd.jspwiki.tags.InsertPageTag.doWikiStartTag(InsertPageTag.java:117)
	at com.ecyrd.jspwiki.tags.WikiTagBase.doStartTag(WikiTagBase.java:85)
	at org.apache.jsp.templates.default_.PageContent_jsp._jspx_meth_wiki_InsertPage_0(PageContent_jsp.java:338)
	at org.apache.jsp.templates.default_.PageContent_jsp._jspService(PageContent_jsp.java:104)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java(Compiled Code))
	at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code))
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java(Compiled Code))
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java(Compiled Code))
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java(Compiled Code))
	at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code))
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java(Compiled Code))
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java(Compiled Code))
	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java(Compiled Code))
	at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java(Compiled Code))
	at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java(Compiled Code))
	at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java(Inlined Compiled Code))
	at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java(Compiled Code))
	at com.ecyrd.jspwiki.tags.ContentTag.doEndTag(ContentTag.java:126)
	at org.apache.jsp.templates.default_.ViewTemplate_jsp._jspx_meth_wiki_Content_0(ViewTemplate_jsp.java:337)
	at org.apache.jsp.templates.default_.ViewTemplate_jsp._jspService(ViewTemplate_jsp.java:137)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java(Compiled Code))
	at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code))
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java(Compiled Code))
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java(Compiled Code))
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java(Compiled Code))
	at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code))
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java(Compiled Code))
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java(Compiled Code))
	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java(Compiled Code))
	at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java(Compiled Code))
	at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java(Compiled Code))
	at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java(Inlined Compiled Code))
	at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java(Compiled Code))
	at com.ecyrd.jspwiki.tags.IncludeTag.doEndTag(IncludeTag.java:83)
	at org.apache.jsp.Wiki_jsp._jspService(Wiki_jsp.java:106)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java(Compiled Code))
	at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code))
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java(Compiled Code))
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java(Compiled Code))
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java(Compiled Code))
	at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code))
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java(Compiled Code))
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java(Compiled Code))
	at com.ecyrd.jspwiki.ui.WikiServletFilter.doFilter(WikiServletFilter.java:99)
	at com.ecyrd.jspwiki.ui.WikiJSPFilter.doFilter(WikiJSPFilter.java:75)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java(Compiled Code))
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java(Compiled Code))
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java(Compiled Code))
	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java(Compiled Code))
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java(Compiled Code))
	at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java(Compiled Code))
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java(Compiled Code))
	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java(Compiled Code))
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java(Compiled Code))
	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java(Compiled Code))
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java(Compiled Code))
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java(Compiled Code))
	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java(Compiled Code))
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java(Compiled Code))
	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java(Compiled Code))
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java(Compiled Code))
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java(Compiled Code))
	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java(Compiled Code))
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java(Compiled Code))
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java(Compiled Code))
	at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java(Compiled Code))
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java(Compiled Code))
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
	at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
	at java.lang.Thread.run(Thread.java:570)

--Rob Schramm, 21-Sep-2006


I'm having the same problem as Rob Schramm. Same Line of Code, when using the above example. I had a look into the JavaDoc. The Constructor WikiPage(java.lang.String) exists. Why isn't it visible? I'm using JSPWiki v2.4.53

--Daniel Kielmann, 04-Oct-2006


In order to enable compilation with JSPWiki 2.4.87, I had to make to small modifications (see comment 'FIX' in NewPageHandler2.java(info)):

  • WikiPage constructor required the WikiEngine
  • in safeParameter the obtained parameters are not checked if they are a String before casting

--marcus, 11-Jan-2007


I'm having problems with a FormTextArea element when using this plugin. I have a multi-element form which uses several FormTextArea elements. They work fine unless the input text includes a $ symbol, in which case I get a "Plugin failed" error message. If I use the BugReportHandler with a similar form, I don't get the error. (Unfortunately, the output from the bughandler is not acceptable for my purposes.) I realize that the $ symbol is used to signify a variable. Is some sort of special coding required to allow its use in a form text box?

I've posted this question here and on the Stupid Questions page but have not received any response. Is anybody out there?

-- Lynne Avery, 24-July-2007


Yeah, we are, but it may be that the author of the NewPageHandler is actually reading these. And I don't really have any experience with it :-(. Did you try contacting the author directly?

--JanneJalkanen, 25-Jul-2007


I'm not the original author of this plugin, JohnVolkar is, but I'm currently the maintainer. The NewPageHandler is now part of the CeryleWikiPlugins.

I just tested this out with the current version using the sample form found above (Example Use-Case: Create a TODO item page via a form). I was able to add a '$' to either of the input fields and the handler successfully created the new TODO pages as expected — with the '$' correctly in the wiki page name. Note that you may have to fully qualify the handler if it's not specified in the wiki's path as handler='org.ceryle.wiki.handler.NewPageHandler'. If you're not using the most current version of the code, download it and try again. Seems to work for me. -- MurrayAltheim


Thanks, Murray and Janne. Unfortunately, we're running a downlevel version of JSPWiki and the administrators have not added the CeryleWikiPlugins. I'll contact them to see if they can add it. In the meantime, I'm just putting a notice on my form not to use the $ but instead spell out dollar :-(.

-- Lynne Avery, 26-July-2007

Lynne, this reminds me that I'm currently distributing the plugins as a single package, but that (time permitting, as always) I'd like to distribute the plugins individually so that those who don't compile code could use them as single plugins without installing the full set. There are some dependencies with utility classes that complicate this a bit. -- MurrayAltheim


I'd like to have the page created by the handler load instead of having my form reload with a link to that page. Does anyone know how to do this? It looks like it might require editing of the source code for NewPageHandler ... -- Tyton


Looking at the modified code, I see that others have discovered the problem as I have. It would be nice to see these modifications integrated in the main downloadable.

1-for (Iterator iter = params.keySet().iterator(); iter.hasNext();) …(String)params.get(paramName);

This loop iterates though all keys, including objects that cannot be cast to strings(ie. "_bounds" which is a int). My solution? Filter certain keys:

if( paramName.equals(PluginManager.PARAM_BOUNDS) || paramName.equals(PluginManager.PARAM_CMDLINE) 
    || paramName.equals(PluginManager.PARAM_BODY) ) continue;

I find this solution much more elegant than the one from NewPageHandler2.

2- new WikiPage(newPageName); this worked when I compiled my code within the JSPWiki project, but not when I complied it outside of the project. I deduce that it’s a path or configuration problem rather than bad code.

--LucTussier

Add new attachment

Only authorized users are allowed to upload new attachments.

List of attachments

Kind Attachment Name Size Version Date Modified Author Change note
java
NewPageHandler.java 5.1 kB 2 14-Sep-2006 08:14 ChristophSauer
java
NewPageHandler2.java 5.7 kB 1 11-Jan-2007 14:29 marcus Version with minor modification for running with 2.4.87
« This page (revision-43) was last changed on 18-Mar-2010 23:11 by Allhours