Skip to main content



      Home
Home » Archived » Sapphire » What is the difference between "@DependsOn" and "FilteredListener<PropertyContentE
What is the difference between "@DependsOn" and "FilteredListener<PropertyContentE [message #1219505] Wed, 04 December 2013 05:35 Go to next message
Eclipse UserFriend
Hello all Smile I know I'm asking too much Razz Sorry for overhead Very Happy

If Properties A & B & C in Parent Property X have validation services called "A_ValidationService" & "B_ValidationService" & "C_ValidationService". Let's assume that "C_ValidationService" uses values in A & B to validate whether C is correct or not. I knew that to do this, you'll have to do either:

// *** C ***

@Label(standard = "&C")
@XmlBinding ( path = "c" )
@DependsOn(value = { "A", "B", })
ValueProperty PROP_C = new ValueProperty(TYPE, "C");

Value<String> getC();

void setC(String value);


or

public final class C_ValidationService extends ValidationService{

	@Override
	protected void initValidationService()
	{
		final Listener listener = new FilteredListener<PropertyContentEvent>(){
			@Override
			protected void handleTypedEvent( final PropertyContentEvent event )
			{
				broadcast();
			}
		};

		final X propX = context( X.class );

		propX.getA().attach(listener);
		propX.getB().attach(listener);
	}

        @Override
	protected Status compute() 
	{
           ...
	}
}


What is the difference? Are there any other ways to set dependencies?

By the way, I'm using Sapphire 0.7 Build #417

[Updated on: Wed, 04 December 2013 05:41] by Moderator

Re: What is the difference between "@DependsOn" and "FilteredListener<PropertyCont [message #1219515 is a reply to message #1219505] Wed, 04 December 2013 06:35 Go to previous messageGo to next message
Eclipse UserFriend
@DependsOn is being slowly phased out. It has the effect of calling refresh() on the property when a dependency changes. For performance reasons, this may not actually refresh result of a particular service, since many services cache their results. As of 0.7, this is true of ValidationService, so you cannot use @DependsOn to update the validation results. The listener pattern within the service is what you must use. Note that when you receive event, you want to call refresh(), not broadcast() in this case.
Re: What is the difference between "@DependsOn" and "FilteredListener<PropertyCont [message #1219525 is a reply to message #1219515] Wed, 04 December 2013 07:07 Go to previous messageGo to next message
Eclipse UserFriend
In my case, I want when any of A, B, or C changes, all of them get re-validated. So, I did the following:

@Override
protected void initValidationService()
{
	final Listener listener = new FilteredListener<PropertyContentEvent>(){
		@Override
		protected void handleTypedEvent( final PropertyContentEvent event )
		{
			refresh();
		}
	};

	final X prop_X = context( X.class );
	for(Property property:prop_X.properties()){
		property.attach(listener);
	}
}


This should do .. Right?
Well, sometimes it does, and sometimes not! Sometimes I change A, then B & C get re-validated. Sometimes I change B, and only A gets re-validated!! Do you know any possible reasons for such strange behavior?
Re: What is the difference between "@DependsOn" and "FilteredListener<PropertyCont [message #1219558 is a reply to message #1219525] Wed, 04 December 2013 10:51 Go to previous message
Eclipse UserFriend
That looks fine. I don't know what could be causing the behavior that you are describing. You will have to debug.
Previous Topic:Include Params behavior/useage
Next Topic:Problem with DefinitionLoader since Sapphire 0.7 Build #418
Goto Forum:
  


Current Time: Thu May 15 10:03:21 EDT 2025

Powered by FUDForum. Page generated in 0.04544 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top