tags:

views:

153

answers:

2

Hi!

Weird question, but i need to find an answer.

Is there any way, in which i can manage managed beans in JSP? I`ll try to explain, what i want to do:

Imagine, i have JSP page, which, for example, is called document.save.jsp. I have some various documents with different types. Each of them have their own bean. For example: BillDocument.java, OrderDocument.java and ReportDocument.java.

BillDocument.java in my jsp is #{billdoc}.
OrderDocument.java -> #{orddoc}.
ReportDocument.java -> #{repdoc}.

Each of them have method save(). In my JSP i want to call this method, but i need to know, which document it is. In my mind this structure is something like:

<% String currentBean = ""; 
if(document == BillDocument){ 
   currentBean = #{billdoc};
}
if(document == OrderDocument){
   currentBean = #{orddoc};
}
if(document = ReportDocument){
   currentBean = #{repdoc};
}
 %>

Then, my Button with save method on it, may be smth like:

<h:commandButton action="currentbean.save"/>

Is there any way, in which i can store data about bean, which will be used in this button?

Thank`s for your replies!

+2  A: 

Why don't you have a fourth bean which has properties of all the other beans and just calls the relevant method given the document type?

i.e. DocumentBean.save() will call BillDocument.save() or OrderDocument.save() or... etc.

Rather than trying to do this in your JSF page.

Phill Sacre
+1  A: 

Why not have a super class, say Document which have the save method, and put the IF statement in this method.

In the JSF page, use something like:

<h:inputHidden id="docType" value="#{document.documentType}"/>

Populate this variable when creating the new document, and then use it in the save method

medopal