You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by maven apache <ap...@gmail.com> on 2010/11/05 09:33:28 UTC

how does the namespace work in struts

I meet some problem when I try to learn the namespace of struts2,I am using
struts-2.2.1.

After read the docs at:
http://struts.apache.org/2.2.1/docs/namespace-configuration.html

I am confused for the following reason:

The example:

<package name="default">

    <action name="foo" class="mypackage.simpleAction">

        <result name="success" type="dispatcher">greeting.jsp</result>

    </action>

    <action name="bar" class="mypackage.simpleAction">

        <result name="success" type="dispatcher">bar1.jsp</result>

    </action>
</package>

<package name="mypackage1" namespace="/">

    <action name="moo" class="mypackage.simpleAction">

        <result name="success" type="dispatcher">moo.jsp</result>

    </action>
</package>

<package name="mypackage2" namespace="/barspace">

    <action name="bar" class="mypackage.simpleAction">

        <result name="success" type="dispatcher">bar2.jsp</result>

    </action>
</package>

This is the explanation:

*If a request is made to /barspace/foo.action, the namespace /barspace will
be checked for action foo. If a local action is not found, the default
namespace is checked. In the Namespace Example, there is no action foo in
the namespace /barspace, therefore the default will be checked and
/foo.action will be executed.*

I wonder why it is '/foo.action' rather than 'foo.action",it said that it
will find the foo.action at the default namespace,and the default namespace
is "",so it should be foo.action,why there is a '/'??

ALso problem 2:

*Namespace are not hierarchical like a file system path. There is one
namespace level. For example if the URL /barspace/myspace/bar.action is
requested, the framework will first look for namespace /barspace/myspace.*

For the request url "/barspace/myspace/bar.action", the '/barspace/myspace'
will be splitted as a namespace,so what is the action now? is it the
"/bar.action" or "bar.action",since the "/" may stand for a root namespace.

I am really confused,anyone can give me a detailed suggestion??


 so I do some test:

This is the struture of my test project:

Struts_TestProject
----WebContent
--------js(floder)
--------jsp()
------------reg.jsp
------------thank.jsp
--------WEB-INF
------------web.xml
------------lib()
--------index.jsp

1)Default namespace test
First I did not define the namespace in the struts.xml:

    <package name="test" extends="struts-default">
        <action name="register" class="com.strutstest.action.RegisterAction"
method="execute">
            <result name="success">/jsp/thank.jsp</result>
        </action>
    </package>
This is the HTML form(I am not intend to use the tag now):
<form action="register" method="post"></form>

It works well, the page will jump to thank.jsp,the only problem is I have
not found any way to pass some parameters to the thank.jsp and render them
in the page.However this is not the main problem, I think I will make it
clear oneday.

2)set a namespace
Then I tried to test the namespace, I add a namespace to the package:

<package name="test" extends="struts-default" namespace="space">
...Other configuration are same as it in the above.

Then I call it by this manner:
<form action="space/register" method="post"></form>

Then the struts show me the exception:

**There is no Action mapped for action name register**

(The following parameter is I get from debugging step by step at the IDE
:(:(

        String servletPath = request.getServletPath()=== /jsp/space/register

        String requestUri = request.getRequestURI()====
/Struts_Test/jsp/space/register
Then the "/jsp/space/register" is used to parsed the namespace and action
name,at last the namespace is set to "" since there is not a mached
namespace named "/jsp/space".And the name is set to "register". Obviously,
it is wrong. Since the brower add the "jsp" prefix in the action.
)

To avoid the browser add a "jsp" prefix in the action, I tried to set the
action in form like:
<form action="/space/register" method="post"></form>
The exception is the same as before.

Then I se the namespace from "space" to "/space",I also get the same
excetpion as before if I use the action to "space/register" in the HTML
form,however I will get a 404 error if I set the action to
"/space/register".


I am crazying!!! How the hell does the namespace work ????????

BTW, how does the "result" element in the "action" location the page?That's
to say ,for exmaple
<result name="success">/jsp/thank.jsp</result>
how to locat the thank.jsp? Is it based the base path of the web context? Is
the first "/" required?

Re: how does the namespace work in struts

Posted by Li Ying <li...@gmail.com>.
>>  <form action="/space/register" method="post"></form>


Are you rendering html code by your self?
Don't do this.
Try Struts2's tag lib instead.

Example:
<s:form namespace="space" action="register" method="post"></s:form>

The tag lib will convert the namespace/action to a valid URL for you.
And then,when you submit this form, on the server side, struts2 will
map your request URL to an action.

See:
http://struts.apache.org/2.2.1/docs/form.html

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: how does the namespace work in struts

Posted by Maurizio Cucchiara <ma...@gmail.com>.
In this case you could interface to ActionMapping through url tag
(http://struts.apache.org/2.2.1/docs/url.html).


2010/11/5 maven apache <ap...@gmail.com>:
> 2010/11/5 Maurizio Cucchiara <ma...@gmail.com>
>
>> Note that without S2 tag you will not appreciate S2 potential.
>>
> So I wonder if the web ui are built by some javascript framework for exmaple
> the ext -we used to build a form by the exe library:
>
> var form=new *Ext*.*form*.FormPanel({........});
>
> And the form are submitted by a ajax request,so how about the s2 tag at this
> moment?
>
>
>> Furthermore they are not hard to learn (take a look at
>> http://struts.apache.org/2.2.1/docs/tag-reference.html)
>>
>> 2010/11/5 maven apache <ap...@gmail.com>:
>> > :)
>> >
>> > In fact the reason I do not want to use tag now is that I do not want
>> > everything done by the framework,since I am new in struts2,so I want to
>> > learn struts step by step,I always thought that unless we know how the
>> > framework work we can not take the  most advantage of it.
>> >
>> > When I know the work mechanism of the action mapping,then I will use the
>> tag
>> > :)
>> > 2010/11/5 Maurizio Cucchiara <ma...@gmail.com>
>> >
>> >> Struts tags are not mandatory in order to deploy an application, but
>> >> as Li suggested make your life easier :)
>> >>
>> >> 2010/11/5 maven apache <ap...@gmail.com>:
>> >> > Thanks for all your guys reply.
>> >> >
>> >> > That's to say I have no choice but using the struts tag if I decide to
>> >> use
>> >> > the struts??
>> >> >
>> >>
>> >> --
>> >> Maurizio Cucchiara
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> >> For additional commands, e-mail: user-help@struts.apache.org
>> >>
>> >>
>> >
>>
>>
>>
>> --
>> Maurizio Cucchiara
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>



-- 
Maurizio Cucchiara

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: how does the namespace work in struts

Posted by maven apache <ap...@gmail.com>.
2010/11/5 Maurizio Cucchiara <ma...@gmail.com>

> Note that without S2 tag you will not appreciate S2 potential.
>
So I wonder if the web ui are built by some javascript framework for exmaple
the ext -we used to build a form by the exe library:

var form=new *Ext*.*form*.FormPanel({........});

And the form are submitted by a ajax request,so how about the s2 tag at this
moment?


> Furthermore they are not hard to learn (take a look at
> http://struts.apache.org/2.2.1/docs/tag-reference.html)
>
> 2010/11/5 maven apache <ap...@gmail.com>:
> > :)
> >
> > In fact the reason I do not want to use tag now is that I do not want
> > everything done by the framework,since I am new in struts2,so I want to
> > learn struts step by step,I always thought that unless we know how the
> > framework work we can not take the  most advantage of it.
> >
> > When I know the work mechanism of the action mapping,then I will use the
> tag
> > :)
> > 2010/11/5 Maurizio Cucchiara <ma...@gmail.com>
> >
> >> Struts tags are not mandatory in order to deploy an application, but
> >> as Li suggested make your life easier :)
> >>
> >> 2010/11/5 maven apache <ap...@gmail.com>:
> >> > Thanks for all your guys reply.
> >> >
> >> > That's to say I have no choice but using the struts tag if I decide to
> >> use
> >> > the struts??
> >> >
> >>
> >> --
> >> Maurizio Cucchiara
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >>
> >
>
>
>
> --
> Maurizio Cucchiara
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: RE: Have you ever used InputConfig annotation?

Posted by Dave Newton <da...@gmail.com>.
On Mon, Nov 8, 2010 at 5:58 PM, Alfredo Manuel Osorio Martinez wrote:
>> you can trivially avoid unnecessary prepare calls.
> How can I avoid unnecessary prepare calls? I mean how can I avoid the
> prepare method won't be called if there are not validation errors.

>> De: Dave Newton [mailto:davelnewton@gmail.com]
>> Enviado el: Monday, November 08, 2010 10:47 AM
>> Don't submit to the same action. Or use prepare{methodName}. Or take
>> advantage of it being a MethodFilterInterceptor and configure it to
>> run only for the methods you want. Or extend it to default to your
>> desired application-specific behavior. Or...

Dave

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: RE: Have you ever used InputConfig annotation?

Posted by Alfredo Manuel Osorio Martinez <al...@afirme.com>.
Hello Dave,

> you can trivially avoid unnecessary prepare calls.

How can I avoid unnecessary prepare calls? I mean how can I avoid the
prepare method won't be called if there are not validation errors.

Thanks in advance

Alfredo Osorio

-----Mensaje original-----
De: Dave Newton [mailto:davelnewton@gmail.com] 
Enviado el: Monday, November 08, 2010 1:30 PM
Para: Struts Users Mailing List
Asunto: Re: RE: Have you ever used InputConfig annotation?

And I'm saying #1 that a testable action is worth a lot and #2 you can
trivially avoid unnecessary prepare calls.

Dave
 On Nov 8, 2010 1:54 PM, "Alfredo Manuel Osorio Martinez" <
alfredo.osorio@afirme.com> wrote:
> Hello Dave and thanks for your response,
>
> I think I didn't explain myself what I tried to say is whenever you
> submit to the action that will process the input data that action's
> prepare (or prepareXXX) needs to know how to populate the data needed
> for the input result and that's because if validation fails the result
> will be the input result (where the data came from) and needs that
data
> for the repopulation of some controls (list, etc). So whether the
> validation passed or failed that logic is always called. So is that
the
> price you have to pay for a cleaner testable action? My point is the
> overhead of calling that method (prepare) for input repopulation even
> though sometimes (successful validation) you won't need it.
>
> Thanks
>
> Alfredo Osorio
>
> -----Mensaje original-----
> De: Dave Newton [mailto:davelnewton@gmail.com]
> Enviado el: Monday, November 08, 2010 10:47 AM
> Para: Struts Users Mailing List
> Asunto: Re: Have you ever used InputConfig annotation?
>
> On Mon, Nov 8, 2010 at 10:07 AM, Alfredo Manuel Osorio Martinez wrote:
>> Are you saying that input methods shouldn't have any logic in and
just
>> return the string of the result. If that's the case where should you
>> retrieve those list values? What other alternatives do I have? The
> only
>> other one that comes to my mind is Preparable and action tag.
>
> Preparable; I have issues with using <s:action> tag for that as well;
> it puts too much responsibility into the view layer, and means you
> *must* integration-test the entire flow, including page rendering, in
> order to know if the action works, rather than testing the action in
> isolation.
>
> My acid test for determining what's appropriate in a method:
>
> Pass:
>
> Q: What does getInputResultNameDo?
> A: Returns the name of the input result.
>
> Fail:
>
> Q: What does getInputResultNameDo?
> A: It gets the name to use for the input result. And goes to the
> database, retrieves a bunch of values, handles persistence-layer
> Texceptions, and may populate error messages to return to the user.
>
>> So in the cases where the validation is going to be
>> successful why would you want to retrieve the input lists values or
>> other stuff for the input result if you are not even going to use it.
>> Isn't that unnecessary overhead?
>
> Don't submit to the same action. Or use prepare{methodName}. Or take
> advantage of it being a MethodFilterInterceptor and configure it to
> run only for the methods you want. Or extend it to default to your
> desired application-specific behavior. Or...
>
> Dave
>
> ---------------------------------------------------------------------
> 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
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: RE: Have you ever used InputConfig annotation?

Posted by Dave Newton <da...@gmail.com>.
And I'm saying #1 that a testable action is worth a lot and #2 you can
trivially avoid unnecessary prepare calls.

Dave
 On Nov 8, 2010 1:54 PM, "Alfredo Manuel Osorio Martinez" <
alfredo.osorio@afirme.com> wrote:
> Hello Dave and thanks for your response,
>
> I think I didn't explain myself what I tried to say is whenever you
> submit to the action that will process the input data that action's
> prepare (or prepareXXX) needs to know how to populate the data needed
> for the input result and that's because if validation fails the result
> will be the input result (where the data came from) and needs that data
> for the repopulation of some controls (list, etc). So whether the
> validation passed or failed that logic is always called. So is that the
> price you have to pay for a cleaner testable action? My point is the
> overhead of calling that method (prepare) for input repopulation even
> though sometimes (successful validation) you won't need it.
>
> Thanks
>
> Alfredo Osorio
>
> -----Mensaje original-----
> De: Dave Newton [mailto:davelnewton@gmail.com]
> Enviado el: Monday, November 08, 2010 10:47 AM
> Para: Struts Users Mailing List
> Asunto: Re: Have you ever used InputConfig annotation?
>
> On Mon, Nov 8, 2010 at 10:07 AM, Alfredo Manuel Osorio Martinez wrote:
>> Are you saying that input methods shouldn't have any logic in and just
>> return the string of the result. If that's the case where should you
>> retrieve those list values? What other alternatives do I have? The
> only
>> other one that comes to my mind is Preparable and action tag.
>
> Preparable; I have issues with using <s:action> tag for that as well;
> it puts too much responsibility into the view layer, and means you
> *must* integration-test the entire flow, including page rendering, in
> order to know if the action works, rather than testing the action in
> isolation.
>
> My acid test for determining what's appropriate in a method:
>
> Pass:
>
> Q: What does getInputResultNameDo?
> A: Returns the name of the input result.
>
> Fail:
>
> Q: What does getInputResultNameDo?
> A: It gets the name to use for the input result. And goes to the
> database, retrieves a bunch of values, handles persistence-layer
> Texceptions, and may populate error messages to return to the user.
>
>> So in the cases where the validation is going to be
>> successful why would you want to retrieve the input lists values or
>> other stuff for the input result if you are not even going to use it.
>> Isn't that unnecessary overhead?
>
> Don't submit to the same action. Or use prepare{methodName}. Or take
> advantage of it being a MethodFilterInterceptor and configure it to
> run only for the methods you want. Or extend it to default to your
> desired application-specific behavior. Or...
>
> Dave
>
> ---------------------------------------------------------------------
> 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: Have you ever used InputConfig annotation?

Posted by Alfredo Manuel Osorio Martinez <al...@afirme.com>.
Hello Dave and thanks for your response,

I think I didn't explain myself what I tried to say is whenever you
submit to the action that will process the input data that action's
prepare (or prepareXXX) needs to know how to populate the data needed
for the input result and that's because if validation fails the result
will be the input result (where the data came from) and needs that data
for the repopulation of some controls (list, etc). So whether the
validation passed or failed  that logic is always called. So is that the
price you have to pay for a cleaner testable action? My point is the
overhead of calling that method (prepare) for input repopulation even
though sometimes (successful validation) you won't need it.

Thanks

Alfredo Osorio

-----Mensaje original-----
De: Dave Newton [mailto:davelnewton@gmail.com] 
Enviado el: Monday, November 08, 2010 10:47 AM
Para: Struts Users Mailing List
Asunto: Re: Have you ever used InputConfig annotation?

On Mon, Nov 8, 2010 at 10:07 AM, Alfredo Manuel Osorio Martinez wrote:
> Are you saying that input methods shouldn't have any logic in and just
> return the string of the result. If that's the case where should you
> retrieve those list values? What other alternatives do I have? The
only
> other one that comes to my mind is Preparable and action tag.

Preparable; I have issues with using <s:action> tag for that as well;
it puts too much responsibility into the view layer, and means you
*must* integration-test the entire flow, including page rendering, in
order to know if the action works, rather than testing the action in
isolation.

My acid test for determining what's appropriate in a method:

Pass:

Q: What does getInputResultNameDo?
A: Returns the name of the input result.

Fail:

Q: What does getInputResultNameDo?
A: It gets the name to use for the input result. And goes to the
database, retrieves a bunch of values, handles persistence-layer
Texceptions, and may populate error messages to return to the user.

> So in the cases where the validation is going to be
> successful why would you want to retrieve the input lists values or
> other stuff for the input result if you are not even going to use it.
> Isn't that unnecessary overhead?

Don't submit to the same action. Or use prepare{methodName}. Or take
advantage of it being a MethodFilterInterceptor and configure it to
run only for the methods you want. Or extend it to default to your
desired application-specific behavior. Or...

Dave

---------------------------------------------------------------------
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: Have you ever used InputConfig annotation?

Posted by Dave Newton <da...@gmail.com>.
On Mon, Nov 8, 2010 at 10:07 AM, Alfredo Manuel Osorio Martinez wrote:
> Are you saying that input methods shouldn't have any logic in and just
> return the string of the result. If that's the case where should you
> retrieve those list values? What other alternatives do I have? The only
> other one that comes to my mind is Preparable and action tag.

Preparable; I have issues with using <s:action> tag for that as well;
it puts too much responsibility into the view layer, and means you
*must* integration-test the entire flow, including page rendering, in
order to know if the action works, rather than testing the action in
isolation.

My acid test for determining what's appropriate in a method:

Pass:

Q: What does getInputResultNameDo?
A: Returns the name of the input result.

Fail:

Q: What does getInputResultNameDo?
A: It gets the name to use for the input result. And goes to the
database, retrieves a bunch of values, handles persistence-layer
Texceptions, and may populate error messages to return to the user.

> So in the cases where the validation is going to be
> successful why would you want to retrieve the input lists values or
> other stuff for the input result if you are not even going to use it.
> Isn't that unnecessary overhead?

Don't submit to the same action. Or use prepare{methodName}. Or take
advantage of it being a MethodFilterInterceptor and configure it to
run only for the methods you want. Or extend it to default to your
desired application-specific behavior. Or...

Dave

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Have you ever used InputConfig annotation?

Posted by Alfredo Manuel Osorio Martinez <al...@afirme.com>.
Hello,

> I still don't believe using a framework-defined method, whose intent
is to
> return a string result name, to load data is an expressive design.

Are you saying that input methods shouldn't have any logic in and just
return the string of the result. If that's the case where should you
retrieve those list values? What other alternatives do I have? The only
other one that comes to my mind is Preparable and action tag.

About Preparable interface and input field repopulation there is
something that I don't get it. When you submit the form data to the
action the Preparable (prepare method) will be executed regardless of
validation. So in the cases where the validation is going to be
successful why would you want to retrieve the input lists values or
other stuff for the input result if you are not even going to use it.
Isn't that unnecessary overhead?

Alfredo Osorio

-----Mensaje original-----
De: Dave Newton [mailto:davelnewton@gmail.com] 
Enviado el: Saturday, November 06, 2010 6:30 AM
Para: Struts Users Mailing List
Asunto: Re: Have you ever used InputConfig annotation?

I still don't believe using a framework-defined method, whose intent is
to
return a string result name, to load data is an expressive design.
 On Nov 6, 2010 2:36 AM, "Maurizio Cucchiara"
<ma...@gmail.com>
wrote:
> InputConfig works as documented. I reccomend to use Li's suggestion
> for inheritance matter. When you need to overwrite base class
> behavior, then mark method with InputConfig annotation.
>
> 2010/11/5 Alfredo Manuel Osorio Martinez <al...@afirme.com>:
>> Hello,
>>
>> By looking at DefaultWorkflowInterceptor I saw an annotation that I
>> didn't know existed. I am talking about:
>>
>> com.opensymphony.xwork2.interceptor.annotations.InputConfig
>>
>> I think it can be used for input repopulation and can be used as an
>> alternative to Preparable and <s:action/>.
>>
>> What surprised me was that there is a little documentation about the
use
>> of the annotation or examples.
>>
>> Haver you ever used this one before?
>>
>> Is it a good idea to use it for input repopulation for example
>> collections for selects in case a validation fails?
>>
>> Thanks
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>
>
> --
> Maurizio Cucchiara
>
> ---------------------------------------------------------------------
> 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: Have you ever used InputConfig annotation?

Posted by Dave Newton <da...@gmail.com>.
I still don't believe using a framework-defined method, whose intent is to
return a string result name, to load data is an expressive design.
 On Nov 6, 2010 2:36 AM, "Maurizio Cucchiara" <ma...@gmail.com>
wrote:
> InputConfig works as documented. I reccomend to use Li's suggestion
> for inheritance matter. When you need to overwrite base class
> behavior, then mark method with InputConfig annotation.
>
> 2010/11/5 Alfredo Manuel Osorio Martinez <al...@afirme.com>:
>> Hello,
>>
>> By looking at DefaultWorkflowInterceptor I saw an annotation that I
>> didn't know existed. I am talking about:
>>
>> com.opensymphony.xwork2.interceptor.annotations.InputConfig
>>
>> I think it can be used for input repopulation and can be used as an
>> alternative to Preparable and <s:action/>.
>>
>> What surprised me was that there is a little documentation about the use
>> of the annotation or examples.
>>
>> Haver you ever used this one before?
>>
>> Is it a good idea to use it for input repopulation for example
>> collections for selects in case a validation fails?
>>
>> Thanks
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>
>
> --
> Maurizio Cucchiara
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>

Re: Have you ever used InputConfig annotation?

Posted by Maurizio Cucchiara <ma...@gmail.com>.
InputConfig works as documented. I reccomend to use Li's suggestion
for inheritance matter. When you need to overwrite base class
behavior, then mark method with InputConfig annotation.

2010/11/5 Alfredo Manuel Osorio Martinez <al...@afirme.com>:
> Hello,
>
> By looking at DefaultWorkflowInterceptor I saw an annotation that I
> didn't know existed. I am talking about:
>
> com.opensymphony.xwork2.interceptor.annotations.InputConfig
>
> I think it can be used for input repopulation and can be used as an
> alternative to Preparable and <s:action/>.
>
> What surprised me was that there is a little documentation about the use
> of the annotation or examples.
>
> Haver you ever used this one before?
>
> Is it a good idea to use it for input repopulation for example
> collections for selects in case a validation fails?
>
> Thanks
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 
Maurizio Cucchiara

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Have you ever used InputConfig annotation?

Posted by Li Ying <li...@gmail.com>.
Actually, I am using interface [ValidationWorkflowAware] instead of
annotation [InputConfig] for the purpose of repopulation when input
validation fail happen.

You can see how ValidationWorkflowAware work when you read the source
code of DefaultWorkflowInterceptor.

Basically, the idea is similar. But, [InputConfig] need you to appoint
a method name every time.
So I think it is more convenient if I use ValidationWorkflowAware.

My solution looks like:
(1)Define a class BaseAction as the base class for all my Action class
(2)In BaseAction, implement [ValidationWorkflowAware]
(3)In the method [getInputResultName], call a protected method
[loadData] which is empty(for now), and then return [INPUT] as the
result name
(4)In specific action class, override the method [loadData], and do
the real repolulation job for this page

So I can keep all the action class do the same work in the same way.
When the project and the develop team get large, I think the
consistency of code convention
is much important than just get the job done.

Hope this helps.



2010/11/6 Alfredo Manuel Osorio Martinez <al...@afirme.com>:
> Hello,
>
> By looking at DefaultWorkflowInterceptor I saw an annotation that I
> didn't know existed. I am talking about:
>
> com.opensymphony.xwork2.interceptor.annotations.InputConfig
>
> I think it can be used for input repopulation and can be used as an
> alternative to Preparable and <s:action/>.
>
> What surprised me was that there is a little documentation about the use
> of the annotation or examples.
>
> Haver you ever used this one before?
>
> Is it a good idea to use it for input repopulation for example
> collections for selects in case a validation fails?
>
> Thanks

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Have you ever used InputConfig annotation?

Posted by Alfredo Manuel Osorio Martinez <al...@afirme.com>.
Hello,

By looking at DefaultWorkflowInterceptor I saw an annotation that I
didn't know existed. I am talking about:

com.opensymphony.xwork2.interceptor.annotations.InputConfig

I think it can be used for input repopulation and can be used as an
alternative to Preparable and <s:action/>.

What surprised me was that there is a little documentation about the use
of the annotation or examples.

Haver you ever used this one before?

Is it a good idea to use it for input repopulation for example
collections for selects in case a validation fails?

Thanks



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: how does the namespace work in struts

Posted by Maurizio Cucchiara <ma...@gmail.com>.
Note that without S2 tag you will not appreciate S2 potential.
Furthermore they are not hard to learn (take a look at
http://struts.apache.org/2.2.1/docs/tag-reference.html)

2010/11/5 maven apache <ap...@gmail.com>:
> :)
>
> In fact the reason I do not want to use tag now is that I do not want
> everything done by the framework,since I am new in struts2,so I want to
> learn struts step by step,I always thought that unless we know how the
> framework work we can not take the  most advantage of it.
>
> When I know the work mechanism of the action mapping,then I will use the tag
> :)
> 2010/11/5 Maurizio Cucchiara <ma...@gmail.com>
>
>> Struts tags are not mandatory in order to deploy an application, but
>> as Li suggested make your life easier :)
>>
>> 2010/11/5 maven apache <ap...@gmail.com>:
>> > Thanks for all your guys reply.
>> >
>> > That's to say I have no choice but using the struts tag if I decide to
>> use
>> > the struts??
>> >
>>
>> --
>> Maurizio Cucchiara
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>



-- 
Maurizio Cucchiara

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: how does the namespace work in struts

Posted by maven apache <ap...@gmail.com>.
:)

In fact the reason I do not want to use tag now is that I do not want
everything done by the framework,since I am new in struts2,so I want to
learn struts step by step,I always thought that unless we know how the
framework work we can not take the  most advantage of it.

When I know the work mechanism of the action mapping,then I will use the tag
:)
2010/11/5 Maurizio Cucchiara <ma...@gmail.com>

> Struts tags are not mandatory in order to deploy an application, but
> as Li suggested make your life easier :)
>
> 2010/11/5 maven apache <ap...@gmail.com>:
> > Thanks for all your guys reply.
> >
> > That's to say I have no choice but using the struts tag if I decide to
> use
> > the struts??
> >
>
> --
> Maurizio Cucchiara
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: how does the namespace work in struts

Posted by Maurizio Cucchiara <ma...@gmail.com>.
Struts tags are not mandatory in order to deploy an application, but
as Li suggested make your life easier :)

2010/11/5 maven apache <ap...@gmail.com>:
> Thanks for all your guys reply.
>
> That's to say I have no choice but using the struts tag if I decide to use
> the struts??
>

-- 
Maurizio Cucchiara

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: how does the namespace work in struts

Posted by maven apache <ap...@gmail.com>.
Thanks for all your guys reply.

That's to say I have no choice but using the struts tag if I decide to use
the struts??

2010/11/5 Li Ying <li...@gmail.com>

> >>  <form action="space/register" method="post"></form>
>
> This HTML code, will post your form to the RELATIVE path [space/register].
> So, the ABSOLUTE path which is requested will depend on the current
> URL of this page.
>
> If ABSOLUTE path is not right, no doubt struts2 can not map it to a
> right namespace/action.
>
>
>
> >> I will get a 404 error if I set the action to "/space/register"
>
> This HTML code, will post your form to the ABSOLUTE path [/space/register].
> But your web app is running under the [context path].
> So the valid URL should be something like
> [/contextPath/space/register.action]
>
> My suggestion is:
> (1)Use the Struts2 tag lib, get it works.
> (2)Read the HTML code generated by tag lib, study how it works
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: how does the namespace work in struts

Posted by Li Ying <li...@gmail.com>.
>>  <form action="space/register" method="post"></form>

This HTML code, will post your form to the RELATIVE path [space/register].
So, the ABSOLUTE path which is requested will depend on the current
URL of this page.

If ABSOLUTE path is not right, no doubt struts2 can not map it to a
right namespace/action.



>> I will get a 404 error if I set the action to "/space/register"

This HTML code, will post your form to the ABSOLUTE path [/space/register].
But your web app is running under the [context path].
So the valid URL should be something like [/contextPath/space/register.action]

My suggestion is:
(1)Use the Struts2 tag lib, get it works.
(2)Read the HTML code generated by tag lib, study how it works

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: how does the namespace work in struts

Posted by Edward Seager <ed...@gmail.com>.
Hi,

I've tried to answer your questions below based on my interpretation of the
documentation.

On Fri, Nov 5, 2010 at 8:33 AM, maven apache <ap...@gmail.com> wrote:

> I meet some problem when I try to learn the namespace of struts2,I am using
> struts-2.2.1.
>
> After read the docs at:
> http://struts.apache.org/2.2.1/docs/namespace-configuration.html
>
> I am confused for the following reason:
>
> The example:
>
> <package name="default">
>
>    <action name="foo" class="mypackage.simpleAction">
>
>        <result name="success" type="dispatcher">greeting.jsp</result>
>
>    </action>
>
>    <action name="bar" class="mypackage.simpleAction">
>
>        <result name="success" type="dispatcher">bar1.jsp</result>
>
>    </action>
> </package>
>
> <package name="mypackage1" namespace="/">
>
>    <action name="moo" class="mypackage.simpleAction">
>
>        <result name="success" type="dispatcher">moo.jsp</result>
>
>    </action>
> </package>
>
> <package name="mypackage2" namespace="/barspace">
>
>    <action name="bar" class="mypackage.simpleAction">
>
>        <result name="success" type="dispatcher">bar2.jsp</result>
>
>    </action>
> </package>
>
> This is the explanation:
>
> *If a request is made to /barspace/foo.action, the namespace /barspace will
> be checked for action foo. If a local action is not found, the default
> namespace is checked. In the Namespace Example, there is no action foo in
> the namespace /barspace, therefore the default will be checked and
> /foo.action will be executed.*
>
> I wonder why it is '/foo.action' rather than 'foo.action",it said that it
> will find the foo.action at the default namespace,and the default namespace
> is "",so it should be foo.action,why there is a '/'??
>


I read this as, the default namespace is also relative to the context path.
so http://mycompany.com/myapp/foo.action. The default action has to be
relative to something afterall right? The difference between the default and
/ namespace is that the / namespace isn't checked in the fall back.



>
> ALso problem 2:
>
> *Namespace are not hierarchical like a file system path. There is one
> namespace level. For example if the URL /barspace/myspace/bar.action is
> requested, the framework will first look for namespace /barspace/myspace.*
>
> For the request url "/barspace/myspace/bar.action", the '/barspace/myspace'
> will be splitted as a namespace,so what is the action now? is it the
> "/bar.action" or "bar.action",since the "/" may stand for a root namespace.
>
> I am really confused,anyone can give me a detailed suggestion??
>
>
>
Namespaces not being hierarchical means that you do not have separate
namespaces for /barspace or /myspace in this case. Just one namespace for
/barspace/myspace. It's not like a directory structure on a file system. So
/barspace/myspace/bar.action will look up an action called bar in the
namespace /barspace/myspace/.

Hope this helps.


-- 
Eddy Seager