I have spent a few weeks getting my hands dirty with Struts 2 now, and I
have come to a crossroads of sorts, in my app design and layout of my
actions.
A good example of where I am looking for direction is the following:
A user logs in and wants to add a transaction for an account. I have an
AccountAction that is setup to work with, ultimately, my AccountBean.
But here is where I need to know the right way to do things in Struts2
land. When I want to search for a particular account, I of course use
the AccountAction, sending in an account.acctNumber via my _input. So
far so good no? If the account is not found, great, I just send them
back to the same page, with a nift actionError telling them what went
wrong.
But if the Account is indeed found, then what? I know I need to get the
Account object onto the stack for displaying. But where should I send
the app next? Do I have an _enterPayment method in my AccountAction?
And then reference that in the same way as I did _input, as a new result
in my ActionCrud_* in my .xml file? Or is it more recommended to create
a new action in the .xml file with a new result just for this particular
scenario? 1 action per functional part of the app, or 1 action per data
type, with many results corresponding to each method that I call inside
that partuclar action?
The more I think of it, the more questions I have.
<action name="AccountCrud_*"
class="com.its.irmc.action.AccountAction" method="{1}">
<!-- this one I get...I bring up my search form...
ActionCrud_input.do brings up my search form
which has an action of ??? (Assuming
ActionCrud_Search for now, if we stay in the 1 action idea->
<result name="input">/WEB-INF/jsp/UC01-EnterPayment.jsp</result>
<!-- This one I get, my search page asks for an account
number, it calls getAccount(acctNumber)
and the appropriate account is found. But if I have
a result that goes to a page...I can't
for some reason see the information in the Account
object on the stack, only the account
number from the Account object created at submit
from the input page. -->
<result
name="success-acctfound">/WEB-INF/jsp/UC01a-EnterPayment.jsp</result>
<!-- Should I instead be redirecting to an action in stead of
havnig the result load a page?
Am I missing a base idea of how the stack operates and
when it is available to me? -->
<result name="success-acctfound"
type="redirect-action">AccountCrud_search</result>
</action>
From my search page:
<s:form namespace="/irmc" action="AccountCrud_search" validate="true">
<s:textfield name="account.acctNumber" value="%{account.acctNumber}"
label="%{getText('acctNumber')}" size="40"/>
<s:submit key="button.label.submit"/>
<s:reset/>
</s:form>
From my result page after the search:
Account Number: [<s:property value="account.acctNumber"/>]<br>
Name: <s:property value="account.firstName"/> <s:property
value="account.lastName"/><br>
Address: <s:property value="account.address1"/><br>
Address: <s:property value="account.address2"/><br>
Debtor Phone: <s:property value="account.phone"/><br>
<s:actionmessage />
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]