File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes JSTL over a Set: Did not get data as expected Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSTL over a Set: Did not get data as expected" Watch "JSTL over a Set: Did not get data as expected" New topic
Author

JSTL over a Set: Did not get data as expected

H Paul
Ranch Hand

Joined: Jul 26, 2011
Posts: 394
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

Joined: Jan 10, 2002
Posts: 60780
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
H Paul
Ranch Hand

Joined: Jul 26, 2011
Posts: 394
Technically, I'm a bit confused by what you said. Can you re-words?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

The bottom line is that your bean is busted and doesn't follow JavaBean best practices and conventions.
H Paul
Ranch Hand

Joined: Jul 26, 2011
Posts: 394


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

Joined: Jan 10, 2002
Posts: 60780
    
  65

No. You have two ambiguous meanings of the property set.
H Paul
Ranch Hand

Joined: Jul 26, 2011
Posts: 394
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

Joined: Jan 10, 2002
Posts: 60780
    
  65

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

Joined: Jul 26, 2011
Posts: 394
Mistake corrected and it works. Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSTL over a Set: Did not get data as expected
 
Similar Threads
Retaining value of checkbox when returning back from a servlet
How to use array of beans in jsp
create one checkbox per row for the JSP table
check boxes retrieving problem
Jstl not reflecting values back to servlet