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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:46:09+00:00 2026-05-30T23:46:09+00:00

Which method is better?: add(new Label(label, new PropertyModel<String>(cat, name))); or add(new Label(label, cat.getName())); I

  • 0

Which method is better?:

add(new Label("label", new PropertyModel<String>(cat, "name")));

or

add(new Label("label", cat.getName()));

I tried to find any information about comparison.. but couldn’t find anything
How I understand the first method is for read/write logic and the second for read only logic, (if I am not right please write me). But for read only logic which better is?

  • 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-30T23:46:10+00:00Added an answer on May 30, 2026 at 11:46 pm

    They’re functionally different.

    The first one says: whenever this component is re-rendered, refresh the value. The second one says: display the value as it was at the time of creation.

    Which one do you need? If you want a dynamically refreshing label, you have no choice, it’s PropertyModel or CompoundPropertyModel (see later).

    If you want it to stay the same, even if the underlying object changes, you can’t use PropertyModels.

    However, if you are absolutely sure that cat.getName() is never going to change, and therefore the two versions behave the same way, I personally wouldn’t use PropertyModel for three reasons:

    1. It breaks encapsulation: in the absence of a getter, it will try to access the private field itself.
    2. As @Jesse pointed it out, it’s “magic”. If you refactor your class and rename your fields, your PropertyModel will break.
    3. It’s not easier to read or maintain. Granted, it’s not that much harder either but why add any unnecessary complexity when you’re not getting anything out of it? If you put cat.getName() there, you can “click through” in your IDE, your label will show up in a search for all invocations of the getName() method and so on.

    If you have many components referring to fields of the same object, you can consider using CompoundPropertyModels, which, although still suffer from problems 1 and 2, make your code look a lot cleaner.

    If you have three or fewer components like this though and you don’t need a dynamic model, just use the modelless format.

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

Sidebar

Related Questions

Does anyone have any advice on which method is better when caching data in
Which method is better and why, when? In terms of scalability,performance etc which one
With .NET, which data access method is better to use LINQ to SQL,entity framework,
Out of the following queries, which method would you consider the better one? What
Some of my classes should be treated differently. Which solution is better: Introduce new
Which method is preferred? Session.Remove(foo); Session[foo] = null; Is there a difference?
Which method would you recommend to pass data from a child view back to
Which method makes the most sense for importing a module in python that is
Which method do you think is the best. Use the System.IO.Packaging namespace? Use interop
which method do you prefer for creating dynamic sql queries? formating or streaming? Is

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.