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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:11:11+00:00 2026-06-03T22:11:11+00:00

I have the following problem: In my data model I have a class called

  • 0

I have the following problem:

In my data model I have a class called Type. Type consists of a title and a description.

Now I have a dropdown box in which the user may select an instance of Type:

<h:selectOneMenu id="typeDropdown" onchange="displayDescription();">
      <f:selectItems value="#{operationCreator.types.title}" />
</h:selectOneMenu>

Below the dropdown box is a div area in which I want the description of the selected Type displayed.

My question is the following:

How can I store the description of the Type instances in javascript? A simple JSF tag which iterates over the list would do the job, but unfortunately I know of none. They all print additional HTML tags (like datatable), or work only with surrounding JSF tags (like selectItems).

I do know I could fix my problem using AJAX push, but I don’t want to. I want to access my data on page load in javascript.

I hope you can help me!
Thanks, Michael

  • 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-03T22:11:13+00:00Added an answer on June 3, 2026 at 10:11 pm

    Prepare the data in JSON format and let JSF just print it as a JS variable. You could do that either directly in backing bean

    public String getTypesAsJson() {
        return typesAsJson;
    }
    

    with

    <script>
        var types = #{bean.typesAsJson};
    </script>
    

    or in the view by iterating over a Java collection like List<Type> and printing the JavaScript code accordingly if the values are guaranteed to not contain any special characters in JS such as quotes and newlines:

    <script>
        var types = {
            <ui:repeat value="#{bean.types}" var="type" varStatus="loop">
                "#{type.title}": "#{type.description}"#{!loop.last ? "," : ""}
            </ui:repeat>
        };
    </script>
    

    The first way is preferable as it eliminates the risk for syntax errors in the produced JS code when the type title or description contains a JS special character. You can use among others Google Gson to convert a Java collection of beans to a string in valid JSON format.

    typesAsJson = new Gson().toJson(types);
    

    Now, if you make sure that the item value of the dropdownlist is the type title, then you can get the associated description as follows

    <h:selectOneMenu ... onchange="displayDescription(this)">
    

    with

    function displayDescription(dropdown) {
        var title = dropdown.options[dropdown.selectedIndex].value;
        var description = types[title];
        // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following cell which is used for my custom column data type
I have the following casting problem when my data structure sSpecificData contains a field
I have the following problem: list.c struct nmlist_element_s { void *data; struct nmlist_element_s *next;
I have the following problem, given the following service contract, data contract, and service
We have the following data model: CalendarAppointment 1 <------> * AppointmentRole * <--------> 1
I have the following model entity: public class ScheduledTask { public virtual int ScheduledTaskId
The problem is best explained by example, consider the following two models: class Topping(models.Model):
I have the following model: public class Blog { public int BlogID { get;
I have a following problem. I'm trying to implement a model for my QTreeView
I have problem using Fluent Nhibernate, I have following model. When I try to

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.