Last modified by Bastian Triller on 2021/08/07 03:59

From version 11.1
edited by Pascal Robert
on 2012/08/09 04:05
Change comment: There is no comment for this version
To version 8.1
edited by Pascal Robert
on 2012/08/09 03:52
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -91,11 +91,11 @@
91 91   <wo:if condition="$displayGroup.hasMultipleBatches">
92 92   <div>
93 93   <wo:link action="$displayGroup.displayPreviousBatch">Previous</wo:link>
94 - | Batch
94 + | Batch
95 95   <wo:str value="$displayGroup.currentBatchIndex" />
96 - of
96 + of
97 97   <wo:str value="$displayGroup.batchCount" />
98 - |
98 + |
99 99   <wo:link action="$displayGroup.displayNextBatch">Next</wo:link>
100 100   </div>
101 101   </wo:if>
... ... @@ -102,9 +102,9 @@
102 102   <wo:loop list="$displayGroup.displayedObjects" item="$blogEntryItem">
103 103   <p><wo:str value="$blogEntryItem.title" /></p>
104 104   <p><wo:str value="$blogEntryItem.content" escapeHTML="false" /></p>
105 - <p>Created by
105 + <p>Created by
106 106   <wo:str value="$blogEntryItem.author.fullName" />
107 - on
107 + on
108 108   <wo:str value="$blogEntryItem.creationDate" />
109 109   </p>
110 110   <hr />
... ... @@ -122,60 +122,31 @@
122 122  
123 123  {{code}}
124 124  
125 -private Author _loggedAuthor;
125 + private Author _loggedAuthor;
126 126  
127 127   public Session() {
128 128   this._loggedAuthor = null;
129 129   }
130 -
130 +
131 131   public Author loggedAuthor() {
132 132   return this._loggedAuthor;
133 133   }
134 -
134 +
135 135   public void setAuthor(Author loggedAuthor) {
136 136   this._loggedAuthor = loggedAuthor;
137 137   }
138 138  
139 +
139 139  {{/code}}
140 140  
141 -Save the file. Next: we need to add a component to present the login form to the user. Right-click on the **Components** folder in the project, and select **New** > **WOComponent**. Change the name of the component to be **AdminMainPage** and change the superclass to **er.extensions.components.ERXComponent**.
142 +Save the file. Next: we need to add a component to present the login form to the user. Right-click on the **Components** folder in the project, and select **New** -> **WOComponent**. Change the name of the component to be **AdminMainPage** and change the superclass to **er.extensions.components.ERXComponent**.
142 142  
143 -After the component have been created, open **AdminMainPage.java** and override the content of the class with the following code:
144 +After the component have been created, open **AdminMainPage.java** and add the following code:
144 144  
145 145  {{code}}
146 146  
147 -package your.app.components;
148 -
149 149  import your.app.Session;
150 -import your.app.model.Author;
151 -import your.app.model.BlogEntry;
152 152  
153 -import com.webobjects.appserver.WOActionResults;
154 -import com.webobjects.appserver.WOContext;
155 -import com.webobjects.eoaccess.EODatabaseDataSource;
156 -import com.webobjects.eocontrol.EOEditingContext;
157 -
158 -import er.extensions.batching.ERXBatchingDisplayGroup;
159 -import er.extensions.components.ERXComponent;
160 -import er.extensions.eof.ERXEC;
161 -
162 -public class AdminMainPage extends ERXComponent {
163 -
164 - private ERXBatchingDisplayGroup<BlogEntry> _dg;
165 -
166 - public AdminMainPage(WOContext context) {
167 - super(context);
168 - EODatabaseDataSource dataSource = new EODatabaseDataSource(editingContext(), BlogEntry.ENTITY_NAME);
169 - _dg = new ERXBatchingDisplayGroup<BlogEntry>();
170 - _dg.setNumberOfObjectsPerBatch(20);
171 - _dg.setDataSource(dataSource);
172 - _dg.setObjectArray(BlogEntry.fetchBlogEntries(editingContext(), BlogEntry.AUTHOR.eq(session().loggedAuthor()), BlogEntry.LAST_MODIFIED.descs()));
173 - }
174 -
175 - public ERXBatchingDisplayGroup<BlogEntry> displayGroup() {
176 - return this._dg;
177 - }
178 -
179 179   private String _emailAddress;
180 180  
181 181   public String emailAddress() {
... ... @@ -185,109 +185,14 @@
185 185   public void setEmailAddress(String emailAddress) {
186 186   this._emailAddress = emailAddress;
187 187   }
188 -
189 - private BlogEntry _blogEntryItem;
190 190  
191 - public void setBlogEntryItem(BlogEntry blogEntryItem) {
192 - this._blogEntryItem = blogEntryItem;
193 - }
194 -
195 - public BlogEntry blogEntryItem() {
196 - return this._blogEntryItem;
197 - }
198 -
199 199   @Override
200 - public Session session() {
201 - return ((Session)super.session());
161 + public WOSession session() {
162 + return ((Session)session());
202 202   }
203 -
164 +
204 204   public boolean isLogged() {
205 205   return ((session()).loggedAuthor() == null) ? false: true;
206 206   }
207 -
208 - private EOEditingContext _ec;
209 -
210 - public EOEditingContext editingContext() {
211 - if (_ec == null) {
212 - _ec = ERXEC.newEditingContext();
213 - }
214 - return _ec;
215 - }
216 -
217 - private String _errorMessage = null;
218 -
219 - public String errorMessage() {
220 - return this._errorMessage;
221 - }
222 -
223 - public WOActionResults login() {
224 - Author loggedAuthor = Author.validateLogin(editingContext(), _emailAddress);
225 - if (loggedAuthor != null) {
226 - session().setAuthor(loggedAuthor);
227 - } else {
228 - _errorMessage = "Invalid email address";
229 - }
230 - return null;
231 - }
232 -}
233 233  
234 234  {{/code}}
235 -
236 -You will notice that we are using a ERXBatchingDisplayGroup again. But this time, when we call dg.setObjectArray//, we set the array of objects so that only the blog entries created by the logged author are displayed.//
237 -
238 -Open **AdminMainPage.wo** and override all the content between the <body> tag to be:
239 -
240 -{{code}}
241 -
242 -
243 - <wo:AjaxUpdateContainer id="main">
244 - <wo:if condition="$isLogged">
245 - <wo:if condition="$displayGroup.hasMultipleBatches">
246 - <div>
247 - <wo:link action="$displayGroup.displayPreviousBatch">Previous</wo:link>
248 - | Batch
249 - <wo:str value="$displayGroup.currentBatchIndex" />
250 - of
251 - <wo:str value="$displayGroup.batchCount" />
252 - |
253 - <wo:link action="$displayGroup.displayNextBatch">Next</wo:link>
254 - </div>
255 - </wo:if>
256 - <wo:loop list="$displayGroup.displayedObjects" item="$blogEntryItem">
257 - <p><wo:str value="$blogEntryItem.title" /></p>
258 - <p><wo:str value="$blogEntryItem.content" escapeHTML="false" /></p>
259 - <p>Created by
260 - <wo:str value="$blogEntryItem.author.fullName" />
261 - on
262 - <wo:str value="$blogEntryItem.creationDate" />
263 - </p>
264 - <hr />
265 - </wo:loop>
266 - </wo:if>
267 - <wo:else>
268 - <wo:if condition="$errorMessage">
269 - <span style="text-color: red;">Error: <wo:str value="$errorMessage" /></span>
270 - </wo:if>
271 - <wo:form>
272 - <div>
273 - <label>Email address:</label>
274 - <wo:textField value="$emailAddress" />
275 - </div>
276 - <div><wo:AjaxSubmitButton updateContainerID="main" action="$login" value="Login" /></div>
277 - </wo:form>
278 - </wo:else>
279 - </wo:AjaxUpdateContainer>
280 -
281 -{{/code}}
282 -
283 -Last step: we need a link to the admin page. Open **Main.wo** and just before the </body> tag, add the following:
284 -
285 -{{code}}
286 -
287 - <wo:link pageName="AdminMainPage">Admin</wo:link>
288 -
289 -{{/code}}
290 -
291 -Save everything, run the app and try to login. If login is not successful, you will get an error message. If login is valid, you will see the blog entries that you created.
292 -
293 -For the last part of this tutorial, we are going to add a link on each blog entry in the list that will bring us to a edit page where we can modify a blog entry. We are also going to add a link to create a new blog entry.