Changes for page Best Practices

Last modified by Vincent Massol on 2017/09/05

<
From version < 5.1 >
edited by Eduard Moraru
on 2012/05/23
To version < 4.1 >
edited by Eduard Moraru
on 2012/05/23
>
Change comment: Added a best practice for "Handling errors when using xredirect for non-Javascript UIs"

Summary

Details

Page properties
Content
... ... @@ -8,7 +8,7 @@
8 8  
9 9  Class sheet documents should be written using the following construct (this is an example for displaying documents containing XWiki.XWikiUsers objects):
10 10  
11 -{{code language="velocity"}}
11 +{{code language='velocity'}}
12 12  #set($obj = $doc.getObject("XWiki.XWikiUsers"))
13 13  #if(!$obj)
14 14   1 User Sheet
... ... @@ -19,9 +19,7 @@
19 19  #end
20 20  {{/code}}
21 21  
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.
24 -{{/info}}
22 +{{info}}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.{{/info}}
25 25  
26 26  = Handling errors when using xredirect for non-Javascript UIs =
27 27  
... ... @@ -33,7 +33,7 @@
33 33  
34 34  A simplified code for this in the background service that produces the error is:
35 35  
36 -{{code language="velocity"}}
34 +{{code language='velocity'}}
37 37  #handleRequest($success)
38 38  #if ($success)
39 39   #if ($request.action == 'get' || $request.xpage== 'plain')
... ... @@ -59,7 +59,7 @@
59 59  
60 60  For the background service, it translates to:
61 61  
62 -{{code language="velocity"}}
60 +{{code language='velocity'}}
63 63  ...
64 64   #elseif ("$!request.xredirect" != '')
65 65   ## No-JavaScript here. Redirect and forward error message.
... ... @@ -71,7 +71,7 @@
71 71  
72 72  On the UI side:
73 73  
74 -{{code language="velocity"}}
72 +{{code language='velocity'}}
75 75  ...
76 76   #set ($xredirect = $doc.getURL($context.action, $!{request.queryString}))
77 77   #set ($errorMessage = $request.session.getAttribute("${errorMessageKeyPrefix}${xredirect}"))
... ... @@ -84,8 +84,7 @@
84 84  {{/code}}
85 85  
86 86  Note that using xredirect's value as session key (prefixed or not) is a good idea because:
85 +1.it's already there in both the UI (for sending it as parameter) and the background service (received as parameter)
86 +2.it acts like a namespace, ensuring that the error will only be displayed for the current page/request.
87 87  
88 -1. it's already there in both the UI (for sending it as parameter) and the background service (received as parameter)
89 -1. it acts like a namespace, ensuring that the error will only be displayed for the current page/request.
90 -
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.

Get Connected