Hi Robert,
Thanks for the reply. I'm heartened that Struts 2 have a live community that
can help with issues. Firstly, yes you are right that I'm using a
ModelDriven.

I have a super class ModelDrivenAction which my other action classes extend
from.

public void prepare() throws Exception {
 super.prepare();
 BaseEntity model = null;
 if (getId() != null) {
 model = (BaseEntity) session.get(getEmbeddedModelKey() + getId());
 if (model == null) model = service.retrieve(modelClass, getId());
 }
 if (model == null && !(this instanceof EmbeddedDrivenAction)) model =
getNewModel();

setModel(model);
 }

I have another class EmbeddedDrivenAction which subclasses
ModelDrivenAction:

public void prepare() throws Exception {
 //call modeldriven's prepare to load in the model
 super.prepare();

if (embeddedModelClass != null)
setEmbeddedModel((IEmbeddable)Class.forName(embeddedModelClass).newInstance());
 Object suffixObj = (getId()!= null?getId():getParentId());
 String suffix = "";
 if (suffixObj != null) suffix = suffixObj.toString();
 String sessionKey = getEmbeddedModelKey() + suffix;
 //for main action, will use id
 if (session.get(sessionKey) == null) { // for main action
 if (getModel() == null) setModel(getNewModel());
 if (!WebUtility.getInstance().isReloadPagePreservingValues(session))
removeSessionObjects();
 session.put(sessionKey, getModel());
 }
 //for embedded action, will use parentid
 else {
 setModel((BaseEntity) session.get(sessionKey));
 }
 }

This is how my model is initialized. It will first check if the model have
been put into the session (I'm using an architecture whereby the user is
using 2 or more screens for the same model object). If eventually the model
is not found, the getNewModel() object will return a newly instantiated
model. In any case, a instantiated model will definitely be returned.

According to my first email, my call chain is "userAddress.country.id". If I
don't remember wrongly, if my userAddress is null, Struts will initialize it
for me. If my country is null, Struts will also initialize it for me. After
both are initialized, the ID is set. In all cases, Struts will initialize
the objects in the chain and apply the final value. Pls correct me if I'm
wrong here.

For point 3, what do you mean by "not ok"? Pls elaborate on that if
possible.

My model class code is a regular POJO:


public class UserAccountAddress extends
sg.com.stellar.ecomm.royalefam.entity.BaseEntity implements
java.io.Serializable, IEmbeddable {

// Fields

private Integer id;

private UserAccount userAccount;

private Country country; *//getters and setters have been set*

...
}

Thanks in advance for any help rendered!

Regards.
W.SayJon

Email Disclaimer:
The information contained in or attached to this email is confidential and
solely for the use of the individual or entity to whom it is addressed.
If you are not the intended recipient, please notify the sender immediately
and delete any copies of this email.
Any unauthorised disclosure, copying, distribution or any action taken in
reliance on the contents of this information is strictly prohibited and may
be unlawful.


On Wed, Jul 15, 2009 at 9:57 PM, Robert Graf-Waczenski <r...@lsoft.com>wrote:

> Even though you are pretty vague in what you write below, i have a few
> pointers for you:
>
> 1) Check (and tell us) if you designed your action implements the
> ModelDriven interface (guessed from you talking about getModel() below)
> 2) Maybe your getModel() returns an improperly initialized instance when it
> is called several times. If the call chain you quote below somewhere yields
> a null value, Struts2 is incapable of applying your parameter value because
> it does not have an instance to set the value at.
> 3) The fact that the problem goes away when you restart Tomcat indicates
> that the getModel() return value depends on the user's session and maybe the
> value is ok when the session is fresh and the value is not ok when you call
> your action repeatedly. (Again, guesswork here...)
>
> Quoting your action source code and your model class source code would help
> us helping you.
>
> Robert
>
> Say Jon schrieb:
>
>  Hi all,
>> I have been using Struts 2 for a while now and I am pulling my hair over
>> the
>> following issue. At times, when my parameter name contains a period, the
>> Parameterinterceptor doesn't seem to be applied properly. For example I
>> have
>> a parameter "userAddress.country.id" which points to
>> getModel().getUserAddress().getCountry().setId() right? This works most of
>> the time but occasionally, the value doesn't get set. I know this because
>> my
>> validation keeps denying the user saying that "Country is required" when
>> the
>> user have indeed chosen a country (problem because the parameter is not
>> applied properly). The problem goes away when I restart Tomcat.
>>
>> Anyone facing the same problem? I'm using Struts 2.1.6 by the way.
>>
>> Regards.
>> W.SayJon
>>
>> Email Disclaimer:
>> The information contained in or attached to this email is confidential and
>> solely for the use of the individual or entity to whom it is addressed.
>> If you are not the intended recipient, please notify the sender
>> immediately
>> and delete any copies of this email.
>> Any unauthorised disclosure, copying, distribution or any action taken in
>> reliance on the contents of this information is strictly prohibited and
>> may
>> be unlawful.
>>
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
>
>

Reply via email to