Changes for page Best Practices

Last modified by Vincent Massol on 2017/09/05

<
From version < 8.1 >
edited by Vincent Massol
on 2014/01/06
To version < 8.4 >
edited by Denis Gervalle
on 2015/12/13
>
Change comment: fix code error in sample for error handling

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.VincentMassol
1 +XWiki.dgervalle
Content
... ... @@ -7,10 +7,10 @@
7 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 8  
9 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.
10 +* In general put the minimum amount of scripts in your wiki pages since that makes them harder to maintain.
11 +* The only scripts that you should put in wiki pages (and not in Java code!) are "presentation logic" scripts, i.e. scripts in charge of presenting the data retrieved by using the Java/REST APIs.
12 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).
13 +Said differently you should use the [[MVC>>http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller]] pattern by separating your Model (what we called "business logic" above) from your View (what we called "presentation logic" above).
14 14  
15 15  = XWiki Application Organization =
16 16  
... ... @@ -33,7 +33,7 @@
33 33  {{/code}}
34 34  
35 35  {{info}}
36 -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.
36 +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 viewing the sheet page, instead of the computed name which will usually display something wrong.
37 37  {{/info}}
38 38  
39 39  = Handling errors when using xredirect for non-Javascript UIs =
... ... @@ -65,7 +65,7 @@
65 65   ## No-JavaScript here. What now!? Redirect?
66 66   #handleErrorHere($request.xredirect)
67 67   #end
68 -#else
68 +#end
69 69  {{/code}}
70 70  
71 71  The idea is that you want to pass the error message to the UI but you don`t have a clear way of doing it, like you have for AJAX calls (response code and response text). A solution is to use the Session in order to pass your error message. You set the error in the service and, in the UI, you read and remove it so that it is only displayed once.

Get Connected