Tiles2 + Struts2 xml validation - struts2

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>

Related

Input attribuite on the action element equivalent in struts2

What is the equivalent in Struts2 for input attribute on the action element?
<action
path="/testAction"
type="com.test.TestAction"
name="test"
scope="request"
input="/pages/test.jsp">
<forward name="success" path="/test.do"/>
<forward name="error" path="/pages/welcome.jsp"/>
</action>

How to redirect with parameter

<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.

Struts 2 Double form submit - why?

I have a few simple actions:
<action name="edit" class="EditAction">
<result>/WEB-INF/jsp/form.jsp</result>
</action>
<action name="preview" class="PreviewAction">
<result>/WEB-INF/jsp/preview.jsp</result>
<result name="input">/WEB-INF/jsp/form.jsp</result>
</action>
<action name="store" class="StoreAction">
<result>/WEB-INF/jsp/confirmation.jsp</result>
<result name="input">/WEB-INF/jsp/preview.jsp</result>
</action>
<global-results>
<result name="invalid.token">/WEB-INF/jsp/invalidToken.jsp</result>
</global-results>
and classic scenario: user interacts with text inputs, press Save, view a Preview page and press Save on it to save data, without double-press buttons, refreshing page etc.
Why double submit can occurs in such situation?
Even I had double form submit problem in struts2 on browser refresh. I resolved the problem using post-redirect-get pattern to avoid double or duplicate form submissions. It happens because hitting "refresh page" for a reponse based on a POST request will re-issue the POST request.It repeats what you did to reach current page even for double button press. It happens for both success and error in struts2.
I suggets you to make this change where-ever necessary.
<action name="onStoreRedirect">
<result name="success" type="redirect">store</result>
</action>
<action name="store" class="StoreAction">
<result>/WEB-INF/jsp/confirmation.jsp</result>
<result name="input">/WEB-INF/jsp/preview.jsp</result>
</action>

I want to call/redirect to a Portal page from Struts2Portlet 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>

Please explain Action in Struts 2.0 XML file

<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

Resources