aspose file tools*
The moose likes JSP and the fly likes jsp:useBean statements within if-else Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp:useBean statements within if-else" Watch "jsp:useBean statements within if-else" New topic
Author

jsp:useBean statements within if-else

Faisal Khan
Ranch Hand

Joined: Jun 29, 2003
Posts: 285
Hi,
I am doing the following:

I get the following error: jsp.error.useBean.duplicate
I presume the beans are being created before getting to the if-else statments. Can someone please enlighten me how I can achieve the above other than using separate JSP pages for this purpose.
Thanks.


The secret to creativity is knowing how to hide your sources.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Yeah, that's not allowed. And in any case, remember that useBean is going to create scripting variables for the bean and by nesting them within a block, their scope would be limited to the block.
It's unusual to try an make the same variable of a different type. What are you actually trying to do?
What is the relationship of the two types? Does one extend the other? Do they implement a common interface? If they share no relationship, how would you expect to be able to use the bean in a common fashion on the rest of the page?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Faisal Khan
Ranch Hand

Joined: Jun 29, 2003
Posts: 285
Thanks Bear,
From my reading around, I realised what I was doing is wrong but not sure of the best solution. The QuoteRecalculateBean extends QuoteBean and overrides two methods.
What I want to do is first time the page is loaded the QuoteBean class should be used, if the user hits recalculate the page gets reloaded and this time it should use QuoteRecalculateBean to work out the new loan.
Would I be better off handling this in my Action class and storing quote in the session, then changing all ${quote.listPrice} etc to ${sessionScop.quote.listPrice} etc.
Do I make sense?
FK
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

I think that the more processing you do in the action, rather than on the JSP, the easier and clearer it is going to be.
Faisal Khan
Ranch Hand

Joined: Jun 29, 2003
Posts: 285
Thanks again Bear.
I better get re-writing now.
FK
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsp:useBean statements within if-else