001    package hirondelle.web4jtools.codegenerator.jsp;
002    
003    import hirondelle.web4j.model.AppException;
004    import hirondelle.web4j.action.ActionImpl;
005    import hirondelle.web4j.request.RequestParser;
006    import hirondelle.web4j.action.ResponsePage;
007    import hirondelle.web4jtools.codegenerator.codes.UiStyle;
008    import hirondelle.web4jtools.codegenerator.feature.Feature;
009    import hirondelle.web4jtools.codegenerator.feature.FeatureAction;
010    import hirondelle.web4jtools.util.TemplatedPage;
011    
012    /** 
013    * Generate a JSP snippet for the feature, and serve as plain text. 
014    * 
015    * <P>Uses the {@link hirondelle.web4jtools.codegenerator.feature.Feature} and 
016    * List of {@link hirondelle.web4jtools.codegenerator.field.Field} objects placed in session scope.
017    */
018    public final class JspAction extends ActionImpl {
019    
020      public JspAction(RequestParser aRequestParser){
021        super(LIST_AND_EDIT, aRequestParser);
022      }
023      
024      @Override  public ResponsePage execute() throws AppException {
025        UiStyle uiStyle = getUiStyle();
026        if ( UiStyle.ListAndEdit == uiStyle ) {
027          //use default forward
028        }
029        else if ( UiStyle.ShowAndApply == uiStyle ) {
030          setResponsePage(SHOW_AND_APPLY);
031        }
032        else {
033          throw new AssertionError("Unexpected value for UiStyle : " + uiStyle);
034        }
035        return getResponsePage();
036      }
037      
038      // PRIVATE //
039      private static final ResponsePage LIST_AND_EDIT = TemplatedPage.getPlain("JSP", "listAndEdit.jsp", JspAction.class);
040      private static final ResponsePage SHOW_AND_APPLY = TemplatedPage.getPlain("JSP", "showAndApply.jsp", JspAction.class);
041      
042      private UiStyle getUiStyle() {
043        Feature feature = (Feature) getFromSession(FeatureAction.FEATURE_KEY);
044        return feature.getUiStyle();
045      }
046    }