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 6704501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:17:45+00:00 2026-05-26T07:17:45+00:00

how to move a variable’s value from jsf’s bean page (i.e, bean.java) to another

  • 0

how to move a variable’s value from jsf’s bean page (i.e, bean.java) to another java class? when i tried to do that, the value assinged to the variable in the second java class is NULL.,

I have used primefaces UI framework(something like jsf) and assigned every fields value in to a bean class. the value assigned to every variable in bean class is proper. but when i tried to move those values to another .java file. The scope of the variable dies, and the value is NULL. Check out my codings..

LOGIN.XHTML

<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.prime.com.tr/ui">


<h:head></h:head>
<h:body>

<p:panel header="Login" style="">
<h:form>

<h:panelGrid columns="2" cellpadding="2">
<h:outputText value="Username"></h:outputText>
<p:inputText id="userName" value="#{loginBean.userName}"></p:inputText>
<h:outputText value="Password"></h:outputText>
<p:password id="password" value="#{loginBean.password}"></p:password>
<p:commandButton value="Sign in" ajax="false" actionListener="#{loginBean.forward}"></p:commandButton>



</h:panelGrid>

</h:form> 

</p:panel>
</h:body>


</html>

loginBean.java

package bean;
import receive.*;
public class loginBean {
public String userName;
public String password;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public void forward()
{
System.out.println(getUserName());
receiveclass r=new receiveclass();
r.dbc();
}
}

receiveclass.java

package receive;
import bean.loginBean; 
public class receiveclass {
loginBean lb=new loginBean();

public void dbc()
{
  String s= lb.getUserName();
  String p=lb.getPassword();
  System.out.println(s);
  System.out.println(p);
  //System.out.println("hi");

}

}

output is,

if i give as admin, admin in text fields

i am receiving as

admin
null
null

  • 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-26T07:17:46+00:00Added an answer on May 26, 2026 at 7:17 am

    You’re manually creating the beans instead of letting JSF manage the beans. Manually created beans won’t be used by JSF at all. You need to let JSF auto-create and manage those beans. You can access other JSF managed beans by injecting it as @ManagedProperty:

    In your particular case, the following should work:

    @ManagedBean
    @RequestScoped
    public class LoginBean {
    
        private String userName;
        private String password;
    
        @ManagedProperty
        private ReceiveClass receiveClass;
    
        public void forward() {
            receiveClass.dbc(this);
        }
    
        // Add/generate getters and setters.
    }
    

    with

    @ManagedBean
    @SessionScoped
    public class ReceiveClass {
    
        public void dbc(LoginBean loginBean) {
            System.out.println(loginBean.getUserName());
        }
    
    }
    

    (Note that I fixed the code to adhere the Java Naming Conventions properly. Class names ought to start with uppercase)

    See also:

    • Communication in JSF 2.0 – Injecting managed beans in each other
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to move a sub directory from one directory to another, given that both
I would like to move a file or folder from one place to another
I've been attempting move a directory structure from one location to another in Subversion,
Is it possible to move quickly from one place in code to another where
We are working an algorithm that calculate the optimal way to move resources from
We just did a move from storing all files locally to storing them on
I need to move data from a datareader into a Farpoint Spreadsheet component in
I am planning to move my vmWare's Virtual Machines from a Windows host to
I have the following code in a UIView subclass that will move it off
I'm trying to create an annotation for a local variable. I know that I

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.