You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by red phoenix <ro...@gmail.com> on 2007/08/16 04:12:08 UTC
How to make initialize with struts2 action?
For general Java class,we can make construction function,like this:
public class test{
String a;
public test(String a){
this.a=a;
}
}
I don't know if I can do it like above code under struts2 action,for some
reason,I want to initialize some variable and assign some value to it,like
follows:
public class MyClass extends ActionSupport{
private ....;
public MyClass(SomeType s){
//make some common operaction,such get session and so on,because I
want to run them only once
}
public String execute() throws Exception {
....
}
public String .....{
}
...
}
I can successly compile above code,but when I run above code,it will say
error:
1)MyClass action error
2)java.lang.NullException because some code in MyClass(SomeType s)
When I remove the code in the MyClass(SomeType s) into execute() function,it
can run well. I am puzzle with it! Anybody could tell me how to do it? An
example is better.
Thanks,
phoenix
Re: How to make initialize with struts2 action?
Posted by Andvar Woo <an...@gmail.com>.
I tested it,it works fine. Note that static block can only refer to static
fields and static methods
Don't put the static block in any method, just put it alone like a function.
2007/8/16, red phoenix <ro...@gmail.com>:
>
> static
> {
> //doSomeInit,this only run once
> }
>
> above code can't run in struct2 action,it will say "can't use in
> non-static
> class"
>
> I use Struts2+spring2.1+hibernate3.2,I am puzzled with it for many many
> days! I am looking for an example,but I don't find it,would you give me an
> example project which can run under tomcat6?
>
>
> On 8/16/07, Nils-Helge Garli <ni...@gmail.com> wrote:
> >
> > So you're using Spring? In that case, maybe parts of this tutorial can
> > help: http://struts.apache.org/2.x/docs/struts-2-spring-2-jpa-ajax.html
> >
> > And here's the documentation for the Spring-plugin:
> > http://struts.apache.org/2.x/docs/spring-plugin.html
> >
> > Nils-H
> >
> > On 8/16/07, red phoenix <ro...@gmail.com> wrote:
> > > I know your meaning,but the question I want to Initialize in struts
> > > action,not in common class,because I want to get WebApplicationContext
> > in
> > > struts action,and then I will transfer WebApplicationContext into dao
> to
> > get
> > > data. I don't know if there is a init method in struts2 action?
> > > Any idea will be appreciated!
> > >
> > >
> > > On 8/16/07, Leonidas Papadakis <it...@creteonline.gr> wrote:
> > > >
> > > > I think you can use the setters after you initialize your class
> > > > i.e.instead of
> > > > MyType mt = new MyType(...parameters.......);
> > > > to do :
> > > > MyType mt = new MyType();
> > > > mt.setParam1()....
> > > > e.t.c. I am not exactly sure if this is what you are after
> though....
> > > > Why do you want to do this ?
> > > >
> > > > Leon
> > > >
> > > > red phoenix wrote:
> > > > > If I use no-argument constructor,how can i do to initialize some
> > > > > information?
> > > > > Thanks
> > > > >
> > > > >
> > > > > On 8/16/07, Rec Floyd <re...@gmail.com> wrote:
> > > > >
> > > > >> Hey,red.In my opinion, to use struts, you have to supply a
> > no-argument
> > > > >> constructor.That is the point.
> > > > >>
> > > > >>
> > ---------------------------------------------------------------------
> > > > >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > > > >> For additional commands, e-mail: user-help@struts.apache.org
> > > > >>
> > > > >>
> > > > >>
> > > > >
> > > > >
> > > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
RE: empty operator
Posted by Al Sutton <al...@alsutton.com>.
I tend to use
empty eq null
To test if it's null and;
empty neq null
For non-null
-----Original Message-----
From: Laszlo Borsos [mailto:bl2006@freemail.hu]
Sent: 16 August 2007 08:04
To: Struts Users Mailing List
Subject: empty operator
In OGNL, how can I assert that a String property is not null or empty?
I would like this functionality:
${!empty bean.string}
kuvera
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
empty operator
Posted by Laszlo Borsos <bl...@freemail.hu>.
In OGNL, how can I assert that a String property is not null or empty?
I would like this functionality:
${!empty bean.string}
kuvera
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: How to make initialize with struts2 action?
Posted by red phoenix <ro...@gmail.com>.
static
{
//doSomeInit,this only run once
}
above code can't run in struct2 action,it will say "can't use in non-static
class"
I use Struts2+spring2.1+hibernate3.2,I am puzzled with it for many many
days! I am looking for an example,but I don't find it,would you give me an
example project which can run under tomcat6?
On 8/16/07, Nils-Helge Garli <ni...@gmail.com> wrote:
>
> So you're using Spring? In that case, maybe parts of this tutorial can
> help: http://struts.apache.org/2.x/docs/struts-2-spring-2-jpa-ajax.html
>
> And here's the documentation for the Spring-plugin:
> http://struts.apache.org/2.x/docs/spring-plugin.html
>
> Nils-H
>
> On 8/16/07, red phoenix <ro...@gmail.com> wrote:
> > I know your meaning,but the question I want to Initialize in struts
> > action,not in common class,because I want to get WebApplicationContext
> in
> > struts action,and then I will transfer WebApplicationContext into dao to
> get
> > data. I don't know if there is a init method in struts2 action?
> > Any idea will be appreciated!
> >
> >
> > On 8/16/07, Leonidas Papadakis <it...@creteonline.gr> wrote:
> > >
> > > I think you can use the setters after you initialize your class
> > > i.e.instead of
> > > MyType mt = new MyType(...parameters.......);
> > > to do :
> > > MyType mt = new MyType();
> > > mt.setParam1()....
> > > e.t.c. I am not exactly sure if this is what you are after though....
> > > Why do you want to do this ?
> > >
> > > Leon
> > >
> > > red phoenix wrote:
> > > > If I use no-argument constructor,how can i do to initialize some
> > > > information?
> > > > Thanks
> > > >
> > > >
> > > > On 8/16/07, Rec Floyd <re...@gmail.com> wrote:
> > > >
> > > >> Hey,red.In my opinion, to use struts, you have to supply a
> no-argument
> > > >> constructor.That is the point.
> > > >>
> > > >>
> ---------------------------------------------------------------------
> > > >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > > >> For additional commands, e-mail: user-help@struts.apache.org
> > > >>
> > > >>
> > > >>
> > > >
> > > >
> > >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
Re: How to make initialize with struts2 action?
Posted by Nils-Helge Garli <ni...@gmail.com>.
So you're using Spring? In that case, maybe parts of this tutorial can
help: http://struts.apache.org/2.x/docs/struts-2-spring-2-jpa-ajax.html
And here's the documentation for the Spring-plugin:
http://struts.apache.org/2.x/docs/spring-plugin.html
Nils-H
On 8/16/07, red phoenix <ro...@gmail.com> wrote:
> I know your meaning,but the question I want to Initialize in struts
> action,not in common class,because I want to get WebApplicationContext in
> struts action,and then I will transfer WebApplicationContext into dao to get
> data. I don't know if there is a init method in struts2 action?
> Any idea will be appreciated!
>
>
> On 8/16/07, Leonidas Papadakis <it...@creteonline.gr> wrote:
> >
> > I think you can use the setters after you initialize your class
> > i.e.instead of
> > MyType mt = new MyType(...parameters.......);
> > to do :
> > MyType mt = new MyType();
> > mt.setParam1()....
> > e.t.c. I am not exactly sure if this is what you are after though....
> > Why do you want to do this ?
> >
> > Leon
> >
> > red phoenix wrote:
> > > If I use no-argument constructor,how can i do to initialize some
> > > information?
> > > Thanks
> > >
> > >
> > > On 8/16/07, Rec Floyd <re...@gmail.com> wrote:
> > >
> > >> Hey,red.In my opinion, to use struts, you have to supply a no-argument
> > >> constructor.That is the point.
> > >>
> > >> ---------------------------------------------------------------------
> > >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > >> For additional commands, e-mail: user-help@struts.apache.org
> > >>
> > >>
> > >>
> > >
> > >
> >
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: How to make initialize with struts2 action?
Posted by Andvar Woo <an...@gmail.com>.
You may try the static block, a no-arg constructor is needed to initialize a
Action object by struts
static
{
//doSomeInit,this only run once
}
2007/8/16, red phoenix <ro...@gmail.com>:
>
> I know your meaning,but the question I want to Initialize in struts
> action,not in common class,because I want to get WebApplicationContext in
> struts action,and then I will transfer WebApplicationContext into dao to
> get
> data. I don't know if there is a init method in struts2 action?
> Any idea will be appreciated!
>
>
> On 8/16/07, Leonidas Papadakis <it...@creteonline.gr> wrote:
> >
> > I think you can use the setters after you initialize your class
> > i.e.instead of
> > MyType mt = new MyType(...parameters.......);
> > to do :
> > MyType mt = new MyType();
> > mt.setParam1()....
> > e.t.c. I am not exactly sure if this is what you are after though....
> > Why do you want to do this ?
> >
> > Leon
> >
> > red phoenix wrote:
> > > If I use no-argument constructor,how can i do to initialize some
> > > information?
> > > Thanks
> > >
> > >
> > > On 8/16/07, Rec Floyd <re...@gmail.com> wrote:
> > >
> > >> Hey,red.In my opinion, to use struts, you have to supply a
> no-argument
> > >> constructor.That is the point.
> > >>
> > >> ---------------------------------------------------------------------
> > >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > >> For additional commands, e-mail: user-help@struts.apache.org
> > >>
> > >>
> > >>
> > >
> > >
> >
>
Re: How to make initialize with struts2 action?
Posted by red phoenix <ro...@gmail.com>.
I know your meaning,but the question I want to Initialize in struts
action,not in common class,because I want to get WebApplicationContext in
struts action,and then I will transfer WebApplicationContext into dao to get
data. I don't know if there is a init method in struts2 action?
Any idea will be appreciated!
On 8/16/07, Leonidas Papadakis <it...@creteonline.gr> wrote:
>
> I think you can use the setters after you initialize your class
> i.e.instead of
> MyType mt = new MyType(...parameters.......);
> to do :
> MyType mt = new MyType();
> mt.setParam1()....
> e.t.c. I am not exactly sure if this is what you are after though....
> Why do you want to do this ?
>
> Leon
>
> red phoenix wrote:
> > If I use no-argument constructor,how can i do to initialize some
> > information?
> > Thanks
> >
> >
> > On 8/16/07, Rec Floyd <re...@gmail.com> wrote:
> >
> >> Hey,red.In my opinion, to use struts, you have to supply a no-argument
> >> constructor.That is the point.
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >>
> >>
> >
> >
>
Re: How to make initialize with struts2 action?
Posted by Leonidas Papadakis <it...@creteonline.gr>.
I think you can use the setters after you initialize your class
i.e.instead of
MyType mt = new MyType(...parameters.......);
to do :
MyType mt = new MyType();
mt.setParam1()....
e.t.c. I am not exactly sure if this is what you are after though....
Why do you want to do this ?
Leon
red phoenix wrote:
> If I use no-argument constructor,how can i do to initialize some
> information?
> Thanks
>
>
> On 8/16/07, Rec Floyd <re...@gmail.com> wrote:
>
>> Hey,red.In my opinion, to use struts, you have to supply a no-argument
>> constructor.That is the point.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>
>
Re: How to make initialize with struts2 action?
Posted by red phoenix <ro...@gmail.com>.
If I use no-argument constructor,how can i do to initialize some
information?
Thanks
On 8/16/07, Rec Floyd <re...@gmail.com> wrote:
>
> Hey,red.In my opinion, to use struts, you have to supply a no-argument
> constructor.That is the point.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
Re: How to make initialize with struts2 action?
Posted by Rec Floyd <re...@gmail.com>.
Hey,red.In my opinion, to use struts, you have to supply a no-argument
constructor.That is the point.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: How to make initialize with struts2 action?
Posted by meisam sarabadani <me...@gmail.com>.
hey
thanks for your help but the thing is that it does not work like that in
eclipse, yeah I have downloaded the full pack of struts and the all
exampels, and also i have deployed it manually by putting it into my
container (tomcat), but when im going to use the eclipse as IDE to develop
and start a struts everything messes and I can`t continue, actually it is
not working, I have seen so many tutorials but none of is 100% sure about
what they are saying, can you help me with this ?
On 8/16/07, Andvar Woo <an...@gmail.com> wrote:
>
> You can refer to the Struts doc.
> The easiest way is to use the struts2-blank-2.0.9.war as a start.
> you can find it from the http://struts.apache.org
> You'd better download a struts-2.x.all.zip from the download pages.
> Hope that helps,good luck.
> 2007/8/16, meisam sarabadani <me...@gmail.com>:
> >
> > Does anybody know how to configure struts on eclipse and build anew
> > project
> > by struts in eclipse ?
> >
> > On 8/16/07, red phoenix <ro...@gmail.com> wrote:
> > >
> > > For general Java class,we can make construction function,like this:
> > > public class test{
> > > String a;
> > > public test(String a){
> > > this.a=a;
> > > }
> > > }
> > >
> > > I don't know if I can do it like above code under struts2 action,for
> > some
> > > reason,I want to initialize some variable and assign some value to
> > it,like
> > > follows:
> > > public class MyClass extends ActionSupport{
> > > private ....;
> > > public MyClass(SomeType s){
> > > //make some common operaction,such get session and so
> on,because
> > I
> > > want to run them only once
> > > }
> > > public String execute() throws Exception {
> > > ....
> > > }
> > > public String .....{
> > > }
> > > ...
> > > }
> > >
> > > I can successly compile above code,but when I run above code,it will
> say
> > > error:
> > > 1)MyClass action error
> > > 2)java.lang.NullException because some code in MyClass(SomeType s)
> > >
> > > When I remove the code in the MyClass(SomeType s) into execute()
> > > function,it
> > > can run well. I am puzzle with it! Anybody could tell me how to do
> > > it? An
> > > example is better.
> > >
> > > Thanks,
> > > phoenix
> > >
> >
> >
> >
> > --
> > Appreciated much,
> >
> > Meisam Sarabadani
> > IBM Student Ambassador
> > Vice president II, IT Society
> > Multimedia University, Cyberjaya Capmus
> > ------------------------------------------------------------------
> > "The day the Lord created hope was probably the same day he created
> > Spring." Bern Williams.
> > ------------------------------------------------------------------
> >
>
--
Appreciated much,
Meisam Sarabadani
IBM Student Ambassador
Vice president II, IT Society
Multimedia University, Cyberjaya Capmus
------------------------------------------------------------------
"The day the Lord created hope was probably the same day he created
Spring." Bern Williams.
------------------------------------------------------------------
Re: How to make initialize with struts2 action?
Posted by Andvar Woo <an...@gmail.com>.
You can refer to the Struts doc.
The easiest way is to use the struts2-blank-2.0.9.war as a start.
you can find it from the http://struts.apache.org
You'd better download a struts-2.x.all.zip from the download pages.
Hope that helps,good luck.
2007/8/16, meisam sarabadani <me...@gmail.com>:
>
> Does anybody know how to configure struts on eclipse and build anew
> project
> by struts in eclipse ?
>
> On 8/16/07, red phoenix <ro...@gmail.com> wrote:
> >
> > For general Java class,we can make construction function,like this:
> > public class test{
> > String a;
> > public test(String a){
> > this.a=a;
> > }
> > }
> >
> > I don't know if I can do it like above code under struts2 action,for
> some
> > reason,I want to initialize some variable and assign some value to
> it,like
> > follows:
> > public class MyClass extends ActionSupport{
> > private ....;
> > public MyClass(SomeType s){
> > //make some common operaction,such get session and so on,because
> I
> > want to run them only once
> > }
> > public String execute() throws Exception {
> > ....
> > }
> > public String .....{
> > }
> > ...
> > }
> >
> > I can successly compile above code,but when I run above code,it will say
> > error:
> > 1)MyClass action error
> > 2)java.lang.NullException because some code in MyClass(SomeType s)
> >
> > When I remove the code in the MyClass(SomeType s) into execute()
> > function,it
> > can run well. I am puzzle with it! Anybody could tell me how to do
> > it? An
> > example is better.
> >
> > Thanks,
> > phoenix
> >
>
>
>
> --
> Appreciated much,
>
> Meisam Sarabadani
> IBM Student Ambassador
> Vice president II, IT Society
> Multimedia University, Cyberjaya Capmus
> ------------------------------------------------------------------
> "The day the Lord created hope was probably the same day he created
> Spring." Bern Williams.
> ------------------------------------------------------------------
>
Re: How to make initialize with struts2 action?
Posted by meisam sarabadani <me...@gmail.com>.
Does anybody know how to configure struts on eclipse and build anew project
by struts in eclipse ?
On 8/16/07, red phoenix <ro...@gmail.com> wrote:
>
> For general Java class,we can make construction function,like this:
> public class test{
> String a;
> public test(String a){
> this.a=a;
> }
> }
>
> I don't know if I can do it like above code under struts2 action,for some
> reason,I want to initialize some variable and assign some value to it,like
> follows:
> public class MyClass extends ActionSupport{
> private ....;
> public MyClass(SomeType s){
> //make some common operaction,such get session and so on,because I
> want to run them only once
> }
> public String execute() throws Exception {
> ....
> }
> public String .....{
> }
> ...
> }
>
> I can successly compile above code,but when I run above code,it will say
> error:
> 1)MyClass action error
> 2)java.lang.NullException because some code in MyClass(SomeType s)
>
> When I remove the code in the MyClass(SomeType s) into execute()
> function,it
> can run well. I am puzzle with it! Anybody could tell me how to do
> it? An
> example is better.
>
> Thanks,
> phoenix
>
--
Appreciated much,
Meisam Sarabadani
IBM Student Ambassador
Vice president II, IT Society
Multimedia University, Cyberjaya Capmus
------------------------------------------------------------------
"The day the Lord created hope was probably the same day he created
Spring." Bern Williams.
------------------------------------------------------------------