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

  • Home
  • SEARCH
  • 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 8629997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:57:05+00:00 2026-06-12T08:57:05+00:00

The problem that I am facing is that after I click on the h:commandLink

  • 0

The problem that I am facing is that after I click on the h:commandLink button the h:outputLabel isn’t showing anything. I have used selectedUser to store the value when the form is submitted but it seems selectedUser is not storing any value.

1)Here is the xhtml file.

<!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.org/ui"
    xmlns:c="http://java.sun.com/jsp/jstl/core">


<h:head></h:head>



<h:body class="thrColElsHdr">


        <div class="friends">

        <h4>Friends</h4>
        <h:form>
        <p:selectOneMenu value="#{chatBean.selectedUser}">
        <f:selectItems value="#{chatBean.friendList}" var="users" itemLabel="#{users.firstName}" itemValue="#{users}"/>
        </p:selectOneMenu>

        <h:commandLink>Chat</h:commandLink>
        </h:form>
        <br>
        </br>
        <h:outputLabel value="#{chatBean.selectedUser.firstName}"/>


        </div>




</h:body>
</html>

2)Here is the chatBean and it is session scoped using facesconfig.xml

package com.bean;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.faces.context.FacesContext;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;
import javax.servlet.http.HttpSession;

import com.entity.Friend;
import com.entity.User;

public class ChatBean {
    private EntityManager em;
    private User selectedUser;


    public User getSelectedUser() {
        return selectedUser;
    }


    public void setSelectedUser(User selectedUser) {
        this.selectedUser = selectedUser;
    }


    public ChatBean(){
        selectedUser= new User();
        EntityManagerFactory emf=Persistence.createEntityManagerFactory("FreeBird");
         em =emf.createEntityManager();
    }


public List<User> getFriendList(){

        FacesContext context = FacesContext.getCurrentInstance();
        HttpSession session = (HttpSession) context.getExternalContext().getSession(true);
        User user=(User) session.getAttribute("userdet");
        Query query = em.createQuery("SELECT f FROM Friend f WHERE f.email='"+user.getEmail()+"' AND f.status=1",Friend.class);
         List<Friend> results =query.getResultList();
         ArrayList<User> friends = new ArrayList<User>();
         Iterator<Friend> it = results.iterator();
          while(it.hasNext()){
              System.out.println("in getFriendList...");

             User friend =em.find(User.class,it.next().getFriendEmail());
             friends.add(friend);
         }
          return friends;
}
}

3) Here is the user entity class

package com.entity;

import java.io.Serializable;
import javax.persistence.*;


/**
 * The persistent class for the user database table.
 * 
 */
@Entity
public class User implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    private String email;

    @Lob()
    private String aboutMe;

    private String birthDate;

    private String city;

    private String college;

    private String confirmation;

    private String contactNo;

    private String country;

    private String degree;

    private String firstName;

    private String gender;

    private String highSchool;

    private String image;

    private String interest;

    private String lastName;

    private String password;

    private int pincode;

    @Lob()
    private String quote;

    private String relationship;

    private String secondarySchool;

    private String state;

    private String street;

    private String university;

    private String userName;

    public User() {
    }

    public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getAboutMe() {
        return this.aboutMe;
    }

    public void setAboutMe(String aboutMe) {
        this.aboutMe = aboutMe;
    }

    public String getBirthDate() {
        return this.birthDate;
    }

    public void setBirthDate(String birthDate) {
        this.birthDate = birthDate;
    }

    public String getCity() {
        return this.city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getCollege() {
        return this.college;
    }

    public void setCollege(String college) {
        this.college = college;
    }

    public String getConfirmation() {
        return this.confirmation;
    }

    public void setConfirmation(String confirmation) {
        this.confirmation = confirmation;
    }

    public String getContactNo() {
        return this.contactNo;
    }

    public void setContactNo(String contactNo) {
        this.contactNo = contactNo;
    }

    public String getCountry() {
        return this.country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getDegree() {
        return this.degree;
    }

    public void setDegree(String degree) {
        this.degree = degree;
    }

    public String getFirstName() {
        return this.firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getGender() {
        return this.gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getHighSchool() {
        return this.highSchool;
    }

    public void setHighSchool(String highSchool) {
        this.highSchool = highSchool;
    }

    public String getImage() {
        return this.image;
    }

    public void setImage(String image) {
        this.image = image;
    }

    public String getInterest() {
        return this.interest;
    }

    public void setInterest(String interest) {
        this.interest = interest;
    }

    public String getLastName() {
        return this.lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getPassword() {
        return this.password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getPincode() {
        return this.pincode;
    }

    public void setPincode(int pincode) {
        this.pincode = pincode;
    }

    public String getQuote() {
        return this.quote;
    }

    public void setQuote(String quote) {
        this.quote = quote;
    }

    public String getRelationship() {
        return this.relationship;
    }

    public void setRelationship(String relationship) {
        this.relationship = relationship;
    }

    public String getSecondarySchool() {
        return this.secondarySchool;
    }

    public void setSecondarySchool(String secondarySchool) {
        this.secondarySchool = secondarySchool;
    }

    public String getState() {
        return this.state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getStreet() {
        return this.street;
    }

    public void setStreet(String street) {
        this.street = street;
    }

    public String getUniversity() {
        return this.university;
    }

    public void setUniversity(String university) {
        this.university = university;
    }

    public String getUserName() {
        return this.userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

}
  • 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-06-12T08:57:06+00:00Added an answer on June 12, 2026 at 8:57 am

    Your managed bean must have the corresponding annotations:

    @ViewScoped
    @ManagedBean
    public class ChatBean {
        //...
    }
    

    The example can be corrected using one of these tips:

    • Add an action to your <h:commandLink> and bind it to a method that returns the name of your page. In this way, the page will be refreshed and it will show the new value in #{chatBean.selectedUser.firstName}:

      <h:commandLink action="#{chatBean.refresh}" value="Chat" />
      

    In your class:

    public String refresh() {
        return "index";
    }
    
    • Add ajax behavior to your <h:commandLink> in order to update the <h:outputLabel>. You should add an id attribute to your <h:outputLabel>:

      <h:commandLink value="Chat">
          <f:ajax render=":theLabel" />
      </h:commandLink>
      <!-- jsf code -->
      <h:outputLabel id="theLabel" value="#{chatBean.selectedUser.firstName}"/>
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So here is the problem that I am facing: I have an application that
I'm facing a problem that I can summarize as it follows: I have a
I'm facing a problem that seems to have no straighforward solution. I'm using java.util.Map
I am facing a situation that I have problem understanding... I am writing a
I have this label that i want to fadeOut after button event clicked. I
I have a problem that I am facing OuOfMemory Error while printing a string
The problem I am facing is that ,I have a set of questions in
The problem I am facing is that after I authorize my app for current
i am facing a problem that after i created the jQuery post, i was
I'm facing the problem that, after i append a bunch of images in a

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.