This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Pipeline as Code and have Mohamed Labouardy on-line!
See this thread for details.
Win a copy of Pipeline as Code this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Action not getting invoked in struts 2

 
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm migrating an app from Struts 1 to Struts 2 and am missing some basic concepts. For some reason, my desired action in my class is not getting invoked. I have this servlet ...


public class AccountsAction extends ActionSupport implements ServletRequestAware, ValidationAware, Validateable {

...

public String pcFlow() {
logger.info("Entering pc flow action.");
return _redirect();
} // pcFlow

...
}


and this defined in my struts.xml file ...


<package name="myapp" namespace="/" extends="struts-default">

<default-action-ref name="index" />
<action name="pcFlow" class="com.myco.regui.struts.accounts.AccountsAction">
<result name="success">jsp/pcredirect.jsp</result>
<result name="input">jsp/start.jsp</result>
<result name="error">jsp/start.jsp</result>
</action>

...
</package>


Although the "validate" method in the above class is getting called properly, the desired action "pcFlow" is not getting invoked, which I know because nothing gets logged from teh debug statement. Any ideas what basic thing I'm missing?

Thanks, - Dave
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseCodeTags. (Also, minor nit--you don't have a servlet, you have an action.)

How would S2 know to call that method? The default method is execute(). If you want to call a specific, non-default method then you need to specify that in the action mapping via the "method" attribute.
 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. When I added the "method" attribute to the action tag, everything worked. -
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just as a heads-up, too--some method names are meaningful to the validation and workflow interceptors and may produce unexpected behaviour if you use one of them by accident.
 
money grubbing section goes here:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic