Author Login
Post Reply
user Digest 16 Jul 2009 08:52:02 -0000 Issue 8754
Topics (messages 200763 through 200779):
Re: Initializing Application
200763 by: Pawe³ Wielgus
200768 by: Balwinder Kumar
Need to update one single field via Ajax
200764 by: Bruno
Re: how to configure struts2 for /*.action?
200765 by: Dave Newton
200766 by: Martin Gainty
200767 by: Struts Two
200771 by: ravi_eze
Re: Struts2 Action Class and EJB Injection
200769 by: Robin Mannering
org.apache.jasper.JasperException: The Struts dispatcher cannot be found.
200770 by: jayadevan
200772 by: Lukasz Lenart
200773 by: jayadevan
200774 by: Lukasz Lenart
200776 by: jayadevan
200777 by: jayadevan
Re: ParameterInterceptor problem
200775 by: Say Jon
200778 by: Robert Graf-Waczenski
200779 by: Say Jon
Administrivia:
---------------------------------------------------------------------
To post to the list, e-mail: user@(protected)
To unsubscribe, e-mail: user-digest-unsubscribe@(protected)
For additional commands, e-mail: user-digest-help@(protected)
----------------------------------------------------------------------

Attachment:
user_200763.ezm (zipped)Hi,
i'm initing my apps by implementing ServletContextListener and
registering it in web.xml like that:
<web-app>
<listener>
<listener-class>com.my.ServletContextListenerImplementation</listener-class>
</listener>
</web-app>
It has nothing to do with struts but i hope that's what You are looking for.
Best greetings,
Paweł Wielgus.
2009/7/15 David Canos <davidcanos@(protected)>:
> I think Struts 2 uses a Struts2Filter to do the init issues of the each
> request
>
> 2009/7/15 Balwinder Kumar <balwinder.mca@(protected)>
>
>> Hi All,
>>
>> I am trying to develop a framework based on Struts 2, I am finding it very
>> difficult to decide where to put the code that is generally called in
>> ActionServlet init method. Any pointer towards this.
>> Thanks in advance.
>>
>> Regards,
>> Balwinder Kumar
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@(protected)
>> For additional commands, e-mail: user-help@(protected)
>>
>>
>

Attachment:
user_200768.ezm (zipped)Thanks Pawel and David for your response. I would like to evaluate both
option before proceeding.
Regards,
Balwinder Kumar
Paweł Wielgus wrote:
> Hi,
> i'm initing my apps by implementing ServletContextListener and
> registering it in web.xml like that:
> <web-app>
> <listener>
> <listener-class>com.my.ServletContextListenerImplementation</listener-class>
> </listener>
> </web-app>
>
> It has nothing to do with struts but i hope that's what You are looking for.
>
> Best greetings,
> Paweł Wielgus.
>
>
> 2009/7/15 David Canos <davidcanos@(protected)>:
>
>> I think Struts 2 uses a Struts2Filter to do the init issues of the each
>> request
>>
>> 2009/7/15 Balwinder Kumar <balwinder.mca@(protected)>
>>
>>
>>> Hi All,
>>>
>>> I am trying to develop a framework based on Struts 2, I am finding it very
>>> difficult to decide where to put the code that is generally called in
>>> ActionServlet init method. Any pointer towards this.
>>> Thanks in advance.
>>>
>>> Regards,
>>> Balwinder Kumar
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@(protected)
>>> For additional commands, e-mail: user-help@(protected)
>>>
>>>
>>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>
>

Attachment:
user_200764.ezm (zipped)Hey guys, I'm using Struts 2.1.6 with Spring...
I've always used <sx:div> for auto refresh, whenever is necessary, but I now
I need to keep updated one single field and I'm not allowed to use sx:div
with updateFreq
So I'll have to make it all manually using JavaScript. The problem is that I
simply don't know how to do it. Any suggestions?
Thanks
--
Bruno Morelli Vargas
Mail: brunomv@(protected)
Msn: brunom_@(protected)
Icq: 165055101
Skype: morellibmv

Attachment:
user_200765.ezm (zipped)ravi_eze wrote:
> We are not serving static content.
Not *you*, *Struts 2*.
> What will happen if i do *.action?
> Why did the doc say /* *should* be in web.xml?
Because of what you've already been told a couple of times now.
Dave

Attachment:
user_200766.ezm (zipped)look at a working example.. showcase contain these *.action entries in /WEB-INF/web.xml
<servlet>
<servlet-name>faces</servlet-name>
<servlet-class>
javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>JspSupportServlet</servlet-name>
<servlet-class>
org.apache.struts2.views.JspSupportServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- JavaServer Faces Servlet Mapping, not called directly -->
<servlet-mapping>
<servlet-name>faces</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
Martin
______________________________________________
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.
> Date: Wed, 15 Jul 2009 16:29:04 -0400
> From: newton.dave@(protected)
> To: user@(protected)
> Subject: Re: how to configure struts2 for /*.action?
>
> ravi_eze wrote:
> > We are not serving static content.
>
> Not *you*, *Struts 2*.
>
> > What will happen if i do *.action?
> > Why did the doc say /* *should* be in web.xml?
>
> Because of what you've already been told a couple of times now.
>
> Dave
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
_________________________________________________________________
Hotmail® has ever-growing storage! Don’t worry about storage limits.
http://windowslive.com/Tutorial/Hotmail/Storage?ocid=TXT_TAGLM_WL_HM_Tutorial_Storage_062009

Attachment:
user_200767.ezm (zipped)Just keep in mind by setting /*.action for your struts filter url, you may cause yourself some problems down the road depending on the app server you use, as struts 2 is not following servlet 2.4 spec in this regard. filters are not supposed to be accessed directly as a resource according to the spec.
I myself have been experiencing some issues for a similar case like this one and had to resort various hacks to get around it.
--- On Wed, 7/15/09, Martin Gainty <mgainty@(protected):
> From: Martin Gainty <mgainty@(protected)>
> Subject: RE: how to configure struts2 for /*.action?
> To: "Struts Users Mailing List" <user@(protected)>
> Received: Wednesday, July 15, 2009, 9:21 PM
>
> look at a working example.. showcase contain these *.action
> entries in /WEB-INF/web.xml
>
> <servlet>
>
> <servlet-name>faces</servlet-name>
>
> <servlet-class>
javax.faces.webapp.FacesServlet</servlet-class>
>
> <load-on-startup>1</load-on-startup>
> </servlet>
> <servlet>
>
> <servlet-name>JspSupportServlet</servlet-name>
>
> <servlet-class>
org.apache.struts2.views.JspSupportServlet</servlet-class>
>
> <load-on-startup>1</load-on-startup>
> </servlet>
>
> <!-- JavaServer Faces Servlet
> Mapping, not called directly -->
> <servlet-mapping>
>
> <servlet-name>faces</servlet-name>
>
> <url-pattern>*.action</url-pattern>
> </servlet-mapping>
>
> Martin
> ______________________________________________
> Verzicht und Vertraulichkeitanmerkung/Note de déni et de
> confidentialité
>
> Diese Nachricht ist vertraulich. Sollten Sie nicht der
> vorgesehene Empfaenger sein, so bitten wir hoeflich um eine
> Mitteilung. Jede unbefugte Weiterleitung oder Fertigung
> einer Kopie ist unzulaessig. Diese Nachricht dient lediglich
> dem Austausch von Informationen und entfaltet keine
> rechtliche Bindungswirkung. Aufgrund der leichten
> Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer
> den Inhalt uebernehmen.
> Ce message est confidentiel et peut être privilégié. Si
> vous n'êtes pas le destinataire prévu, nous te demandons
> avec bonté que pour satisfaire informez l'expéditeur.
> N'importe quelle diffusion non autorisée ou la copie de
> ceci est interdite. Ce message sert à l'information
> seulement et n'aura pas n'importe quel effet légalement
> obligatoire. Étant donné que les email peuvent facilement
> être sujets à la manipulation, nous ne pouvons accepter
> aucune responsabilité pour le contenu fourni.
>
>
>
>
> > Date: Wed, 15 Jul 2009 16:29:04 -0400
> > From: newton.dave@(protected)
> > To: user@(protected)
> > Subject: Re: how to configure struts2 for /*.action?
> >
> > ravi_eze wrote:
> > > We are not serving static content.
> >
> > Not *you*, *Struts 2*.
> >
> > > What will happen if i do *.action?
> > > Why did the doc say /* *should* be in web.xml?
> >
> > Because of what you've already been told a couple of
> times now.
> >
> > Dave
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@(protected)
> > For additional commands, e-mail: user-help@(protected)
> >
>
> _________________________________________________________________
> Hotmail® has ever-growing storage! Don’t worry about
> storage limits.
> http://windowslive.com/Tutorial/Hotmail/Storage?ocid=TXT_TAGLM_WL_HM_Tutorial_Storage_062009
__________________________________________________________________
Ask a question on any topic and get answers from real people. Go to Yahoo! Answers and share what you know at http://ca.answers.yahoo.com

Attachment:
user_200771.ezm (zipped)
hi,
can you give some exampels for which u had to put hacks? We will test those
parts explicitly.
--
ravi
--
Sent from the Struts - User mailing list archive at Nabble.com.

Attachment:
user_200769.ezm (zipped)Thanks for the example. I shall download the source and give it a go.
Thanks again.
Nathan Schulte wrote:
> Robin Mannering <robin <at> mtndesigns.co.uk> writes:
>
>> Can you please tell me how you obtained the EJB plugin and a short
>> example of using it.
>>
>> I would prefer to use this if possible.
>>
>
> Sorr, I misspoke earlier. I'm actually using the EJB3 JBoss Plugin, from here
> http://cwiki.apache.org/S2PLUGINS/ejb3-jboss-plugin.html.
>
> However, browsing the source for the EJB3 Plugin, the annotations and even
> classes are named the same, so the following example should still apply;
> http://pastebin.com/f7053a2bc.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 8.5.387 / Virus Database: 270.13.14/2238 - Release Date: 07/14/09 18:03:00
>
>

Attachment:
user_200770.ezm (zipped)
Attachment:
user_200772.ezm (zipped)Could you show your web.xml?
Regards
--
Lukasz
http://www.lenart.org.pl/
http://dailylog.lenart.org.pl/
Lenny Bruce - "Communism is like one big phone company." -
http://www.brainyquote.com/quotes/authors/l/lenny_bruce.html

Attachment:
user_200773.ezm (zipped)hi
my web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>strutsExample</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
Lukasz Lenart wrote:
>
> Could you show your web.xml?
>
>
> Regards
> --
> Lukasz
> http://www.lenart.org.pl/
> http://dailylog.lenart.org.pl/
>
> Lenny Bruce - "Communism is like one big phone company." -
> http://www.brainyquote.com/quotes/authors/l/lenny_bruce.html
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>
>
--
Sent from the Struts - User mailing list archive at Nabble.com.

Attachment:
user_200774.ezm (zipped)It's ok, when you got that exception? What url were you entering in
web browser? It looks like you went directly to jsp.
Regards
--
Lukasz
http://www.lenart.org.pl/
http://dailylog.lenart.org.pl/
Timothy Leary - "Women who seek to be equal with men lack ambition."
- http://www.brainyquote.com/quotes/authors/t/timothy_leary.html

Attachment:
user_200776.ezm (zipped)
i tried both way
directly
and step by step
Lukasz Lenart wrote:
>
> It's ok, when you got that exception? What url were you entering in
> web browser? It looks like you went directly to jsp.
>
>
> Regards
> --
> Lukasz
> http://www.lenart.org.pl/
> http://dailylog.lenart.org.pl/
>
> Timothy Leary - "Women who seek to be equal with men lack ambition."
> - http://www.brainyquote.com/quotes/authors/t/timothy_leary.html
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>
>
--
Sent from the Struts - User mailing list archive at Nabble.com.

Attachment:
user_200777.ezm (zipped)
my index.jsp like this
<%@(protected)"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@(protected)" %>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<s:form action="HelloWorld" >
<s:textfield name="userName" label="User Name" />
<s:submit />
</s:form>
</body>
</html>
where i place "struts-tags.xml " ?
jayadevan wrote:
>
> i tried both way
> directly
> and step by step
>
>
> Lukasz Lenart wrote:
>>
>> It's ok, when you got that exception? What url were you entering in
>> web browser? It looks like you went directly to jsp.
>>
>>
>> Regards
>> --
>> Lukasz
>> http://www.lenart.org.pl/
>> http://dailylog.lenart.org.pl/
>>
>> Timothy Leary - "Women who seek to be equal with men lack ambition."
>> - http://www.brainyquote.com/quotes/authors/t/timothy_leary.html
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@(protected)
>> For additional commands, e-mail: user-help@(protected)
>>
>>
>>
>
>
--
Sent from the Struts - User mailing list archive at Nabble.com.

Attachment:
user_200775.ezm (zipped)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 <rgw@(protected):
> 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-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>

Attachment:
user_200778.ezm (zipped)Say Jon schrieb:
> 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);
> }
>
This code does not look particularly wrong. It does what we also do
frequently (without the service.retrieve() part and without the user
using several sessions for his work). So i guess that your problem is
not located here.
> 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.
>
I didn't check (and in fact, not completely understand) your code above,
but i think you should investigate a bit further into the area below:
> 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.
>
I can't tell you off the top of my head, but i'd suggest to verify your
assumption with the debugger. If your assumption is correct, theny you
should see calls to getUserAddress(), getCountry() and getId(). We here
in our application frequently use nested instances and we always make
sure that anything that is necessary for such a call chain is
initialized properly by our own code. My strong guess is that Struts
does not initalize the objects for you. (And, btw, even if it did: How
would your container class obtain the correct reference to the object
created for you by Struts?) And how would the ultimate setter be then
called on an instance that is referenced from the object at the start of
your call chain? Try to use lazy initialization and reference
bookkeeping when your getter method is accessed and you find your local
member variable pointer null.
> For point 3, what do you mean by "not ok"? Pls elaborate on that if
> possible.
>
By "not ok" i meant that your parent object does not have all its child
objects correctly initialized so that when Struts calls along your
object nesting chain, it encounters null return values and either has to
deal with NPEs or (if your guess that it initializes objects on the fly
which i'm still a bit unsure about) it creates new instances that only
live in the nether outside of your original object. So if you later need
to query the value of an object further down the call chain, all parent
objects need correct references to the child objects. I'm not aware of
any mechanism in Struts to establish such a proper reference chain for
you, so you need to make sure that is exists before Struts comes into play.
The behavior you describe hints that your reference chain somehow gets
broken during the lifetime of your model object so that your call chains
don't work correctly anymore.
Robert

Attachment:
user_200779.ezm (zipped)Thanks Robert for your inputs.
Well I'm sure that Struts does initialize all null objects along the object
chain if they are null, because for 90% of the time, this works. I do not
explicitly initialize objects along the object chain in my code. For most of
the time, Struts detects that it is null and therefore initializes it for me
till the final property which it sets properly.
As mentioned this problem occurs intermittently and its so frustrating for
apps that are in production because of its unpredictability. I will follow
your advice to initialize all objects in the object chain and see if it
helps.
Thanks for your help!
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 Thu, Jul 16, 2009 at 3:47 PM, Robert Graf-Waczenski <rgw@(protected):
> Say Jon schrieb:
>
>> 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);
>> }
>>
>>
>
> This code does not look particularly wrong. It does what we also do
> frequently (without the service.retrieve() part and without the user using
> several sessions for his work). So i guess that your problem is not located
> here.
>
>
> 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.
>>
>>
>
> I didn't check (and in fact, not completely understand) your code above,
> but i think you should investigate a bit further into the area below:
>
>> 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.
>>
>>
>
> I can't tell you off the top of my head, but i'd suggest to verify your
> assumption with the debugger. If your assumption is correct, theny you
> should see calls to getUserAddress(), getCountry() and getId(). We here in
> our application frequently use nested instances and we always make sure that
> anything that is necessary for such a call chain is initialized properly by
> our own code. My strong guess is that Struts does not initalize the objects
> for you. (And, btw, even if it did: How would your container class obtain
> the correct reference to the object created for you by Struts?) And how
> would the ultimate setter be then called on an instance that is referenced
> from the object at the start of your call chain? Try to use lazy
> initialization and reference bookkeeping when your getter method is accessed
> and you find your local member variable pointer null.
>
>> For point 3, what do you mean by "not ok"? Pls elaborate on that if
>> possible.
>>
>>
>
> By "not ok" i meant that your parent object does not have all its child
> objects correctly initialized so that when Struts calls along your object
> nesting chain, it encounters null return values and either has to deal with
> NPEs or (if your guess that it initializes objects on the fly which i'm
> still a bit unsure about) it creates new instances that only live in the
> nether outside of your original object. So if you later need to query the
> value of an object further down the call chain, all parent objects need
> correct references to the child objects. I'm not aware of any mechanism in
> Struts to establish such a proper reference chain for you, so you need to
> make sure that is exists before Struts comes into play.
>
> The behavior you describe hints that your reference chain somehow gets
> broken during the lifetime of your model object so that your call chains
> don't work correctly anymore.
>
> Robert
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>