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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:40:56+00:00 2026-05-22T00:40:56+00:00

I would like to have a reusable ui component which is tied to the

  • 0

I would like to have a reusable ui component which is tied to the model.

For example :

  1. I have a selectonemenu that is chained to another selectonemenu (like department -> sub-department)
  2. Would like to make this a composite component
  3. This composite component is going to be tied to a specific JSF Bean

I think this idea works if im only using one compositeComponent.

But this will not work if i make use of more than one compositeComponent of the same type, since the compositeComponent’s JSF Bean will be the same (in this example, im using view scope), and will share the state between one or more compositeComponents.

This is one rough example that illustrates my confusion. In this case, Page1.xhtml (with the main model of Page1Bean.java), makes use of 2 compositeComponents (which is handled by the JSF Bean of MyCompositeComponent.java)

The composite component will be something like :

<!-- one composite component that has 2 chained selectOneMenus -->
<h:selectOneMenu
    ...
    value="#{myCompositeComponentBean.firstComboValue}"
    valueChangeListener="#{myCompositeComponentBean.yyy}">
    <f:ajax event="valueChange" execute="@this" ... />
    <f:selectItem itemLabel="Choose one .." noSelectionOption="true" />
    <f:selectItems value="#{myCompositeComponentBean.firstComboList}" .... />
</h:selectOneMenu>
<h:selectOneMenu
    ...
    value="#{myCompositeComponentBean.secondComboValue}"
    valueChangeListener="#{myCompositeComponentBean.bbb}">
    <f:selectItem itemLabel="Choose one .." noSelectionOption="true" />
    <f:selectItems value="#{myCompositeComponentBean.secondComboList}" .... />
</h:selectOneMenu>

And the composite component’s JSF Bean will be like :

// this model will serve the composite component
@Named
@Scope("view")
public class MyCompositeComponentBean {
    private String firstComboValue, secondComboValue;
    private List<String> firstComboList, secondComboList;
    ...
}

This is an example of Page1.xhtml :

....
main department : <my:comboChainComponent /> <!-- 2 select items will be rendered here -->
secondary department : <my:comboChainComponent /> <!-- another 2 select items will be rendered here -->
....

And the Page1Bean (Main JSF Bean for Page1.xhtml)

@Named
@Scope("view")
public class Page1Bean {
    // inject the first bean for the composite component 1
    @Inject private MyCompositeComponentBean bean1;
    @Inject private MyCompositeComponentBean bean2;
    ...
}

Is it possible to achieve this kind of reusability?

Thank you.

  • 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-22T00:40:56+00:00Added an answer on May 22, 2026 at 12:40 am

    Why don’t use this kind of approach.

    <mytag:combo id="combo1" 
             value="#{bean.firstData}" 
             model="#{globalBean.getList()}"
             update="form1:combo2"   />
    
    <mytag:combo id="combo2" 
             value="#{bean.secondData}" 
             model="#{globalBean.getSubList(bean.firstData)}"  />
    

    You can use composite attribute.

    ...
    <composite:interface name="combo">
       ... define your attributes here
    </composite:interface>
    
    <composite:implementation>
    <p:outputPanel id="content">
        <p:selectOneMenu id="select_menu_1" value="#{cc.attrs.value}">
             <f:selectItems value="#{cc.attrs.model}" />
            <p:ajax event="change" process="@this" update="#{cc.attrs.update}" />
        //add converter if you want 
        </p:selectOneMenu>
    </p:outputPanel>
    </composite:implementation>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have reusable ratings (typical layout with 5 stars). I have
I have a problem that I would like have solved via a SQL query.
So in my project i would like have a nice treeview that has images.
I would like to have it so that when I play one Vimeo video
I would like to have a Referral model, where user A can refer an
I would like to have an interface that allows for a generic type public
I have developed some reusable android component which is basically a class . This
I have this C# class structure that I would like to refactor to use
I have created a custom UIView that I would like to use on multiple
I'm creating a reusable flex tree component. And i would like to stick in

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.