Hi again wim DC, and thanks for making your thoughts clear by exemplifying.
Basically it's a filing system that follows a project through from start to end. You add desicions, metrics and results as you go along the phases. There's just a lot of attachments to go with that.
The solution as you suggest looks a lot like the one I'm leaning towards in my 'conclusion', which was also based on your comments.
I'll tailor your examples.. Mostly to see if I am getting this.
public class Record1EntityA{
private List<Attachment> planningDocsList;
private List<Attachment> reviewDocsList;
...
}
public class Record1BeanA{
private List<Attachment> selectedAttachment;
private Record1EntityA entity;
private Record1Service recordService;
public Record1BeanA(){
}
public String prepareAttachPlanning(){
selectedAttachment= entity.getPlanningDocsList();
return "prepareAttachment";
}
public String prepareAttachReview(){
selectedAttachment= entity.getReviewDocsList();
return "prepareAttachment";
}
...
}
public class AttachmentBean{
private Attachment attachment;
private List attachmentList;
private AttachmentService attachmentService;
public AttachmentBean(){
attachment = new Attachment();
}
-getters and setters-
public String saveAttachment(){
attachmentService.save(attachment); //optional with cascade?
attachmentList.add(attachment);
return "attachmentSuccessful";
}
}
<managed-bean>
<managed-bean-name>attachmentBean</managed-bean-name>
<managed-bean-class>my.package.beansattachmentBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>attachmentList</property-name>
<value>#{record1BeanA.selectedAttachment}</value>
</managed-property>
</managed-bean>
record1.jsp
..some display of record1BeanA.entity.planningDocsList..
<h:commandButton action="#{record1BeanA.prepareAttachPlanning}" />
..some display of record1BeanA.entity.reviewDocsList..
<h:commandButton action="#{record1BeanA.prepareAttachReview}" />
attachment.jsp
<h:inputText value="#{attachmentBean.attachment.name}" />
...
<h:commandButton action="#{attachmentBean.saveAttachment}" />
User clicks Record1BeanA.prepareAttachPlanning() - button
User fills in AttachmentBean.attachment
User clicks AttachmentBean.saveAttachment()
-> Record1BeanA.entity.planningDocsList has the new Attachment element?
Ok, this demonstrates a possible implementation with the one-method-per-list-per-bean approach that I have not yet tried. Looks really clean. But we'd need to do the same for the other 12 beans. The faces-config defines AttachmentBean as depending on Record1BeanA - but how can then Record2BeanA be handeled? Other AttachmentBeans? Add managed properites for each/which one is active?
Lets have a look at the example of just using the JSP
public class RecordBeanA{
private RecordEntityA entity;
private RecordService recordService;
public RecordBeanA(){
}
// no attachment actions
...
}
public class AttachmentBean{
private Attachment attachment;
private List attachmentList;
private AttachmentService attachmentService;
public AttachmentBean(){
attachment = new Attachment();
}
-getters and setters-
public void prepare(ActionEvent event){
attachmentList = (List) FacesUtil.getParamFromEvent("container", event);
}
public String saveAttachment(){
attachmentService.save(attachment); //optional with cascade?
attachmentList.add(attachment);
return "attachmentSuccessful";
}
}
<h:commandButton action="prepareAttachment" actionListener="#{attachmentBean.prepare}" >
<f:param name="container" value="{recordBeanA.entity.planningDocsList}" />
</h:commandButton>
<h:commandButton action="prepareAttachment" actionListener="#{attachmentBean.prepare}" >
<f:param name="container" value="{recordBeanA.entity.reviewDocsList}" />
</h:commandButton>
That's all. RecordBeanA is clean from attachment handling.
What do you think, which is better? Not sure where I stand atm..
Cheers
Johannes
Edited by johannes, 06 July 2011 - 11:35 PM.
Forgot about the different types of bean A in the first example