What you are saying when you post user.group.id = '' is to set the group object of the user id property to null. What you want to say is set user.group to null.

To do that create a TypeConverter for Group rather than try to maintain the id directly. This way when the id (String representation of Group) is passed from the post you can test it for null and either return the group object you looked up or a null. Then you just register the type converter in xwork-conversion.properties.

Then your field is just user.group rather than user.group.id.

-D

public class GroupConverter extends DefaultTypeConverter {


    public Object convertValue(Map map, Object object, Class aClass) {
        if (aClass == Group.class) {
                Group source = (Group)object;
                return source.getId();
        } else if (aClass == String.class) {
            String id  = (String)object;
            if(id == null || "".equals(object)_
                        return null
            else
return groupDao.find(object); //maybe you have to cast to a Long instead of a String. Maybe your DAO returns a null if it can't find the group or if it gets a null or blank id. Then you just need the dao lookup.
        }
        return null;
    }
}


On Aug 21, 2008, at 6:30 AM, Stephan Schröder wrote:


Can you define an interface that is common across all the actions/ model objects. Then you can have the relevant Actions implement the interface
and
write an interceptor to check the value of the specified fields and set
them
to null if required after checking that the object is of the correct type
(i.e. it implements your interface)

Nice Idea Andy! You don't even need common methods in the interface, it can just bee a signal

interface DomainModelObject{}

than you can have an interceptor

public class CleanerInterceptor extends AbstractInterceptor {

public String intercept(ActionInvocation invocation) throws Exception {
   Object action = invocation.getAction();
   if( action instanceof ModelDriven ) {
     Object model = ((ModelDriven)action).getModel();
//if the model is instance of DomainModelObject clean all of its properties
     if( model instanceof DomainModelObject ) {
       DomainModelObject modelObject = (DomainModelObject)model;
Collection<DomainObjectModel> properties = getProperties( modelObject );
       for( DomainObjectModel property:properties ) {
         cleanProperty( modelObject ,property );
       }
     }
   }
   invocation.invoke();
 }

private void cleanProperty( DomainObjectModel parent, DomainObjectModel model )
 {
   if( model==null ) return;

   Collection<DomainObjectModel> properties = getProperties( model );

   if( allPropertiesNull( properties ) ) {
     setPropertyNullOnParent( parent,model );
   }else{
     for( DomainObjectModel property:properties ) {
       cleanProperty( model,property );
     }
   }

private Collection<DomainObjectModel> getProperties( DomainObjectModel model )
 {...
 }

private void setPropertyNullOnParent( DomainObjectModel parent, DomainObjectModel model )
 {...
 }

private boolean allPropertiesNull( Collection<DomainObjectModel> properties )
 {
   for( DomainObjectModel property:properties ) {
     if( property!=null ) return false;
   }
   return true;
 }
}

getProperties(...) and setPropertyNullOnParent(...) can both be programmed using Java Reflection and if you don't like DomainObjectModel being an Interface you can make it an annotation. Then cleaner-Interceptor shoulb probably called last on you interceptorstack.

/Stephan
--
GMX Kostenlose Spiele: Einfach online spielen und Spaß haben mit Pastry Passion!
http://games.entertainment.gmx.net/de/entertainment/games/free/puzzle/6169196

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to