Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSTL over a Set: Did not get data as expected

 
H Paul
Ranch Hand
Posts: 471
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Set of Items (In this for example, it has 1 item with value as below)


Using old WAY 1 as below, I got the data display correctly: 04


But with this WAY 2 as below, I got the data wrong: false ( I expected the value 04 and not false).
What/Why the error?

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64712
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not at all surprising. The JSTL and EL have no idea that you have a private member named set. What it sees is the Bean property set which you created with the isSet() accessor. Very bad design, by the way.

Also, the began, at least what you show, has no getSet() method. Please avoid such red herrings in the future.
 
H Paul
Ranch Hand
Posts: 471
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Technically, I'm a bit confused by what you said. Can you re-words?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64712
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The bottom line is that your bean is busted and doesn't follow JavaBean best practices and conventions.
 
H Paul
Ranch Hand
Posts: 471
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


1.
For the boolean isSet, 2 methods generated

public boolean isSet() {
return isSet;
}
public void setSet(boolean isSet) {
this.isSet = isSet;
}

Is this correct from Bean Spec point of view?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64712
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. You have two ambiguous meanings of the property set.
 
H Paul
Ranch Hand
Posts: 471
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Side note; I used Eclipse and I got 4 methods generated for those 2 fields/property.

Now, if I undestand what you said correctly: even technically (with no compilator error), it is confusing design-wise
in terms of choosing property name which are confusing to JSTL?

(As usally, correct me if I am wrong. )
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64712
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, this is a horribly-designed bean whether it compiles or not.

Remember, the #1 rule of development is clarity.

The first mistake is having members named set and isSet. Start by fixing that with better and unambiguous names.
 
H Paul
Ranch Hand
Posts: 471
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mistake corrected and it works. Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic