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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:27:40+00:00 2026-05-17T21:27:40+00:00

I have two classes representing menu items. First one is Category , it represents

  • 0

I have two classes representing menu items.

First one is Category, it represents the parent menu items.

@Entity
@Table(name = "category")
@NamedQueries({
    @NamedQuery(name = "Category.findAll", query = "SELECT c FROM Category c"),
    @NamedQuery(name = "Category.findByCateId", query = "SELECT c FROM Category c WHERE c.cateId = :cateId"),
    @NamedQuery(name = "Category.findByCateName", query = "SELECT c FROM Category c WHERE c.cateName = :cateName")})
public class Category implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "cate_id")
    private Integer cateId;
    @Basic(optional = false)
    @Column(name = "cate_name")
    private String cateName;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "category")
    private List<SubCat> subCatList;

    public Category() {
    }

    public Category(Integer cateId) {
        this.cateId = cateId;
    }

    public Category(Integer cateId, String cateName) {
        this.cateId = cateId;
        this.cateName = cateName;
    }

    public Integer getCateId() {
        return cateId;
    }

    public void setCateId(Integer cateId) {
        this.cateId = cateId;
    }

    public String getCateName() {
        return cateName;
    }

    public void setCateName(String cateName) {
        this.cateName = cateName;
    }

    public List<SubCat> getSubCatList() {
        return subCatList;
    }

    public void setSubCatList(List<SubCat> subCatList) {
        this.subCatList = subCatList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (cateId != null ? cateId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Category)) {
            return false;
        }
        Category other = (Category) object;
        if ((this.cateId == null && other.cateId != null) || (this.cateId != null && !this.cateId.equals(other.cateId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.entity.Category[cateId=" + cateId + "]";
    }

}

Second is SubCategory, it represent the child menu items.

@Entity
@Table(name = "sub_cat")
@NamedQueries({
    @NamedQuery(name = "SubCat.findAll", query = "SELECT s FROM SubCat s"),
    @NamedQuery(name = "SubCat.findBySubcatid", query = "SELECT s FROM SubCat s WHERE s.subcatid = :subcatid"),
    @NamedQuery(name = "SubCat.findBySubcatName", query = "SELECT s FROM SubCat s WHERE s.subcatName = :subcatName")})
public class SubCat implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "subcatid")
    private Integer subcatid;
    @Basic(optional = false)
    @Column(name = "subcat_name")
    private String subcatName;
    @JoinColumn(name = "cat_parent", referencedColumnName = "cate_id")
    @ManyToOne(optional = false)
    private Category category;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "subCat")
    private List<Items> itemList;

    public SubCat() {
    }

    public SubCat(Integer subcatid) {
        this.subcatid = subcatid;
    }

    public SubCat(Integer subcatid, String subcatName) {
        this.subcatid = subcatid;
        this.subcatName = subcatName;
    }

    public Integer getSubcatid() {
        return subcatid;
    }

    public void setSubcatid(Integer subcatid) {
        this.subcatid = subcatid;
    }

    public String getSubcatName() {
        return subcatName;
    }

    public void setSubcatName(String subcatName) {
        this.subcatName = subcatName;
    }

    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    }

    public List<Items> getItemList() {
        return itemList;
    }

    public void setItemList(List<Items> itemList) {
        this.itemList = itemList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (subcatid != null ? subcatid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof SubCat)) {
            return false;
        }
        SubCat other = (SubCat) object;
        if ((this.subcatid == null && other.subcatid != null) || (this.subcatid != null && !this.subcatid.equals(other.subcatid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.entity.SubCat[subcatid=" + subcatid + "]";
    }

}

Two class have many to one relationship. I want to display them on my a JSF 2.0/Facelets webpage like:

Category 1
    |
    ---->  Sub_Category 1 
    |
    ---->  Sub_Category 2
Category 2
    |
    ---->  Sub_Category 3
    |
    ---->  Sub_Category 4
    . . . 

How can I do this?

  • 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-17T21:27:41+00:00Added an answer on May 17, 2026 at 9:27 pm

    As per the comments on the question, you seem to have trouble with displaying them in the view side, which is apparently JSF. As per your question history, you seem to be using JSF2 on Facelets as view technology.

    You can just use ui:repeat to iterate over the categories and their subcategories. Assuming that you’ve a managed bean which returns a List<Category> by #{bean.categories}, here’s an example:

    <ul>
        <ui:repeat value="#{bean.categories}" var="category">
            <li>#{category.cateName}
                <h:panelGroup rendered="#{not empty category.subCatList}">
                    <ul>
                        <ui:repeat value="#{category.subCatList}" var="subCat">
                            <li>#{subCat.subcatName}</li>
                        </ui:repeat>
                    </ul>
                </h:panelGroup>
            </li>
        </ui:repeat>
    </ul>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on an assignment and have to create two classes, one represents
I have two classes, and want to include a static instance of one class
I have two classes in separate folders class Parent { public $path = null;
I have two classes, Foo and Bar, that have constructors like this: class Foo
I have two classes that each need an instance of each other to function.
I have two classes: Media and Container. I have two lists List<Media> and List<Container>
I have two classes A and B in two different .NET assemblies: AssemblyA and
I have two classes declared like this: class Object1 { protected ulong guid; protected
I have two classes: Action and MyAction . The latter is declared as: class
Suppose I have two classes with the same interface: interface ISomeInterface { int foo{get;

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.