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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:41:58+00:00 2026-05-17T14:41:58+00:00

A pretty normal case: We have a ‘portlet’ composite component that has two states:

  • 0

A pretty normal case:

We have a ‘portlet’ composite component that has two states: expanded and collapsed. Portlets start as expanded, but user can collapse them by clicking on them. This state should be saved to the session, so that once the user refreshes the page or navigates to a new, the portlets remember if they are expanded/collapsed.

This is the core of the problem: How would you actually implement such state-saving into a component, that can be inserted on page multiple times?

Some background / ideas:

Implementing state-saving for one portlet would be easily achieved by using a session-scoped bean. Also fixed number of portlets could be supported by creating a fixed number of session-scoped beans or declaring different properties into one bean. However, I don’t want to even mention why those approaches is bad.

My initial idea for this was to create a Map (or some object structure) under single session bean to hold the states for all of the portlets. However, I cannot directly refer to this data from JSF (so that JSF would also update them). I considered writing a specific getter/setter to fetch/update the right value in the map, but that’s not possible as there’s no identifying data during the execution of getters and setters.

However, it is probably clear that I need to save the states into a session bean. I can do the state-saving pretty easily by posting a form with f:ajax and executing a special method using listener and the submitted data. In order to support multiple instances of component, I could use (multiple instances of) a request-scoped bean to handle each expand/collapse. However, in order to actually post the data that identifies the portlet and its’ state, I need to first insert it on the form fields in render-time.

So, how to actually provide each portlet with right data on render-time (actually just state boolean/enum in this case, but consider a case where more data should be handled)?

It seems that:

  • h:inputHidden and h:inputText do not support setting initial value other than than the value-attribute (which would point to #{portletBean.portletState}).
  • I cannot auto-load the request beans with right initial values on their creation time, as there’s no identifying information available.

Once again it feels like I’m missing something… pointers?

I suppose at least one of the answers would be to use UIComponent rather than composite components, but I would like to keep this as composite component as it contains lots of raw HTML elements.

Update:

  • There is a rather similar question, with suggestion to use view-scoped bean. I don’t think this is viable here, however.
  • 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-17T14:41:58+00:00Added an answer on May 17, 2026 at 2:41 pm

    I used a previously solved hack to call a bean method from JS:

    Created an empty, invisible form, with h:commandButton and f:ajax inside it calling listener.

    Created a separate button for launching the expand/collapse event. From that button initiate javascript method, that animates the expansion/collapse and at the same time clicks the hidden button inside the form. All needed data is sent using the listener attribute. Listener targets a session bean, which checks/updates a map of states, identified by component’s client ids.

    This is pretty simple, wonder why I didn’t realize it eariler…

    However, it’s still far from perfect and it doesn’t answer how the request-scoped beans could be initiated with default values to use them as storage/transport form.

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

Sidebar

Related Questions

Pretty self explanatory. I have a textbox in an updatepanel that will autopostback when
Pretty simple: I need a script that reads the element ij of TWO images
I've read pretty often, that using try-catch is quite slow compared to normal code.
I have a pretty normal setInterval call (I think): var myInterval = setInterval(myFunction('passVar1', 'passedVar2'),
We have a pretty normal looking printf style function in our project, with the
I have an ASP.NET GridView which has columns that look like this: | Foo
I have a Maven project that has always worked fine in Netbeans, but upgrading
This one has us all baffled at work. We have two services running on
Pretty new to MVC and the like. I have a class the looks like
Pretty simple question. I'm quite certain I have the Class, method, codebehind, etc linked

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.