Solved

Communication between two session beans in jsp

Posted on 2008-06-26
3
277 Views
Last Modified: 2008-06-26
Hi.
I'm creating a rather complex webpage here, and keeping all methods in one session bean creates an enormous class.
I therefore wonder if it is possible break this into several session beans.
The problem is communication between the session beans.
Say Im using one session for selecting language, and one session for displaying some content.
The java class for language selection is simple: (See code snippet)

Problem: The answer from Content is always 1.

Any idea why?
Or any neat trick to avoid this?

Jsp:
<jsp:useBean id="lang" class="Language" scope="session" />
public class Language implements Serializable {
   private int language = 1;
   private static Reference ref = null;
   public int getLanguage() { return language;}
   public void setLanguage(int language) { this.language = language; }
   public String languageTest() { return language select =  + this.language; }
   public static synchronized Language getDefault() {
       Language obj;
        if (ref != null) {
            obj = (Language) ref.get();
        } else {
            obj = null;
        }
        if (obj == null) {
            obj = new Language ();
            ref = new WeakReference(obj);
        }
        return obj;
    }
}
and the java class for content is :
Jsp:
<jsp:useBean id="cont" class=" Content " scope="session" />
public class Content implements Serializable {
   private Language language;
   public Content() { language = Language.getDefault(); }   
   public String contentBlock() {
       if(language.getLanguage() == 1) return Some text;
       if(language.getLanguage() == 2) return Some other text;
   }
   public String languageTest() { return language select =  + this.language. getLanguage(); }
}

Open in new window

0
Comment
Question by:kristian_gr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 92

Expert Comment

by:objects
ID: 21872621
You could have your session bean encapsulate the various beans u need

public class MySessionBean implements Serializable
{
   private Language language = new Language();
   private Content content = new Content();

    ...

0
 

Author Comment

by:kristian_gr
ID: 21872895
hmm. not quite what I was looking for.

Is it possible to something like:
public class MySessionBean extends Language, Content

0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 21872910
> hmm. not quite what I was looking for.

may be a better way, not really my area

> Is it possible to something like:
> public class MySessionBean extends Language, Content

No you can only extend a single class

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question