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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:54:29+00:00 2026-06-14T03:54:29+00:00

I have an entity, with a field containing a list to Refs to other

  • 0

I have an entity, with a field containing a list to Refs to other entities (always 4). I’m trying to get some entities, and dispatch them for a jsp for display. I want all the Refs in the field to be loaded as well, and to access them in the jsp.

Here is my basic structure:

@Entity
public class Question {
    @Id Long id;
    @Index String question;
    @Load List<Ref<Answer>> answers = new ArrayList<Ref<Answer>>();
}

When I’m fetching question like this, obviously there’s an error in the jsp. Makes sense, because answers field is not a list of answers, but of refs:

ObjectifyService.register(Question.class);
ObjectifyService.register(Answer.class);

List<Question> questions = ofy().load().type(Question.class).limit(50).list();

req.setAttribute("questions", questions);
try { 
    getServletContext().getRequestDispatcher("/admin/view-questions.jsp").forward(req, resp); 
} catch (ServletException e) {
    System.out.println (e.getMessage());
}

So how do access the answers in the jsp? is the only way to manually loop through the questions and do a get() for the answers field?

  • 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-14T03:54:32+00:00Added an answer on June 14, 2026 at 3:54 am

    You might find this handy:

    public class Deref {
        public static class Func<T> implements Function<Ref<T>, T> {
            public static Func<Object> INSTANCE = new Func<Object>();
    
            @Override
            public T apply(Ref<T> ref) {
                return deref(ref);
            }
        }
    
        public static <T> T deref(Ref<T> ref) {
            return ref == null ? null : ref.get();
        }
    
        @SuppressWarnings({ "unchecked", "rawtypes" })
        public static <T> List<T> deref(List<Ref<T>> reflist) {
            return Lists.transform(reflist, (Func)Func.INSTANCE);
        }
    }
    

    Using this, you can provide a method like:

    @Entity
    public class Question {
        @Id Long id;
        @Index String question;
        @Load List<Ref<Answer>> answers = new ArrayList<Ref<Answer>>();
        public List<Answer> getAnswers() { return Deref.deref(answers); }
    }
    

    One caveat is that it’s a readonly list. With a little creativity you can create a writeable list, but it requires creating a ReversibleFunction and a new List.transform() method. If you just want something simple for JSPs, you might not want to worry about it.

    Alternatively, you can use the ‘value’ property of a Ref in most expression languages.

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

Sidebar

Related Questions

I have an entity set called Entities which has a field Name and a
I have a form containing several fields. One of them is a Datetime field.
A have a JPA entity that has timestamp field and is distinguished by a
How can I give set foreign key value field in Entity Framework. I have
I have a field aliases of type java.util.Set in one Entity . This Set
I have Entity Framework entities Events which have an EntityCollection of RSVP. I want
I have a 'mylist' model entity which contains a IEnumerable field. I'd like to
I'm trying to implement change password functionality in Symfony 2 project. I have entity
I have a Entity with a field which I want to be an Enum.
I have form with checkboxes loaded from database (I use entity field type). Checkboxes

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.