> This is pretty much what I was looking to do, except that I was hoping
> struts2 could automatically remove an object if *all* of it's properties were
> null, not just one. Would your answer be the same given this minor
> difference?

This is actually not a question whether struts2 can do but whether OGNL can do 
it. OGNL is the expression language that struts 2 uses to navigate the object 
network.
-Maybe it works if you write your own OGNL PropertyAccessor 
(http://www.opensymphony.com/ognl/html/DeveloperGuide/propertyAccessors.html).
-I read that struts 2.1 will make the Expression Language plugable. Maybe 
different language works your way or is more easily extendable.

But booth these solutions are nontrivial. Maybe there is a better way hidden in 
the OGNL Documentaion:

Language Guide: http://www.opensymphony.com/ognl/html/LanguageGuide/index.html
Developer Guide: http://www.opensymphony.com/ognl/html/DeveloperGuide/index.html

/Stephan


-------- Original-Nachricht --------
> Datum: Thu, 21 Aug 2008 11:36:47 +0100
> Von: "Gawain Hammond" <[EMAIL PROTECTED]>
> An: "Struts Users Mailing List" <user@struts.apache.org>
> Betreff: RE: [S2] Does struts set null values for pojo fields?

> Thanks very much for your reply.
> 
> The problem with this type of work around is that it completely messes up
> my fiendish master plan. If it wasn't for those pesky objects with null
> values! :-P
> 
> You see, I've probably been a bit too clever for my own good, and for the
> first time I've created a single action, a single service, and single dao
> to persist objects submitted from multiple struts forms. I'm currently
> persisting about 20 domain objects this way, and this is the last issue I need
> to solve to get it all working as desired.
> 
> This issue is a pretty common occurrence in my domain model, so I'd have
> to write code to check for null values in many places for every domain
> object. I've been thinking this problem would be best solved either in the
> struts/view layer, or maybe the persistence layer. I'm spreading myself a bit
> thin trying to work it out at both ends at the same time :-)
> 
> If you don't mind, I have one last question: You said:
> 
> "I think you cann't expect Struts 2 to automatically remove an object just
> because one of it's properties is set to null."
> 
> This is pretty much what I was looking to do, except that I was hoping
> struts2 could automatically remove an object if *all* of it's properties were
> null, not just one. Would your answer be the same given this minor
> difference?
> 
> 
> 
> -----Original Message-----
> From: "Stephan Schröder" [mailto:[EMAIL PROTECTED] 
> Sent: 21 August 2008 09:10
> To: Struts Users Mailing List
> Subject: Re: [S2] Does struts set null values for pojo fields?
> 
> I think you cann't expect Struts 2 to automatically remove an object just
> because one of it's properties is set to null. Ok, in your case it's the
> id-property but struts 2 (or better OGNL) doesn't know that.
> So i don't think this is worth a feature request.
> But here is the workaround i'd use:
> use the prepare-Interceptor after params and set group to null if the ID
> is null in the prepare method. That way the execute method stays a simple
> "persist( user );return SUCCESS;".
> 
> /Stephan
> 
> > <s:select label="Group" headerKey=""
> > headerValue="-- None --"
> > name="user.group.id"
> > value="%{user.group.id}"
> > list="%{#groupAction.list}"
> > listKey="id" listValue="name"
> > />
> > 
> > 
> > Does anyone know if this can be done? Can I configure struts to set
> > user.group as null rather than create an empty Group object if no
> > id/value has been specified in the drop down select box?
> > 
> > Is this something that is working as desired, and I'm the one who needs
> > to change? Or does struts maybe needs a new feature request in jira?
> -- 
> Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten 
> Browser-Versionen downloaden: http://www.gmx.net/de/go/browser
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> ----------------------------------------------------------
> This transmission is strictly confidential, possibly legally privileged,
> and intended solely for the 
> addressee.  Any views or opinions expressed within it are those of the
> author and do not necessarily 
> represent those of 192.com, i-CD Publishing (UK) Ltd or any of it's
> subsidiary companies.  If you 
> are not the intended recipient then you must not disclose, copy or take
> any action in reliance of this 
> transmission. If you have received this transmission in error, please
> notify the sender as soon as 
> possible.  No employee or agent is authorised to conclude any binding
> agreement on behalf of 
> i-CD Publishing (UK) Ltd with another party by email without express
> written confirmation by an 
> authorised employee of the Company. http://www.192.com (Tel: 08000 192
> 192).  i-CD Publishing (UK) Ltd 
> is incorporated in England and Wales, company number 3148549, VAT No. GB
> 673128728.

-- 
Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten 
Browser-Versionen downloaden: http://www.gmx.net/de/go/browser

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

Reply via email to