Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

How to create sub properties within a Bean??

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???
0
drodalejo
Asked:
drodalejo
  • 3
  • 2
1 Solution
 
CEHJCommented:
Maybe they're properties just setting other properties when a PropertyChangeListener fires?
0
 
Giant2Commented:
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.
0
 
drodalejoAuthor 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???
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Giant2Commented:
Seems a refresh problem
0
 
drodalejoAuthor 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.

0
 
Giant2Commented:
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."
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now