1 Reply Latest reply on May 29, 2007 12:21 PM by wayfarer3130

    Add operation specific pages.xml configuration

    wayfarer3130

      The pages.xml file assumes that for a given view-id, all responses/updates
      are handled identically. That isn't necessarily a good idea as it means that the
      action is the same in all cases and that violates separation of concerns. In specific, the example in the tutorial:

       <page view-id="/calculator.jsp" action="#{calculator.calculate}">
       <param name="x" value="#{calculator.lhs}"/>
       <param name="y" value="#{calculator.rhs}"/>
       <param name="op" converter="#{operatorConverter}" value="#{calculator.op}"/>
       </page>
      


      implies that calculator.calculate knows about EVERY op possible. In this example, it isn't possible to add a new operation without modifying calculator.calculate. Sometimes that is a good idea if there are a very few operations available, but if there are lots of operations, then calculator.calculate needs to have some sort of registration mechanism for new operations - however, consider the operation ?: that takes x,y,z. This operation won't work because the parsing doesn't work correctly. Or consider the hex conversion operation - again, the value is probably a double or integer or some such thing, and the parsing doesn't work for that either.
      It would be helpful to have something like:
      <pages>
       <page view-id="/calculator.jsp" action="#{calculator.calculate}">
       <param name="x" value="#{calculator.lhs}"/>
       <param name="y" value="#{calculator.rhs}"/>
       <param name="op" converter="#{operatorConverter}" value="#{calculator.op}"/>
       <view-modifier value="#{calculator.op}" />
       </page>
       <page view-id="/calculator.jsp" view-modifier="+" action="#{calculator.add}" />
       <page view-id="/calculator.jsp" view-modifier="?:">
       <param name="z" value="#{trivalued.z}" />
       </page>
      </pages>
      

      Note that this works fairly well with RESTful services - the post can be done to the same URL, but different actions can go through different operations, and then still render the same overall page.
      It also works well if you want to add another outcome variant - just add a view modifier and add a new outcome.

        • 1. Re: Add operation specific pages.xml configuration
          wayfarer3130

          Adding support for sub-operations also would allow better support for cache control, where the sub-operation might over-ride the parent's cache control, that is, the document might be cached by default for 9 seconds, by not at all for get operations with an op provided (this probably isn't realistic for this example, but for something like an editor or the like, it is very nice to have reasonable cache control built in.)

          <pages>
           <page view-id="/calculator.jsp" action="#{calculator.calculate}">
           <cache expires="9" />
           <param name="x" value="#{calculator.lhs}"/>
           <param name="y" value="#{calculator.rhs}"/>
           <param name="op" converter="#{operatorConverter}" value="#{calculator.op}"/>
           <view-modifier value="#{calculator.op}" />
           </page>
           <page view-id="/calculator.jsp" view-modifier="+" action="#{calculator.add}">
           <cache expires="0" />
           </page>
           <page view-id="/calculator.jsp" view-modifier="?:">
           <cache expires="0" />
           <param name="z" value="#{trivalued.z}" />
           </page>
          </pages>