[jboss-user] [JBoss Seam] - Re: feature idea - conversation names

ellenzhao do-not-reply at jboss.com
Tue Aug 14 17:56:33 EDT 2007


The more I think about it, the more I'd like to have named conversation. Since I can mentally map a named conversation to a use case. What I get from named conversation is more than just "exit to the entry point". 

For now, in my own application, the "named conversation (use case)" is implemented this way:

The application scoped enum UseCase


  | public enum UseCase {
  |   doANewPlan, viewPastPlans, viewAllRecipes, viewAllFoods,.... 
  | }
  | 

although the "viewPastPlans", "viewAllRecipes", "viewAllFoods" ... have only "view" as a verb but in fact these use cases are deep having many sub usecases. From the "viewPastPlans", user can click a recipe link and enter the "recipe-detail.xhtml",  there are CRUD option buttons/links which would be rendered according to the current use case and user permssions on the recipe-detail page. From the recipe-detail page user can enter the food-detail.xhtml and again there are CRUD options available according to use cases and user permissions. If I want to implement it, from the food-detail.xhtml page a user can enter the nutrient-detail.xhtml...... All my conversation beans such as planManager, recipeManager, foodManager ...... has code like this inside the impl classes:


  | private UseCase currentUseCase;
  | 
  | public UseCase getCurrentUseCase(){return this.currentUseCase}
  | public void setCurrentUseCase(UseCase motherUseCase){
  |   this.currentUseCase = motherUseCase;
  | }
  | 

Here is some code example from my view code and pages.xhtml just to demonstrate why knowing current use case is very useful

Code from the plan-detail.xhtml using use case information:

  | <ui:composition xmlns="http://www.w3.org/1999/xhtml"
  |   xmlns:s="http://jboss.com/products/seam/taglib"
  |   xmlns:ui="http://java.sun.com/jsf/facelets"
  |   xmlns:f="http://java.sun.com/jsf/core"
  |   xmlns:h="http://java.sun.com/jsf/html"
  |   xmlns:rich="http://richfaces.ajax4jsf.org/rich"
  |   xmlns:a="https://ajax4jsf.dev.java.net/ajax"
  |   xmlns:p="http://jboss.com/products/seam/pdf">
  |  
  |   <!-- check loggedIn and permission-->
  |    ... ... ...
  |    ... ... ...
  | 
  |   <!-- ########### render shopping list on screen ############## -->
  |   <div class="section"><s:fragment
  |     rendered="#{recipePlanner.weeklyCookingPlan.renderShoppingList}">
  |     <h:outputText
  |       value="Amount in gram, price in Euro. Check the items you want to
  |       remove."
  |       class="message"
  |       rendered="#{recipePlanner.currentUseCase == useCases['doANewPlan']}" />
  |     <h:form>
  |       <rich:dataTable id="weeklyShoppingList"
  |         value="#{recipePlanner.weeklyCookingPlan.foods}" var="wf">
  |         <rich:column
  |           rendered="#{recipePlanner.currentUseCase == useCases.['doANewPlan']}">
  |           <f:facet name="header">
  |             <h:outputText value="Option" />
  |           </f:facet>
  |           <h:commandButton value="Remove"            action="#{recipePlanner.weeklyCookingPlan.removeAShoppingItem(wf)}" />
  |         </rich:column>
  | 
  |         <rich:column>
  |           <f:facet name="header">
  |             <h:outputText value="Food" />
  |           </f:facet>
  |           <h:outputText value="#{wf.food.longDesc}" />
  |         </rich:column>
  | 
  |         <rich:column>
  |           <f:facet name="header">
  |             <h:outputText value="Amount in gram" />
  |           </f:facet>
  |           <h:outputText value="#{wf.amountInGram}">
  |             <f:convertNumber type="number" maxFractionDigits="2" />
  |           </h:outputText>
  |           <h:outputText value=" g" />
  |         </rich:column>
  | 
  |         <rich:column>
  |           <f:facet name="header">
  |             <h:outputText value="Price per 100g" />
  |           </f:facet>
  |           <h:outputText value="#{wf.price}">
  |             <f:convertNumber pattern="? ###0.00" />
  |           </h:outputText>
  |         </rich:column>
  | 
  |         <rich:column>
  |           <f:facet name="header">
  |             <h:outputText value="Actual cost" />
  |           </f:facet>
  |           <h:outputText value="#{wf.amountInGram / 100 * wf.price}">
  |             <f:convertNumber pattern="? ###0.00" />
  |           </h:outputText>
  |         </rich:column>
  |       </rich:dataTable>
  |     </h:form>
  |     <div class="section"><h:outputText value="Total cost: " /> <h:outputText
  |       value="#{recipePlanner.weeklyCookingPlan.getTotalPrice()}">
  |       <f:convertNumber pattern="? ###0.00" />
  |     </h:outputText></div>
  |   </s:fragment></div>
  |   <!-- ####### end of render shopping list on screen ############## -->
  | ... ... ... 
  | ... ... ...
  | </ui:composition>
  | 

UseCase flags used in pages.xhtml:

  | <page view-id="/recipe-detail.xhtml">
  | 		<navigation from-action="#{recipeManager.quitRecipeDetail}">
  | 			<rule if="#{recipeManager.currentUseCase == 'viewAllRecipes'}">
  | 				<redirect view-id="/all-recipes.xhtml" />
  | 			</rule>
  | 			<rule if="#{recipeManager.currentUseCase == 'doANewPlan'}">
  | 				<redirect view-id="/weekly-planner.xhtml" />
  | 			</rule>			
  | 			<rule if="#{recipeManager.currentUseCase == 'viewPastPlans'}">
  | 			  <redirect view-id="/my-past-plans.xhtml" />
  | 			</rule>			
  | 		</navigation>
  | 	</page>
  | 

The conversation beans (in my application they are manager beans) set each other's the currentUseCase whenever there is any dependency between the managers.....

This way the entity-oriented view code is very reusable. (a xxxx-detail.xhtml page is in fact a view representation of an entity bean. There the basic CRUD operation happens) Each useCase's view is simply composed with xxxx-detail.xhtml pages with additional information. So far my code for the views of useCases is very short. So I think syntax sugars for named conversation would be very nice. 

Regards,
Ellen

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4074217#4074217

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4074217



More information about the jboss-user mailing list