开发者

Spring Web Flow - Issue of Reusing Subflow

This is probably a design issue then coding issue.

We have an existing ordering interface which we are trying to convert into Spring Web Flow. For each product we have a few reusable components such as contact details, contract details, order details, pricing ...

Now we want to put them on a single page but still keep it reusable such that it can be used for different product.

eg - I have a Service Details page on which I have three diff开发者_开发问答erent components called:

    Host Details
    IP Details
    Backup Details

Each of these components needs to be reused in other products, so the question is how to achieve this?

Problem: If i create a subflow called "Service Details" then the view associated will have to have all three jsps included and the subflow's model attribute will be a composite attribute which will have to bind all above values such as Host Details, IP Details, Backup Details ....

I am never going to reuse entire page, only the components are needed to be reused across different pages.


This isn't really specific to webflow - you want to create re-usable view components which are related to components in your model?

Its true that in webflow you can only do automatic binding & validation against a single object in one of the variable scopes, so I suggest that you create a bean to hold these three components, e.g.

public class Holder implements Serializable {

      private HostDetails;
      private IpDetails;
      private BackupDetails;

      //getters & setters
}

Then the 'model' attribute in your flow would refer to an instance of this Holder class.

You just need to remember that if you want to bind a submitted field to e.g. HostDetails, your input should use dot notation to reference the field (including 'holder'):

<input type="text" name="holder.hostDetails.hostName"/>

Then, in order to re-use components in your view layer, create one JSP which includes the other components. I like to create .tag files for this purpose, one tag file responsible for rendering each component.

<%!-- This is the main JSP --%>

<%!-- Include modules using tag files --%>
<content:hostDetails details="${holder.hostDetails}" nestedPath="holder.hostDetails"/>
<content:ipDetails details="${holder.ipDetails}" nestedPath="holder.ipDetails"/>
<content:backupDetails details="${holder.backupDetails}" nestedPath="holder.backupDetails "/>

I put the 'nestedPath' attribute there so that the tag file is modular and re-usable even when included in different pages (even without the Holder.class). There might be a more elegant way of doing that bit...

I haven't shown the tag file implementation here, but look here: http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSPTags5.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜