Did you consider this option? Maybe have a look at the JSFUnit Wiki and its Getting Started Guide. This is not what exactly what you are asking for but JSFUnit (which uses JUnit, Cactus, HtmlUnit, and HttpUnit) seems to be a serious candidate for testing in the JSF land. Good luck, and let me know how it works out for you! It would be much, much easier if IceFaces used Spring to match backing beans to JSF pages - then you could simply define the test-beans in an application.xml with the relevant test classes. Mind you, the whole business of swapping out beans and config files is messy. Voila! You've just unit-tested your JSF components. Once your tests are verified, swap the regular beans and config file back into the app. (This alone may be the reason why very few JSF developers try to unit test JSF output.) This is going to be tricky, because IceFaces loves to munge DIV IDs and other relevant parts of the DOM tree that you may want to sniff for. Your tests will probably need to sniff the raw HTML output to verify the results. If you don't want something as heavy as HTTPUnit, and if you're using Spring in your app, look at this blog post for an excellent way to mock up a full web context without a web server. The dummy beans, of course, won't touch any business logic or back-end services - they'll simply be simple sets of data that will be easy to verify in your tests.Ĭreate an ant script to substitute in your dummy backing beans and the test config file. It allows to have in memory only a limited number of records and to meet any potential "back and forth" of the user.If I understand your question correctly, then it ought to be a simple matter of creating special dummy backing beans for your pages, and then creating a test JSF configuration file mapping those beans to the. Surely the third implementation is the best solution from all points of view. Surely the second solution is the most potentially weak as in the worst case will keep in memory all the dataset. Public void setNumResults(int numResults)Īll implementations give the opportunity to retrieve records in a lazy way. Int firstIndexOfPreviusPage = firstIndexOfCurrentPage - (bufferSize / 3) Int firstIndexOfCurrentPage = pageSize * (currentPage - 1) * the index of the previous page's first element * Calculates the index of the previous page's first element * clears the map except the first element that MUST be kept LoadedData.put((startRow + j), (T) results.get(j)) List results = dataAdapter.getBufferedData(startRow, numElementToFind) NumElementToFind = totalResultsNumber - startRow This.totalResultsNumber = totalResultsNumber Public LazyLoadingList(IDataProvider dataProvider, int pageSize, int totalResultsNumber) * totalResultsNumber, the total number of rows as result of the database count query. * pageSize, the number of rows to be showed in a table page * dataProvider, the object that will perform the query * class LazyLoadingList extends AbstractList * If pageSize is equals to totalResultsNumber, the dataTable will be non paginated: the first query will retrieve all the dataset. * This list loads and stores only the first page and the current page. This parameter 'is usually the result of a count query. Note that the constructor of the list accepts as incoming parameter totalResultsNumber, that is the total number of results to show in the table. When the user navigates in the following pages, they will be retrieved by method get() and saved in a different list. This list keeps in memory a list of objects corresponding to the first page. They will be initialized in the page backingBean and used in this way in the. Let's see three possible implementations to implement the lazy loading of the list. The solution is to manage the list of results in a lazy way: the list itself will retrieve the records to show in the current page and only when there will be a real need.īesides this, we need also to manage the total page number: the paginator in fact invokes the method size() of the list supplied to the table calculates the number of pages. The main weakness of this component lies in the difficulty to handle large data sets: ice:dataTable component need to receive a list containing all rows that will gradually showed.Īs long as we are in the order of some hundreds of records, there is no problem to provide the entire results list to the component but if they begin to be thousands, keep in memory such a quantity of objects can be an issue. This component, together with ice:dataPaginator makes it possible to paginate the entire data set of a table, showing only N rows per page. IceFaces provides numerous components to facilitate the development of web applications.Īmong these, one of the most 'useful' is definitely ice:dataTable.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |