You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Philip Lorenz <ph...@gmx.net> on 2007/02/05 10:48:16 UTC

Using the Restful2ActionMapper

Hi,

I am trying to use the Restful2ActionMapper for my project. However I have not been able to configure it correctly so far.

My struts.xml looks like the following:

<struts>

	<constant name="struts.mapper.class" value="restful2" />

	<constant name="struts.enable.SlashesInActionNames" value="true" />

	<package name="default" extends="struts-default">
		<action name="view/*" class="com.test.View">
			<result>/test.jsp</result>
		</action>
	</package>
</struts>

However mapping does not work at all. After enabling SlashesInActionNames and accessing the URL "/view/uploadId/5.action" I get a "There is no Action mapped for action name uploadId/5" error. Disabling it only leads to to an error message that the action 5 could not be found.

After having a glimpse at the source code it the class does not seem to set the action name correctly (it receives the correct URL however). Is this a known problem or did I misconfigure my application?

Any hints would be appreciated.

Philip Lorenz

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


Re: Using the Restful2ActionMapper

Posted by Philip Lorenz <ph...@gmx.net>.
> This is most likely a bug, can you create a JIRA ticked?
> 
> /Ian
> 

The bug is now located here: https://issues.apache.org/struts/browse/WW-1706

Philip

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


Re: Using the Restful2ActionMapper

Posted by Ian Roughley <ia...@fdar.com>.
This is most likely a bug, can you create a JIRA ticked?

/Ian



Philip Lorenz wrote:
>   
>> Hi,
>>
>> I am trying to use the Restful2ActionMapper for my project. However I have
>> not been able to configure it correctly so far.
>>
>> My struts.xml looks like the following:
>>
>> <struts>
>>
>> 	<constant name="struts.mapper.class" value="restful2" />
>>
>> 	<constant name="struts.enable.SlashesInActionNames" value="true" />
>>
>> 	<package name="default" extends="struts-default">
>> 		<action name="view/*" class="com.test.View">
>> 			<result>/test.jsp</result>
>> 		</action>
>> 	</package>
>> </struts>
>>
>> However mapping does not work at all. After enabling SlashesInActionNames
>> and accessing the URL "/view/uploadId/5.action" I get a "There is no Action
>> mapped for action name uploadId/5" error. Disabling it only leads to to an
>> error message that the action 5 could not be found.
>>
>> After having a glimpse at the source code it the class does not seem to
>> set the action name correctly (it receives the correct URL however). Is this
>> a known problem or did I misconfigure my application?
>>
>> Any hints would be appreciated.
>>
>> Philip Lorenz
>>     
>
>
> Just a quick follow up on this.
>
> By replacing 
> String params = actionName.substring(0, actionSlashPos);
> at line 146 in Restful2ActionMapper with
> String params = actionName.substring(actionSlashPos + 1);
>
> and
> mapping.setName(actionName.substring(actionSlashPos+1));
> at line 177 with
> mapping.setName(actionName.substring(0, actionSlashPos));
>
> I get the expected behaviour of setting the variable uploadId to 5 using the following URL: view/uploadId/5
>
> Is this a bug or am I misunderstanding the documentation regarding REST-based URLs?
>
> Philip
>
> ---------------------------------------------------------------------
> 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: Using the Restful2ActionMapper

Posted by Philip Lorenz <ph...@gmx.net>.

> Hi,
> 
> I am trying to use the Restful2ActionMapper for my project. However I have
> not been able to configure it correctly so far.
> 
> My struts.xml looks like the following:
> 
> <struts>
> 
> 	<constant name="struts.mapper.class" value="restful2" />
> 
> 	<constant name="struts.enable.SlashesInActionNames" value="true" />
> 
> 	<package name="default" extends="struts-default">
> 		<action name="view/*" class="com.test.View">
> 			<result>/test.jsp</result>
> 		</action>
> 	</package>
> </struts>
> 
> However mapping does not work at all. After enabling SlashesInActionNames
> and accessing the URL "/view/uploadId/5.action" I get a "There is no Action
> mapped for action name uploadId/5" error. Disabling it only leads to to an
> error message that the action 5 could not be found.
> 
> After having a glimpse at the source code it the class does not seem to
> set the action name correctly (it receives the correct URL however). Is this
> a known problem or did I misconfigure my application?
> 
> Any hints would be appreciated.
> 
> Philip Lorenz


Just a quick follow up on this.

By replacing 
String params = actionName.substring(0, actionSlashPos);
at line 146 in Restful2ActionMapper with
String params = actionName.substring(actionSlashPos + 1);

and
mapping.setName(actionName.substring(actionSlashPos+1));
at line 177 with
mapping.setName(actionName.substring(0, actionSlashPos));

I get the expected behaviour of setting the variable uploadId to 5 using the following URL: view/uploadId/5

Is this a bug or am I misunderstanding the documentation regarding REST-based URLs?

Philip

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


Re: Using the Restful2ActionMapper

Posted by Dale Newfield <Da...@Newfield.org>.
mraible wrote:
> I'm trying to change from using the old-style URLs to Restful2ActionMapper.

What do you want your URLs to be for the various actions?
If you really just want the view to look restful, you don't need to muck 
with the ActionMapper at all:

/user/bob.html to view bob

<package name="viewUser" namespace="/user" extends="struts-default">
   <action name="*" class="userAction" method="view">
       <param name="username">{1}</param>
       <result name="success">/WEB-INF/pages/viewUser.jsp</result>
       <result name="badID">/404.jsp</result>
   </action>
</package>

Presumably if you set slashesInActions you can do this without a 
separate package.

-Dale

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


Re: Using the Restful2ActionMapper

Posted by mraible <ma...@raibledesigns.com>.
I'm trying to change from using the old-style URLs to Restful2ActionMapper.
Here's what I've added to struts.xml:

    <bean name="struts2"
type="org.apache.struts2.dispatcher.mapper.ActionMapper"
class="org.apache.struts2.dispatcher.mapper.CompositeActionMapper"/>
    <constant name="struts.mapper.composite"
value="org.apache.struts2.dispatcher.mapper.DefaultActionMapper,org.apache.struts2.dispatcher.mapper.Restful2ActionMapper"/>

I have a UserAction that does CRUD (below).

And the following action definitions:

        <!-- List of Users -->
        <action name="users" class="userAction" method="list">
            <result name="success">userList.jsp</result>
            <result name="input">userList.jsp</result>
        </action>

        <!-- Edit User -->
        <action name="editUser" class="userAction" method="edit">
            <result name="success">userForm.jsp</result>
            <result name="input">userList.jsp</result>
        </action>

        <!-- Save User -->
        <action name="saveUser" class="userAction">
            <result name="cancel" type="redirect">users.html</result>
            <result name="delete" type="redirect">users.html</result>
            <result name="input">userForm.jsp</result>
            <result name="success"
type="chain">saveUserWithValidation</result>
        </action>

        <action name="saveUserWithValidation" class="userAction"
method="save">
            <result name="input">userForm.jsp</result>
            <result name="success" type="redirect">users.html</result>
        </action>

Is it possible to change to something like the following?

  <action name="user/*" className="userAction">
    {0}
    ...
  </action>

If so, I'm guessing I need to change some method names (i.e. the default
method for /user would be index, so I should change list() to index()) and
some result names (edit goes to "edit", save goes to "save", index goes to
"success")?

Thanks,

Matt


Philip Lorenz-2 wrote:
> 
> 
>> 
>> Tomorrow's task for me is trying RESTful, so hopefully
>> you'll figure this out ;)
>> 
>> Do you need the ".action" in the URL?!
>> 
>> d.
> 
> You can remove the action postfix by setting struts.action.extension to an
> empty string. I just left it enabled to have a clean default config with
> only the neccesary settings changed.
> 
> Philip
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Using-the-Restful2ActionMapper-tf3173361.html#a12171692
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Using the Restful2ActionMapper

Posted by Philip Lorenz <ph...@gmx.net>.
> 
> Tomorrow's task for me is trying RESTful, so hopefully
> you'll figure this out ;)
> 
> Do you need the ".action" in the URL?!
> 
> d.

You can remove the action postfix by setting struts.action.extension to an empty string. I just left it enabled to have a clean default config with only the neccesary settings changed.

Philip

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


Re: Using the Restful2ActionMapper

Posted by Dave Newton <ne...@yahoo.com>.
--- Philip Lorenz <ph...@gmx.net> wrote:
> However mapping does not work at all. After enabling
> SlashesInActionNames and accessing the URL
> "/view/uploadId/5.action" I get a "There is no
> Action mapped for action name uploadId/5" error.
> Disabling it only leads to to an error message that
> the action 5 could not be found.

Tomorrow's task for me is trying RESTful, so hopefully
you'll figure this out ;)

Do you need the ".action" in the URL?!

d.



 
____________________________________________________________________________________
We won't tell. Get more on shows you hate to love 
(and love to hate): Yahoo! TV's Guilty Pleasures list.
http://tv.yahoo.com/collections/265 

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