• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Should a Java Bean be always put inside a package?

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,
I would like to know is there a rule which states that Java Bean should always be in a package. I had some problems working with Java Bean having default package with some jsp action tags.


<jsp:useBean id="person3" class="test.Person">
<jsp:setProperty name="person3" property="name" value="${param.name}"/>
</jsp:useBean>

this works fine, but the same class with the package name omitted(in both java code and jsp) does not work

<jsp:useBean id="person3" class="Person">
<jsp:setProperty name="person3" property="name" value="${param.name}"/>
</jsp:useBean>


I have tried both the option with class files inside WEB-INF/classes/Person.class -> when there is no package and
WEB-INF/classes/test/Person.class -> when the class is put inside a package

Need your inputs
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, all your classes, beans or not, should be in packages. This became more of a requirement starting I think in Java 1.4 where classes inside a package can no longer import classes that are not in a package. This pretty much forces you to use packages for all of your classes (which is good practice anyway) when working with outside tools and frameworks.
 
tuty sra
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi guys,
Thanks for your reply. I got it now. Is the rule is applicable only from java1.4?. How could we import a class having default access from another class in some package in prior versions?
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by tuty sra:
hi guys,
Thanks for your reply. I got it now. Is the rule is applicable only from java1.4?. How could we import a class having default access from another class in some package in prior versions?



How could we import a class having default access
Default Access is different than the default package. I will guess you meant Default Package since that is more consistent with the rest of this thread.

I don't recall exactly how to use classes in the Default Package from other classes in a package, it has been a long time since I used it. I think in normal java you didn't need to import it, you could just use it. Not sure though.
 
tuty sra
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi steve,
you are right i was actually talking about the default package. I suppose what you say is correct. we would have had the ability to import the classes in default package without specifying anything.
 
reply
    Bookmark Topic Watch Topic
  • New Topic