We help IT Professionals succeed at work.

How to create sub properties within a Bean??

drodalejo
drodalejo asked
on
Medium Priority
249 Views
Last Modified: 2013-11-21
I have been looking for some info about this topic but still nothing. I'm creating a JavaBean with two properties but one of them depends on the other one, so if the first one has a value 'false' the other one should be disabled but the problem is that i don't know how to do that!!! Since I'm using Sun One IDE i have notice that for example, when you create a JForm, within the properties sheet, into the Code tab, if I change the form size policy, some extra properties appear, so I guess it can be done for any other property, like a enable/disable, but as I mentioned I don't know how to do it. Can someone give some help, give one example, or put me in the right direction at least???
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016

Commented:
Maybe they're properties just setting other properties when a PropertyChangeListener fires?

Commented:
propertyA with values a,b,c,d
propertyB with values true or false (true if propertyA is a or b, false otherwise)

Your bean code could be like:
getPropertyA(){
return propertyA;
}

getPropertyB(){
if (propertyA==a || propertyA==b) return true;
return false;
}

On the client side you must follow what CEHJ told before. Here is an example:
http://www.javaworld.com/javaworld/jw-06-1998/jw-06-beans-p3.html

Bye, Giant.

Author

Commented:
Ok guys! I appreciate your interest in my problem, so i'm going to use the example gived by Giant to illustrate what I have. As in the example, I have:

propertyA with values a, b, c, d
propertyB with valules true or false

(if propertyA is a or b, propertyB could be true or false, but if propertyA is c or d, propertyB must be false)

so, in order to do this,

propertyA fires a propertyChange
propertyB fires a vetoableChange

i have the listeners and the needen code to handle each event; i have created my bean and when I test it into the beanbox everything is fine, I mean:

a) if propertyA is a or b i can change propertyB to false or true
b) if propertyB is false and propertyA is c or d, i cannot change propertyB to true (it's vetoed)
c) if propertyB is true and propertyA is a or b, but I change propertyA to c or d, automatically propertyB change to false (as expected) due to the propertyChange used

in conclusion, everything works as I wish. the problem is that when I load my bean into Sun One 4 or Java Studio 8 i get a different behaviour, i mean:

a) if propertyA is a or b i can change propertyB to false or true
b) if propertyB is false and propertyA is c or d, i cannot change propertyB to true (it's vetoed)

BUT....

c) if propertyB is true and propertyA is a or b, but I change propertyA to c or d, propertyB doesn't change to false or at least this new value is not reflected into the properties view.

Any ideas???

Commented:
Seems a refresh problem

Author

Commented:
I'm agree with you because if i click on any other component and then i click again my bean the properties sheet displays the correct values for the two properties...

So, is there a way to programatically refresh the properties sheet?? or am i missing something into my bean??

I have tested my bean with the beanbox and Netbeans getting the desired behaviour, but with SunOne 4 and Java Studio Enterprise 8 i cannot say the same.

Commented:
See here:
http://java.sun.com/docs/books/tutorial/javabeans/properties/constrained.html
at "Write a property's setter method to fire a property change event when the property is changed."

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.