<action name="userLogin" class="com.cc.ad.web.common.UserLoginAction">
<result name="error">/user-login.jsp</result>
<result name="redirect" type="redirect">${retUrl}</result>
<result name="customerRedirect" type="redirect">${customerRedirect}</result>
<result name="supplierRedirect" type="redirect">${supplierRedirect}</result>
<result name="diamondViewRedirect" type="redirect">${diamondViewRedirect}</result>
<result name="supplierPopupRedirect" type="redirect">${supplierPopup}</result>
<result name="customerPopupRedirect" type="redirect">${customerPopup}</result>
</action>
Above I show one of many things written in my Struts XML file. Here nothing is define in the method attributes so I am confused about which method of UserLoginAction class is called when this action is called.
If method name is not specified in the action configuration, Struts will look for a method named execute by default.
Struts 2.0 Action Configuration Doc
Related
I'm migrating my application from Struts1 to 2.5. All the navigation url is defined as per below :
../menumanager.do?method=adduser
../menumanager.do?method=deleteuser
In struts 1 we extend dispather action class and reading the method name from query parameter. Using action forward we are redirecting to particular method.
Is there any way in struts 2, we can define same action name in struts.xml and besed on method name in the url we will redirect to paricular method.
I tried below code. When I hit ../menumanager.do?method=adduser it is going to last method of action class.
<action name="menumanager" method="adduser" class="X.Action">
<result name="login">Some JSP</result>
<result name="logout">Some JSP</result>
</action>
<action name="menumanager" method="deleteuser" class="X.Action">
<result name="login">Some JSP</result>
<result name="logout">Some JSP</result>
</action>
Anyone has successfully used Struts conversation plugin?
The documentation says that fields annotated with #ConversationField annotation in Action class is supposed to be retained for the entire conversation, which is not happening.
Can you help me with any other plugin for Struts 2 for developing wizard-like application?
Following is my structure of struts.xml
<package name="wstest" namespace="/wstest" extends="struts-conversation-default">
<action name="*" class="com.bla.bla.WebServiceTestController" method="{1}">
<result name="upload">/WEB-INF/content/wstest/UploadWSDL.jsp</result>
<result name="selectoperation">
/WEB-INF/content/wstest/selectoperation.jsp
</result>
</action>
</package>
<action name="AddedPaid" class="iland.payment.SupplierPaidAction" method="insert">
<result name="success" type="redirect">ShowPaid</result>
<result name="input">/pages/payment/addToPay.jsp</result>
<result name="login">/pages/login.jsp</result>
</action>
<action name="ShowPaid" class="iland.payment.SupplierPaidAction" method="fetchAllByfk">
<result name="success">/pages/paid/showPaidDetails.jsp</result>
<result name="input">/pages/payment/ShowPay.jsp</result>
<result name="login">/pages/login.jsp</result>
</action>
Here AddedPaid Action is used to add form data in to database.
After adding data in to database I am redirecting result to ShowPaid action.
This is working properly.
Now I want whenever I redirect AddedPaid action to ShowPaid.
ShowPaid must show data of perticular supplierPaymentId for which I have added data in AddedPaid.
After redirect it is howing url
http://localhost:8082/ClothStore/ShowPaid
I want
http://localhost:8082/ClothStore/ShowPaid?supplierPaymentId=4
It's strange, usually people have 2 and want 1 :)
Btw, since you are using PostRedirectGet, you need to manually pass the parameter in Struts configuration.
Assuming you have a variable named supplierPaymentId with getter and setter, it's achievable like follows:
<action name="AddedPaid" class="iland.payment.SupplierPaidAction" method="insert">
<result name="success" type="redirectAction">
<param name="actionName">ShowPaid</param>
<param name="supplierPaymentId">${supplierPaymentId}</param>
</result>
<result name="input">/pages/payment/addToPay.jsp</result>
<result name="login">/pages/login.jsp</result>
</action>
Also use redirectAction instead of redirect, that is meant to be used to redirect to external URLs or non-Action URLs
First of all use redirectAction result instead of redirect to redirect to another action.
And use param tag to add parameters in your result configuration.
<result type="redirectAction">
<param name="actionName">ShowPaid</param>
<param name="supplierPaymentId">${supplierPaymentId}</param>
</result>
Note you need to have getter/setter for supplierPaymentId in your action class.
Hi We are developing a Struts2Portlet Application in WebSpherePortal6.0.1. In my application I want to redirect to another portlet page after fullfilling the validations in my struts action class.How to achieve it. Please help me.
Thanks in Advance.
I have done some R&D to fix this issue,finally i found a solution.We cant call/redirect the portal page from struts2Portlet Action class.We can have to give a result type in strut action class,then we have to configure the action in the result.
<action name="view" class="com.ibm.rock.ViewAction" method="prepareview">
<result name="view">*/view/viewportalpage.action*</result>
</action>
<action name="viewportalpage" class="com.ibm.rock.ViewAction" method="prepareview">
<result name="preview">/_Rock/jsp/html/Preview.jsp</result>
</action>
Synatax:
<result name="success">*/Namespace/view.action*</result>
<action name="view" class="com.ibm.rock.ViewAction" method="prepareview">
<result name="preview">/_Rock/jsp/html/Preview.jsp</result>
</action>
i have a problem, i have my login with Strits2, Tiles2 and Struts xml validations, when i run my webapp the first page is the login and the struts2 xml validator send me the error, how do i tell that for the first time do not validate until submit?
<action name="loginPage" class="com.webapp.login.action.LoginAction">
<result name="input" type="tiles">loginPage</result>
<result name="success" type="tiles">loginPage</result>
</action>
Whenever you want to go to a "blank form", you should execute the input() method of your Action. This tells Struts 2 that you do not want to perform any validation for the action:
<action name="loginPage" class="com.webapp.login.action.LoginAction"
method="input">
<result name="input" type="tiles">loginPage</result>
<result name="success" type="tiles">loginPage</result>
</action>
Then, you should submit your login form to another action definition that executes the default action execute(). Struts 2 will then try to perform Action validation:
<action name="loginPageSubmit" class="com.webapp.login.action.LoginAction">
<result name="input" type="tiles">loginPage</result>
<result name="success" type="tiles">loginPage</result>
</action>