BinaryFlowController.jpf Sample

This topic inludes the source code for the BinaryFlowController.jpf Sample.

Sample Location

This sample is located in the following directory in your WebLogic Workshop installation:

BEA_HOME/weblogic81/samples/workshop/SamplesApp/WebApp/handlingData/binaryFlow/

Sample Source Code


001 package handlingData.binaryFlow;
002 import com.bea.wlw.netui.pageflow.Forward;
003 
004 import handlingData.binaryFlow.docContentDB;
005 import java.util.Map;
006 import java.util.Iterator;
007 import javax.sql.RowSet;
008 import java.sql.SQLException;
009 import com.bea.wlw.netui.databinding.form.RowSetForm;
010 import com.bea.wlw.netui.pageflow.FormData;
011 
012 import com.bea.wlw.netui.pageflow.PageFlowController;
013 import com.bea.wlw.netui.tags.databinding.SortFilterService;
014 import com.bea.wlw.netui.databinding.form.RowSetFormException;
015 import com.bea.wlw.netui.databinding.exception.RowIdentifierParseException;
016 import java.io.ByteArrayInputStream;
017 import java.io.InputStreamReader;
018 import java.math.BigDecimal;
019 import weblogic.jdbc.rowset.OptimisticConflictException;
020 import weblogic.jdbc.rowset.WLCachedRowSet;
021 import org.apache.struts.upload.FormFile;
022 
023 /**
024  * The following page flow shows how to handle binary files within a page flow.
025  
026  * This page flow was created by:
027  * (1) autogenerating a RowSet control from the database table WEBLOGIC.DOCUMENT_CONTENT
028  * (2) autogenerating a page flow from that RowSet control
029  * (3) modifying the page flow to upload and display images.
030  
031  * Image file uploading and database storage was added by:
032  * (1) adding a field, "contentUp", to the DatabaseForm FormBean
033  * (2) adding a <netui:fileUpload> tag to the insertDocumentContent.jsp page
034  * (3) adding a code to the submitInsert method below
035  
036  * Image file database retrieval and display was added by:
037  * (1) adding a getPHOTO method to the database control to retrieve Blob data.
038  * (2) adding the servlet WebApp/servlets/ShowImageServlet.java 
039  * (3) adding a <servlet> declaration and <servlet-mapping> element to WEB-INF/web.xml
040  * (4) adding a showImage.jsp page which uses the image displaying servlet
041  * (5) modifying detailsDocumentContent.jsp and grid.jsp to display the image content. 
042  *  
043  * @jpf:controller
044  * @jpf:view-properties view-properties::
045  <!-- This data is auto-generated. Hand-editing this section is not recommended. -->
046  <view-properties>
047  <pageflow-object id="pageflow:/handlingData/binaryFlow/BinaryFlowController.jpf"/>
048  <pageflow-object id="action:begin.do">
049  *   <property value="400" name="x"/>
050  *   <property value="100" name="y"/>
051  </pageflow-object>
052  <pageflow-object id="action:insertDocumentContent.do#handlingData.binaryFlow.BinaryFlowController.DatabaseForm">
053  *   <property value="160" name="x"/>
054  *   <property value="300" name="y"/>
055  </pageflow-object>
056  <pageflow-object id="action:submitInsert.do#handlingData.binaryFlow.BinaryFlowController.DatabaseForm">
057  *   <property value="280" name="x"/>
058  *   <property value="400" name="y"/>
059  </pageflow-object>
060  <pageflow-object id="action:cancelInsert.do">
061  *   <property value="160" name="x"/>
062  *   <property value="500" name="y"/>
063  </pageflow-object>
064  <pageflow-object id="action:detailsDocumentContent.do#handlingData.binaryFlow.BinaryFlowController.DatabaseForm">
065  *   <property value="520" name="x"/>
066  *   <property value="200" name="y"/>
067  </pageflow-object>
068  <pageflow-object id="action:showGrid.do">
069  *   <property value="400" name="x"/>
070  *   <property value="500" name="y"/>
071  </pageflow-object>
072  <pageflow-object id="action:updateDocumentContent.do#handlingData.binaryFlow.BinaryFlowController.DatabaseForm">
073  *   <property value="400" name="x"/>
074  *   <property value="300" name="y"/>
075  </pageflow-object>
076  <pageflow-object id="action:submitUpdate.do#handlingData.binaryFlow.BinaryFlowController.DatabaseForm">
077  *   <property value="640" name="x"/>
078  *   <property value="200" name="y"/>
079  </pageflow-object>
080  <pageflow-object id="action:cancelUpdate.do">
081  *   <property value="640" name="x"/>
082  *   <property value="500" name="y"/>
083  </pageflow-object>
084  <pageflow-object id="action:deleteDocumentContent.do#handlingData.binaryFlow.BinaryFlowController.DatabaseForm">
085  *   <property value="700" name="x"/>
086  *   <property value="100" name="y"/>
087  </pageflow-object>
088  <pageflow-object id="action:pageAction.do">
089  *   <property value="160" name="x"/>
090  *   <property value="200" name="y"/>
091  </pageflow-object>
092  <pageflow-object id="action-call:@page:grid.jsp@#@action:updateDocumentContent.do#handlingData.binaryFlow.BinaryFlowController.DatabaseForm@">
093  *   <property value="400,400,400,400" name="elbowsX"/>
094  *   <property value="244,250,250,256" name="elbowsY"/>
095  *   <property value="South_1" name="fromPort"/>
096  *   <property value="North_1" name="toPort"/>
097  </pageflow-object>
098  <pageflow-object id="action-call:@page:grid.jsp@#@action:detailsDocumentContent.do#handlingData.binaryFlow.BinaryFlowController.DatabaseForm@">
099  *   <property value="436,460,460,484" name="elbowsX"/>
100  *   <property value="192,192,192,192" name="elbowsY"/>
101  *   <property value="East_1" name="fromPort"/>
102  *   <property value="West_1" name="toPort"/>
103  </pageflow-object>
104  <pageflow-object id="action-call:@page:grid.jsp@#@action:pageAction.do@">
105  *   <property value="364,280,280,196" name="elbowsX"/>
106  *   <property value="192,192,192,192" name="elbowsY"/>
107  *   <property value="West_1" name="fromPort"/>
108  *   <property value="East_1" name="toPort"/>
109  </pageflow-object>
110  <pageflow-object id="action-call:@page:grid.jsp@#@action:insertDocumentContent.do#handlingData.binaryFlow.BinaryFlowController.DatabaseForm@">
111  *   <property value="364,280,280,196" name="elbowsX"/>
112  *   <property value="203,203,292,292" name="elbowsY"/>
113  *   <property value="West_2" name="fromPort"/>
114  *   <property value="East_1" name="toPort"/>
115  </pageflow-object>
116  <pageflow-object id="page:grid.jsp">
117  *   <property value="400" name="x"/>
118  *   <property value="200" name="y"/>
119  </pageflow-object>
120  <pageflow-object id="action-call:@page:insertDocumentContent.jsp@#@action:submitInsert.do#handlingData.binaryFlow.BinaryFlowController.DatabaseForm@">
121  *   <property value="196,220,220,244" name="elbowsX"/>
122  *   <property value="392,392,392,392" name="elbowsY"/>
123  *   <property value="East_1" name="fromPort"/>
124  *   <property value="West_1" name="toPort"/>
125  </pageflow-object>
126  <pageflow-object id="action-call:@page:insertDocumentContent.jsp@#@action:cancelInsert.do@">
127  *   <property value="South_1" name="fromPort"/>
128  *   <property value="North_1" name="toPort"/>
129  *   <property value="160,160,160,160" name="elbowsX"/>
130  *   <property value="444,450,450,456" name="elbowsY"/>
131  </pageflow-object>
132  <pageflow-object id="page:insertDocumentContent.jsp">
133  *   <property value="160" name="x"/>
134  *   <property value="400" name="y"/>
135  </pageflow-object>
136  <pageflow-object id="action-call:@page:detailsDocumentContent.jsp@#@action:updateDocumentContent.do#handlingData.binaryFlow.BinaryFlowController.DatabaseForm@">
137  *   <property value="400,400,400,400" name="elbowsX"/>
138  *   <property value="356,350,350,344" name="elbowsY"/>
139  *   <property value="North_1" name="fromPort"/>
140  *   <property value="South_1" name="toPort"/>
141  </pageflow-object>
142  <pageflow-object id="action-call:@page:detailsDocumentContent.jsp@#@action:deleteDocumentContent.do#handlingData.binaryFlow.BinaryFlowController.DatabaseForm@">
143  *   <property value="436,550,550,664" name="elbowsX"/>
144  *   <property value="381,381,92,92" name="elbowsY"/>
145  *   <property value="East_0" name="fromPort"/>
146  *   <property value="West_1" name="toPort"/>
147  </pageflow-object>
148  <pageflow-object id="action-call:@page:detailsDocumentContent.jsp@#@action:showGrid.do@">
149  *   <property value="South_1" name="fromPort"/>
150  *   <property value="North_1" name="toPort"/>
151  *   <property value="400,400,400,400" name="elbowsX"/>
152  *   <property value="444,450,450,456" name="elbowsY"/>
153  </pageflow-object>
154  <pageflow-object id="page:detailsDocumentContent.jsp">
155  *   <property value="400" name="x"/>
156  *   <property value="400" name="y"/>
157  </pageflow-object>
158  <pageflow-object id="action-call:@page:updateDocumentContent.jsp@#@action:submitUpdate.do#handlingData.binaryFlow.BinaryFlowController.DatabaseForm@">
159  *   <property value="640,640,640,640" name="elbowsX"/>
160  *   <property value="256,250,250,244" name="elbowsY"/>
161  *   <property value="North_1" name="fromPort"/>
162  *   <property value="South_1" name="toPort"/>
163  </pageflow-object>
164  <pageflow-object id="action-call:@page:updateDocumentContent.jsp@#@action:cancelUpdate.do@">
165  *   <property value="South_1" name="fromPort"/>
166  *   <property value="North_1" name="toPort"/>
167  *   <property value="640,640,640,640" name="elbowsX"/>
168  *   <property value="344,400,400,456" name="elbowsY"/>
169  </pageflow-object>
170  <pageflow-object id="page:updateDocumentContent.jsp">
171  *   <property value="640" name="x"/>
172  *   <property value="300" name="y"/>
173  </pageflow-object>
174  <pageflow-object id="page:/error.jsp">
175  *   <property value="760" name="x"/>
176  *   <property value="200" name="y"/>
177  </pageflow-object>
178  <pageflow-object id="page:showImage.jsp">
179  *   <property value="860" name="x"/>
180  *   <property value="200" name="y"/>
181  </pageflow-object>
182  <pageflow-object id="forward:path#grid#grid.jsp#@action:begin.do@">
183  *   <property value="South_1" name="fromPort"/>
184  *   <property value="North_1" name="toPort"/>
185  *   <property value="grid" name="label"/>
186  *   <property value="400,400,400,400" name="elbowsX"/>
187  *   <property value="144,150,150,156" name="elbowsY"/>
188  </pageflow-object>
189  <pageflow-object id="forward:path#insert#insertDocumentContent.jsp#@action:insertDocumentContent.do#handlingData.binaryFlow.BinaryFlowController.DatabaseForm@">
190  *   <property value="160,160,160,160" name="elbowsX"/>
191  *   <property value="344,350,350,356" name="elbowsY"/>
192  *   <property value="South_1" name="fromPort"/>
193  *   <property value="North_1" name="toPort"/>
194  *   <property value="insert" name="label"/>
195  </pageflow-object>
196  <pageflow-object id="forward:path#inserted#detailsDocumentContent.jsp#@action:submitInsert.do#handlingData.binaryFlow.BinaryFlowController.DatabaseForm@">
197  *   <property value="316,340,340,364" name="elbowsX"/>
198  *   <property value="392,392,381,381" name="elbowsY"/>
199  *   <property value="East_1" name="fromPort"/>
200  *   <property value="West_0" name="toPort"/>
201  *   <property value="inserted" name="label"/>
202  </pageflow-object>
203  <pageflow-object id="forward:path#canceled#begin.do#@action:cancelInsert.do@">
204  *   <property value="South_1" name="fromPort"/>
205  *   <property value="West_1" name="toPort"/>
206  *   <property value="canceled" name="label"/>
207  *   <property value="160,80,80" name="elbowsX"/>
208  *   <property value="580,580,92" name="elbowsY"/>
209  </pageflow-object>
210  <pageflow-object id="forward:path#view#detailsDocumentContent.jsp#@action:detailsDocumentContent.do#handlingData.binaryFlow.BinaryFlowController.DatabaseForm@">
211  *   <property value="484,460,460,436" name="elbowsX"/>
212  *   <property value="192,192,392,392" name="elbowsY"/>
213  *   <property value="West_1" name="fromPort"/>
214  *   <property value="East_1" name="toPort"/>
215  *   <property value="view" name="label"/>
216  </pageflow-object>
217  <pageflow-object id="forward:path#showGrid#begin.do#@action:showGrid.do@">
218  *   <property value="South_1" name="fromPort"/>
219  *   <property value="West_1" name="toPort"/>
220  *   <property value="showGrid" name="label"/>
221  *   <property value="400,80,80" name="elbowsX"/>
222  *   <property value="580,580,92" name="elbowsY"/>
223  </pageflow-object>
224  <pageflow-object id="forward:path#update#updateDocumentContent.jsp#@action:updateDocumentContent.do#handlingData.binaryFlow.BinaryFlowController.DatabaseForm@">
225  *   <property value="436,520,520,604" name="elbowsX"/>
226  *   <property value="292,292,292,292" name="elbowsY"/>
227  *   <property value="East_1" name="fromPort"/>
228  *   <property value="West_1" name="toPort"/>
229  *   <property value="update" name="label"/>
230  </pageflow-object>
231  <pageflow-object id="forward:path#updated#detailsDocumentContent.do#@action:submitUpdate.do#handlingData.binaryFlow.BinaryFlowController.DatabaseForm@">
232  *   <property value="604,580,580,556" name="elbowsX"/>
233  *   <property value="192,192,192,192" name="elbowsY"/>
234  *   <property value="West_1" name="fromPort"/>
235  *   <property value="East_1" name="toPort"/>
236  *   <property value="updated" name="label"/>
237  </pageflow-object>
238  <pageflow-object id="forward:path#canceled#begin.do#@action:cancelUpdate.do@">
239  *   <property value="South_1" name="fromPort"/>
240  *   <property value="West_1" name="toPort"/>
241  *   <property value="canceled" name="label"/>
242  *   <property value="640,80,80" name="elbowsX"/>
243  *   <property value="580,580,92" name="elbowsY"/>
244  </pageflow-object>
245  <pageflow-object id="forward:path#deleted#begin.do#@action:deleteDocumentContent.do#handlingData.binaryFlow.BinaryFlowController.DatabaseForm@">
246  *   <property value="664,550,550,436" name="elbowsX"/>
247  *   <property value="92,92,92,92" name="elbowsY"/>
248  *   <property value="West_1" name="fromPort"/>
249  *   <property value="East_1" name="toPort"/>
250  *   <property value="deleted" name="label"/>
251  </pageflow-object>
252  <pageflow-object id="forward:path#page#grid.jsp#@action:pageAction.do@">
253  *   <property value="196,280,280,364" name="elbowsX"/>
254  *   <property value="192,192,192,192" name="elbowsY"/>
255  *   <property value="East_1" name="fromPort"/>
256  *   <property value="West_1" name="toPort"/>
257  *   <property value="page" name="label"/>
258  </pageflow-object>
259  <pageflow-object id="control:handlingData.binaryFlow.docContentDB#myControl">
260  *   <property value="28" name="x"/>
261  *   <property value="34" name="y"/>
262  </pageflow-object>
263  <pageflow-object id="formbeanprop:handlingData.binaryFlow.BinaryFlowController.DatabaseForm#id#java.lang.Integer"/>
264  <pageflow-object id="formbeanprop:handlingData.binaryFlow.BinaryFlowController.DatabaseForm#versioned_object_id#java.lang.Integer"/>
265  <pageflow-object id="formbeanprop:handlingData.binaryFlow.BinaryFlowController.DatabaseForm#object_type#java.lang.String"/>
266  <pageflow-object id="formbeanprop:handlingData.binaryFlow.BinaryFlowController.DatabaseForm#name#java.lang.String"/>
267  <pageflow-object id="formbeanprop:handlingData.binaryFlow.BinaryFlowController.DatabaseForm#content_type#java.lang.Integer"/>
268  <pageflow-object id="formbeanprop:handlingData.binaryFlow.BinaryFlowController.DatabaseForm#containment_of_content#java.lang.Integer"/>
269  <pageflow-object id="formbeanprop:handlingData.binaryFlow.BinaryFlowController.DatabaseForm#contentUp#org.apache.struts.upload.FormFile"/>
270  <pageflow-object id="formbeanprop:handlingData.binaryFlow.BinaryFlowController.DatabaseForm#content#byte[]"/>
271  <pageflow-object id="formbeanprop:handlingData.binaryFlow.BinaryFlowController.DatabaseForm#file_size#java.math.BigDecimal"/>
272  <pageflow-object id="formbeanprop:handlingData.binaryFlow.BinaryFlowController.DatabaseForm#file_last_modified#java.sql.Timestamp"/>
273  <pageflow-object id="formbean:handlingData.binaryFlow.BinaryFlowController.DatabaseForm"/>
274  <pageflow-object id="formbeanprop:handlingData.binaryFlow.BinaryFlowController.ViewImageForm#imageByArr#byte[]"/>
275  <pageflow-object id="formbean:handlingData.binaryFlow.BinaryFlowController.ViewImageForm"/>
276  </view-properties>
277  * ::
278  * @jpf:catch type="RowSetFormException" method="rowSetFormExceptionHandler"
279  * @jpf:catch type="java.sql.SQLException" method="sqlExceptionHandler"
280  * @jpf:catch type="java.lang.reflect.UndeclaredThrowableException" method="exceptionHandler"
281  * @jpf:catch type="RowIdentifierParseException" method="rowIdentifierParseExceptionHandler"
282  * @jpf:catch type="OptimisticConflictException" method="ocExceptionHandler"
283  */
284 public class BinaryFlowController extends PageFlowController
285 {
286     /**
287      * This is the control used to generate this pageflow
288      *  @common:control
289      */
290     private docContentDB myControl;
291     
292     // Ensures that the image displaying servlet compiles at runtime.
293     private transient handlingData.binaryFlow.servlets.ShowImageServlet _sis;
294 
295     private transient RowSet allRows;
296     private transient SortFilterService sortFilterService;
297     private transient String gridName = "binaryFlowControllerGridName";
298     private transient RowSet lastRowFetched;
299 
300 
301     /**
302      * This method represents the point of entry into the page group
303      * @jpf:action
304      * @jpf:forward name="grid" path="grid.jsp"
305      * @jpf:catch method="exceptionHandler" type="java.lang.Exception"
306      */
307     public Forward begin()
308         throws Exception
309     {
310         sortFilterService = SortFilterService.getInstance(getRequest());
311         allRows = myControl.getAllDocumentContent(getSortFilterService().getDatabaseFilter(getGridName()));
312         return new Forward("grid");
313     }
314 
315     /**
316      * @jpf:action
317      * @jpf:forward name="insert" path="insertDocumentContent.jsp"
318      */
319     public Forward insertDocumentContent(DatabaseForm form)
320         throws Exception
321     {
322         return new Forward("insert");
323     }
324 
325     /**
326      * @jpf:action
327      * @jpf:forward name="inserted" path="detailsDocumentContent.jsp"
328      */
329     public Forward submitInsert(DatabaseForm aDatabaseForm)
330         throws Exception
331     {
332         // The convertUploadedContentToContent method extracts the uploaded image content
333         // and prepares it for insertion into the database.
334         aDatabaseForm = convertUploadedContentToContent(aDatabaseForm);
335                                 
336         getSortFilterService().reset();
337         RowSet row = myControl.detailsDocumentContentTemplate();
338 
339         // Generate a new primary key value for the recored about to be inserted.
340         RowSet keyRS = myControl.getNewKey();
341         keyRS.first();
342         row.updateInt(1, keyRS.getInt(1));
343 
344         // Set default values for the required database fields, if the user has not specified values.
345         if(aDatabaseForm.getContainment_of_content() == null)
346             aDatabaseForm.setContainment_of_content(new Integer(1));
347         if(aDatabaseForm.getVersioned_object_id() == null)
348             aDatabaseForm.setVersioned_object_id(new Integer(1));
349         if(aDatabaseForm.getContent_type() == null)
350             aDatabaseForm.setContent_type(new Integer(1));
351         if(aDatabaseForm.getObject_type() == "")
352             aDatabaseForm.setObject_type("1");
353         if(aDatabaseForm.getFile_last_modified() == null)
354             aDatabaseForm.setFile_last_modified(new java.sql.Timestamp(new java.util.Date().getTime()));
355 
356         // The remaining code is autogenerated.
357         aDatabaseForm.applyInsertValuesToRowSet(row);
358         RowSet var = myControl.insertDocumentContent(row);
359         aDatabaseForm.applyValuesToForm(var);
360 
361         lastRowFetched = myControl.getInserted();
362         DatabaseForm form = new DatabaseForm();
363         form.applyValuesToForm(lastRowFetched);
364 
365         getSortFilterService().addRowIdentifier(getGridName(),"id", form.getId() );
366 
367         return new Forward("inserted",form);
368     }
369 
370     /**
371      * @jpf:action
372      * @jpf:forward name="canceled" path="begin.do"
373      */
374     public Forward cancelInsert()
375         throws Exception
376     {
377         return new Forward("canceled");
378     }
379 
380     /**
381      * @jpf:action
382      * @jpf:forward name="view" path="detailsDocumentContent.jsp"
383      */
384     public Forward detailsDocumentContent(DatabaseForm form)
385         throws Exception
386     {
387         lastRowFetched = getCurrentRow();
388         form.applyValuesToForm(lastRowFetched);
389 
390         return new Forward("view",form);
391     }
392 
393     /**
394      * @jpf:action
395      * @jpf:forward name="showGrid" path="begin.do"
396      */
397     public Forward showGrid()
398         throws Exception
399     {
400         return new Forward("showGrid");
401     }
402 
403     /**
404      * @jpf:action
405      * @jpf:forward name="update" path="updateDocumentContent.jsp"
406      */
407     public Forward updateDocumentContent(DatabaseForm form)
408         throws Exception
409     {
410         lastRowFetched = getCurrentRow();
411         form.applyValuesToForm(lastRowFetched);
412 
413         return new Forward("update",form);
414     }
415 
416     /**
417      * @jpf:action
418      * @jpf:forward name="updated" path="detailsDocumentContent.do"
419      */
420     public Forward submitUpdate(DatabaseForm aDatabaseForm)
421         throws Exception
422     {
423         // The convertUploadedContentToContent method extracts the uploaded image content
424         // and prepares it for insertion into the database.
425         aDatabaseForm = convertUploadedContentToContent(aDatabaseForm);
426             
427         // The remaining code is autogenerated.
428         if(lastRowFetched == null)
429         {
430             System.err.println("There is no last row to manipulate.");
431             return new Forward("updated");
432         }
433         getSortFilterService().reset();
434         RowSet row = getLastRowFetched();
435 
436         aDatabaseForm.applyUpdateValuesToRowSet(row);
437         RowSet var = myControl.updateDocumentContent(row);
438         lastRowFetched = null;
439 
440         return new Forward("updated");
441     }
442 
443     /**
444      * @jpf:action
445      * @jpf:forward name="canceled" path="begin.do"
446      */
447     public Forward cancelUpdate()
448         throws Exception
449     {
450         return new Forward("canceled");
451     }
452 
453     /**
454      * @jpf:action
455      * @jpf:forward name="deleted" path="begin.do"
456      */
457     public Forward deleteDocumentContent(DatabaseForm aDatabaseForm)
458         throws Exception
459     {
460         getSortFilterService().reset();
461 
462         RowSet row = getLastRowFetched();
463 
464         ifrow == null )
465         {
466             System.err.println("There is no last row to manipulate.");
467             return new Forward("deleted");
468         }
469         row.absolute(1);
470         row.deleteRow();
471 
472         lastRowFetched = null;
473 
474         myControl.deleteDocumentContent(row);
475         return new Forward("deleted");
476     }
477 
478     /**
479      * @jpf:action
480      * @jpf:forward name="page" path="grid.jsp"
481      */
482     public Forward pageAction()
483         throws Exception
484     {
485         sortFilterService = SortFilterService.getInstance(getRequest());
486         return new Forward("page");
487     }
488 
489 
490     // 
491     // Utility methods
492     // 
493 
494     // This method extracts data from the uploaded file 
495     // and uses that data to populate the DatabaseForm.
496     public DatabaseForm convertUploadedContentToContent(DatabaseForm aDatabaseForm)
497         throws Exception
498     {
499         // Get the size of the uploaded file.
500         int filesize = (aDatabaseForm.contentUp.getFileSize());
501     
502         // Make a byte Array big enough to fit the file. 
503         byte[] byteArr = new byte[filesize]
504         
505         //Create an input stream to read the uploaded file.
506         ByteArrayInputStream bytein = new ByteArrayInputStream(aDatabaseForm.contentUp.getFileData())
507         
508         // Load the input stream into the byte Array.
509         bytein.read(byteArr);
510         
511         // Close the input stream.
512         bytein.close();        
513         
514         // Load the byte[] into the FormBean field corresponding to the database table field (CONTENT).
515         aDatabaseForm.setContent(byteArr);
516         
517         // Set the file name
518         aDatabaseForm.setName(aDatabaseForm.contentUp.getFileName());
519         // Set the file type
520         aDatabaseForm.setObject_type(aDatabaseForm.contentUp.getContentType());
521         // Set the file size
522         aDatabaseForm.setFile_size(BigDecimal.valueOf((long)filesize));
523         
524         return aDatabaseForm;
525     }
526 
527 
528     private RowSet getCurrentRow()
529     {
530         String columnName = null;
531         try
532         {
533             columnName = "id";
534             Integer pk0 = new Integer(SortFilterService.decodeUniqueIdentifier(getRequest(), getGridName(), columnName));
535             lastRowFetched = myControl.detailsDocumentContent(pk0);
536 
537             int rowCount = (( WLCachedRowSet lastRowFetched ).size();
538             if(rowCount == 1)
539                 return lastRowFetched;
540             else throw new IllegalStateException("The RowSet for the primary key is not valid");
541         }
542         catch(Exception e)
543         {
544             RowIdentifierParseException ripe =
545                 new RowIdentifierParseException
546                         ("An exception occurred parsing the row identifier " + columnName + " for the grid named " + getGridName() " caused by " + e.toString(), e);
547             throw ripe;
548         }
549     }
550 
551 
552     protected RowSet getLastRowFetched()
553         throws Exception
554     {
555         String columnName = null;
556         if(lastRowFetched != null)
557         {
558             columnName = "id";
559             Integer pk0 = new Integer(SortFilterService.decodeUniqueIdentifier(getRequest(), getGridName(), columnName));
560 
561             lastRowFetched.absolute(1);
562 
563             ifpk0.equals(lastRowFetched.getObject("id")))
564             {
565                return lastRowFetched;
566             }
567             else
568             {
569                return getCurrentRow();
570             }
571         }
572         else
573         {
574             return getCurrentRow();
575         }
576     }
577 
578 
579     /**
580      * @jpf:exception-handler
581      * @jpf:forward name="errorPage" path="/error.jsp"
582      */
583     protected Forward sqlExceptionHandler(SQLException ex,String actionName,String message,FormData form)
584     {
585         // log sql exception
586         String displayMessage = "An exception occurred in the action " + actionName;
587         getRequest().setAttribute("errorMessage", displayMessage);
588         return new Forward("errorPage");
589     }
590 
591 
592     /**
593      * @jpf:exception-handler
594      * @jpf:forward name="errorPage" path="/error.jsp"
595      */
596     protected Forward exceptionHandler(java.lang.Exception ex,String actionName,String message,FormData form)
597     {
598         // log general exception
599         String displayMessage = "An exception occurred in the action " + actionName;
600         getRequest().setAttribute("errorMessage", displayMessage);
601         return new Forward("errorPage");
602     }
603 
604 
605     /**
606      * @jpf:exception-handler
607      * @jpf:forward name="errorPage" path="/error.jsp"
608      */
609     protected Forward rowSetFormExceptionHandler(RowSetFormException ex,String actionName,String message,FormData form)
610     {
611         // log rowset exception
612         String displayMessage = "An exception occurred in the action " + actionName;
613         getRequest().setAttribute("errorMessage", displayMessage);
614         return new Forward("errorPage");
615     }
616 
617 
618     /**
619      * @jpf:exception-handler
620      * @jpf:forward name="errorPage" path="/error.jsp"
621      */
622     protected Forward rowIdentifierParseExceptionHandler(RowIdentifierParseException ex,String actionName,String message,FormData form)
623     {
624         // log rowset exception
625         String displayMessage = "An exception occurred in the action " + actionName;
626         getRequest().setAttribute("errorMessage", displayMessage);
627         return new Forward("errorPage");
628     }
629 
630 
631     /**
632      * @jpf:exception-handler
633      * @jpf:forward name="errorPage" path="/error.jsp"
634      */
635     protected Forward ocExceptionHandler(OptimisticConflictException ex,String actionName,String message,FormData form)
636     {
637         // log opimistic concurrency exception
638         String displayMessage = "A version conflict occurs when the underlying data in the database has changed after the WLCachedRowSet read the data into memory but before it can write back to the database. The exact circumstances that produce an OptimisticConflictException depend on the optimistic policy being used.";
639         getRequest().setAttribute("errorMessage", displayMessage);
640         return new Forward("errorPage");
641     }
642 
643 
644     public SortFilterService getSortFilterService()
645     {
646         return sortFilterService;
647     }
648 
649 
650     protected void beforeAction()
651     {
652         if(getSortFilterService() == null)
653         {
654             sortFilterService = SortFilterService.getInstance(getRequest());
655         }
656 
657         sortFilterService.updateRowId(getRequest());
658     }
659 
660 
661     public String getGridName()
662     {
663         return gridName;
664     }
665 
666 
667 
668     public RowSet getAllRows()
669     {
670         return allRows;
671     }
672 
673 
674     /**
675      * Database form class
676      * This class is tailored after the db control specified during generation
677      */
678     public static class DatabaseForm extends RowSetForm
679     {
680 
681         public  DatabaseForm()
682         {
683             super();
684         }
685 
686         private Integer id;
687         private Integer versioned_object_id;
688         private String object_type;
689         private String name;
690         private Integer content_type;
691         private Integer containment_of_content;
692         private FormFile contentUp;
693         private byte[] content;
694         private java.math.BigDecimal file_size;
695         private java.sql.Timestamp file_last_modified;
696 
697         public Integer getId()
698         {
699             return id;
700         }
701 
702         public void setId(Integer newOne)
703         {
704             registerChange("id");
705             this.id = newOne;
706         }
707 
708         public Integer getVersioned_object_id()
709         {
710             return versioned_object_id;
711         }
712 
713         public void setVersioned_object_id(Integer newOne)
714         {
715             registerChange("versioned_object_id");
716             this.versioned_object_id = newOne;
717         }
718 
719         public String getObject_type()
720         {
721             return object_type;
722         }
723 
724         public void setObject_type(String newOne)
725         {
726             registerChange("object_type");
727             this.object_type = newOne;
728         }
729 
730         public String getName()
731         {
732             return name;
733         }
734 
735         public void setName(String newOne)
736         {
737             registerChange("name");
738             this.name = newOne;
739         }
740 
741         public Integer getContent_type()
742         {
743             return content_type;
744         }
745 
746         public void setContent_type(Integer newOne)
747         {
748             registerChange("content_type");
749             this.content_type = newOne;
750         }
751 
752         public Integer getContainment_of_content()
753         {
754             return containment_of_content;
755         }
756 
757         public void setContainment_of_content(Integer newOne)
758         {
759             registerChange("containment_of_content");
760             this.containment_of_content = newOne;
761         }
762 
763         public FormFile getContentUp()
764         {
765             return contentUp;
766         }
767 
768         public void setContentUp(FormFile newOne)
769         {
770             //registerChange("content");
771             this.contentUp = newOne;
772         }
773 
774         public byte[] getContent()
775         {
776             return content;
777         }
778 
779         public void setContent(byte[] newOne)
780         {
781             registerChange("content");
782             this.content = newOne;
783         }
784 
785         public java.math.BigDecimal getFile_size()
786         {
787             return file_size;
788         }
789 
790         public void setFile_size(java.math.BigDecimal newOne)
791         {
792             registerChange("file_size");
793             this.file_size = newOne;
794         }
795 
796         public java.sql.Timestamp getFile_last_modified()
797         {
798             return file_last_modified;
799         }
800 
801         public void setFile_last_modified(java.sql.Timestamp newOne)
802         {
803             registerChange("file_last_modified");
804             this.file_last_modified = newOne;
805         }
806     }
807 
808     /**
809      * FormData get and set methods may be overwritten by the Form Bean editor.
810      */
811     public static class ViewImageForm extends FormData
812     {
813         private byte[] imageByArr;
814 
815         public void setImageByArr(byte[] imageByArr)
816         {
817             this.imageByArr = imageByArr;
818         }
819 
820         public byte[] getImageByArr()
821         {
822             // For data binding to be able to post data back, complex types and
823             // arrays must be initialized to be non-null.
824             if(this.imageByArr == null || this.imageByArr.length == 0)
825             {
826                 this.imageByArr = new byte[1];
827             }
828 
829             return this.imageByArr;
830         }
831     }
832 }