Change comment:
minor fixes
Summary
-
Page properties (2 modified, 0 added, 0 removed)
Details
- Page properties
-
- Author
-
... ... @@ -1,1 +1,1 @@ 1 -XWiki. enygma1 +XWiki.ManuelSmeria - Content
-
... ... @@ -1,5 +1,17 @@ 1 +{{box cssClass="floatinginfobox" title="**Contents**"}} 1 1 {{toc/}} 3 +{{/box}} 2 2 5 += Where to put code? = 6 + 7 +Since xwiki allows you to put code both in wiki pages and in Java you might wonder where you should put your code. Here are some general guidelines: 8 + 9 +* Don't put "business logic" code in wiki pages. Use Java for that. This gives you nice IDEs, the ability to easily debug the code and the ability to write automated unit tests. Generally speaking it makes it easy on maintenance. 10 +* In general put the minimum amount of scripts in your wiki pages since that makes it harder to maintain. 11 +* The only scripts that you may put in wiki pages are "presentation logic" code. 12 + 13 +Said differently you should use the [[MVC>>http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller]] approach by separating your Model (what we called "business logic" above) from your View (what we called "presentation logic" above). 14 + 3 3 = XWiki Application Organization = 4 4 5 5 This [[Best Practices document>>Best Practices XWiki Application Organization]] explains how to best organize an XWiki Application. ... ... @@ -20,7 +20,7 @@ 20 20 {{/code}} 21 21 22 22 {{info}} 23 -The 'if' tests first for the non existence. This is so that XWiki extract the title from the //1 User Sheet//, which is a proper title to display when viewsing the sheet page, instead of the computed name which will usually display something wrong. 35 +The 'if' tests first for the non existence. This is so that XWiki can extract the title from the //1 User Sheet//, which is a proper title to display when viewsing the sheet page, instead of the computed name which will usually display something wrong. 24 24 {{/info}} 25 25 26 26 = Handling errors when using xredirect for non-Javascript UIs = ... ... @@ -36,7 +36,7 @@ 36 36 {{code language="velocity"}} 37 37 #handleRequest($success) 38 38 #if ($success) 39 - #if ($request.action == 'get' || $request.xpage== 'plain') 51 + #if ($request.action == 'get' || $request.xpage == 'plain') 40 40 ## JavaScript call here. 41 41 Action was successful. 42 42 #elseif ("$!request.xredirect" != '') ... ... @@ -63,6 +63,7 @@ 63 63 ... 64 64 #elseif ("$!request.xredirect" != '') 65 65 ## No-JavaScript here. Redirect and forward error message. 78 + #set ($errorMessageKeyPrefix = "myModule.error.") 66 66 $request.session.setAttribute("${errorMessageKeyPrefix}${request.xredirect}", 'Action was NOT successful') 67 67 $response.sendRedirect($request.xredirect) 68 68 #end ... ... @@ -74,6 +74,7 @@ 74 74 {{code language="velocity"}} 75 75 ... 76 76 #set ($xredirect = $doc.getURL($context.action, $!{request.queryString})) 90 + #set ($errorMessageKeyPrefix = "myModule.error.") 77 77 #set ($errorMessage = $request.session.getAttribute("${errorMessageKeyPrefix}${xredirect}")) 78 78 #if ("$!errorMessage" != '') 79 79 ## Clean the error and display the message. ... ... @@ -88,4 +88,6 @@ 88 88 1. it's already there in both the UI (for sending it as parameter) and the background service (received as parameter) 89 89 1. it acts like a namespace, ensuring that the error will only be displayed for the current page/request. 90 90 105 +Using a prefix as above allows you to have multiple components (wiki macros, gadgets, etc.) in the same page using the same mechanism without collisions. 106 + 91 91 This method works together with the whole purpose for which we are doing the redirect in the first place (so that the user can refresh the page without re-sending the action or re-posting a form), ensuring that after the first display, on a refresh, the error goes away.