calling an inner class in a <jsp:usebean> tag

Hi everybody !

Here's my problem : working in my project on multiple pages, I'm using inner classes/beans to limitate my '.java' files but I'm stuck when calling that 'inner-bean' in my jsp:usebean tag.

First, I tried to declare in the class parameter : 'class="MyPrincipalBean.theInnerBean" but jsp returns me a 'not found' message.

I tried an other issue with this :

'class="MyPrincipalBean$theInnerBean" but I encountered a 'Attempt to use a bean type without a void constructor in jsp:useBean tag (JSP 1.1 specification, 2.13.1)'. Since I can't find that specification, I'm sending an SOS.

Am I on the good way ? If somebody as encoutered that sort of problem, it would be very kind of you to help me.

Thanks for your help !

pf_delagrange@yahoo.fr

[836 byte] By [pf_delagrange] at [2007-9-26 3:36:50]
# 1

PF:

First, is your inner class declared with the "static" modifier so that it can be created without an instance of the outer class?

If the first is true, does your inner class have a default constructor (i.e. a constructor without arguments)?

Third, are both the outer and the inner class declared as public?

Let me know!

John

johnrayburn at 2007-6-29 12:08:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

PF:

One note that I would make is the following:

Do you really need to use an inner class? Does using an inner class in this case model the objects correctly? If you think it may not be the case, then I would suggest not using inner classes just to limit the number of Java files. As you know, even if you limit the number of Java files, there is still one class file created for each class, whether inner, outer, nested, or anonymous.

John

johnrayburn at 2007-6-29 12:08:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Thanks for your help!

I must recognize that my explainations weren't really precise.

My principal bean owns a table of my inner-class type :

public class FirstBean extends EntityBean {

....

private SecondBean[] tabSB;

...

public SecondBean[] getTabSB() {...}

public void setTabSB(SecondBean[] p_tabSB) {...}

...

public class SecondBean {...}

}

So I can call a specific bean from the tab in my Servlet for another page.

But I think I have the solution and I need your advise :

I tried this :

<jsp:useBean id="FirstBean" class="<...>.FirstBean" scope="session" />

<jsp:useBean id="SecBean" beanName="<...>.FirstBean$SecondBean" type="<...>.FirstBean$SecondBean" scope="request" />

And would you believe it ? It seems to work ! But I have to test this farther to be sure. What do you think of it ?

pf_delagrange at 2007-6-29 12:08:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...