Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 795393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:28:26+00:00 2026-05-14T22:28:26+00:00

It seems I am not clear on my previous question about managed bean. So,

  • 0

It seems I am not clear on my previous question about managed bean. So, I am posting it again in a more systematic manner.

I have one page:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        <ui:insert name="head">

        </ui:insert>

        <br/><br/>
        <h:inputText value="#{MasterBean.laala}"/>
        <br/><br/>

        <ui:insert name="content">

        </ui:insert>
    </h:body>
</html>

This is its bean:

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;


@ManagedBean(name="MasterBean")
@ViewScoped
public class MasterBean {

    private String laala;

    public String getLaala() {
        return laala;
    }

    public void setLaala(String laala) {
        this.laala = laala;
    }


    public MasterBean() {
    }

}

This is data.xhtml which uses master.xhtml:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        <ui:composition template="master.xhtml">
            <ui:define name="head">
                laala
            </ui:define>

            <h:outputText value="#{pageBean.content}"/>

            <ui:define name="content">
                <h:commandButton actionListener="#{pageBean.speakHello}"/>
            </ui:define>>


        </ui:composition>
    </h:body>
</html>

This is its bean:

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;


@ManagedBean(name="pageBean")
@ViewScoped
public class pageBean {

    private String content;

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }


    public void speakHello(){
        //how do i get value of laaala here which is in MasterBean???
        content = ??? + " Hello friend";
    }

    public pageBean() {
    }

}

What should I put in the blank where ??? is marked in speakHello(). How do I get value of other bean in this bean?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T22:28:27+00:00Added an answer on May 14, 2026 at 10:28 pm

    As you can learn in a JSF2 tutorial one can use the dependency injection feature. In your case it would be about injecting MasterBean instance to pageBean. I believe you could have something like this in your pageBean:

    @ManagedBean(name="pageBean")
    @ViewScoped
    public class pageBean {
    
        private String content;
    
        @ManagedProperty(value="#{MasterBean}")
        private MasterBean masterBean;
    
        ...
    

    a then use it in your methods:

     public void speakHello(){
        //how do i get value of laaala here which is in MasterBean???
        content = masterBean.getLaala() + " Hello friend";
     }
    

    I haven’t tried that myself. I hope it will work.

    BTW, it’s highly recommended not to start class name with a small letter. So pageBean class should be called PageBean instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple question whose answer seems not to be in the official
Following up on my previous newbie question about Paypal , I have a new
This question might seem a repeat of previous ones. I have read through a
Is my second question on this topic today but on the previous one it
In an answer to a previous question: How can I use 'do I have
A previous question asked if changing one line of code implemented persistent SSL connections.
In a previous question I asked about weaknesses in my own security layer concept...
Asp.net mvc 2 seems to not clear a required validation error for a password
I have a very similar problem to the one described in this question .
The title may not seem very clear - was not sure how to explain

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.