submit and load the same form using struts2 - struts2

I've a test.jsp which includes an html.using the following tag
<s:form action="showTrainingPage">
<s:include value="%{objBarcodeCertificationTaskForm.strTrainingPage}"></include>
<s:submit type="image" src="../../images/next.png"/>
</s:form>
The value is developed dynamically in action.
<action name="showTrainingPage" method="getTrainingDetails" class="certificationTask">
<result name="input" >test.jsp</result>
</action>
But this does not help. When i click on Next, it says the requested source is not available. Please let me know how can this be solved.

Related

Prevent re-execute action in struts

this is probably an old question, but I just couldn't find an answer anywhere...
is there any way to prevent re-execute action in struts (other than re-direct to another page) when user clicks the refresh or back button on the browser?
index.jsp
<form action='call_action'>
<input type='text' name='name'/>
<s:token name="token"></s:token>
</form>
In struts.xml
<action name="call_action" class="controller.ActionClass">
<interceptor-ref name="token" />
<interceptor-ref name="basicStack"/>
<result name="invalid.token">invalid_token.jsp</result>
<result name="success">signup.jsp</result>
</action>
add invalid_token.jsp in your project.if unfortunetly user clicked second time.it automatically forward to invalid_token.jsp Page.

Does anyone have any experience that interceptor(i18n) will cause no value during postback?

Assume I have this struts2 form
<s:form action="login" method="post">
<s:textfield key="login_name" name="login_name"/>
<s:submit></s:submit>
</s:form>
And also with this struts.xml setting
<constant name="struts.custom.i18n.resources" value="messageResource" />
<constant name="struts.devMode" value="true" />
<package name="login" namespace="/" extends="struts-default">
<action name="login" class="actions.index.index">
<interceptor-ref name="i18n"/>
<result name="LOGIN_SUCCESS">/Main.jsp</result>
<result name="LOGIN">/Login.jsp</result>
</action>
</package>
If I have added <interceptor-ref name="i18n"/> to the setting, login_name will have no value after form submitted; otherwise I can retrieve the value successfully.
If you want me to provide further detail, please just let me know. Thanks in advance!
You are adding only one interceptor for your action by doing so all other interceptors are not included. The default stack already includes i18n interceptor so no point to add it by yourself.

how to show error message on struts2 jquery dialog box

I have a form open in Struts2 jquery dialog box. When users submit this form, i want to show the Server Side error message (eg. Username exist,Please choose another) on this same open dialoguebox itself .
How can i do this? Any hint or suggestion! Please share.
index.jsp (on click of a button the below form will open)
`<s:actionerror/>
<s:form action="testError" id="form3" theme="simple"/>
<s:textfield name="quantity" value="1""/>
<s:form>
<sj:submit formId="form3" value="true"/>`
Action.java
public String execute()
{
addActionError("Error message is blah blah");
return ERROR;
}
Struts.xml
<action name="testError" class="com.Action">
<result name="error">index.jsp</result>
</action>
try this:
<s:if test="hasErrors()">
<sj:dialog title="error message">
<s:actionerror/>
</sj:dialog>
</s:if>

accept attribute is not working in <s:file> tag of struts2

I am trying to validate the content types of uploading files using accept attribute but it seem to be not working.
Here is my code.
<s:file theme="simple" name="fileUpload" accept="image/jpeg"/>
i also tried
<s:file theme="simple" name="fileUpload" accept="image/*"/>
Both are not working what could be the problem?
The HTML accept attribute is not supported in IE and Safari. You can define allowed mime types in struts.xml for you file upload action like that:
<action name="..." class="...">
<interceptor-ref name="defaultStack">
<param name="fileUpload.allowedTypes">image/jpeg</param>
</interceptor-ref>
<result>...</result>
</action>
See others parameters you can configure in fileUpload interceptor.

Struts2 token interceptor always fails

Im trying to make it so that once i submit this form i cannot hit the back button, but with the current configuration I cannot even get the page/form to load. I can't seem to figure out why "invalid.token" is always being triggered thus redirecting me to index.jsp no matter what I have the token tag in my form like im supposed to. If i use the "excludeMethods" filter and exclude View then my page loads but I can hit the back button freely so it still does not work properly. I have tried moving the interceptor-ref above and below my noLoginStack but it dosen't make a difference. Based on my debugging my actual java class isn't even being hit, so its failing before then. What am I doing wrong?
My action declaration:
<action name="viewAppointmentLetter" class="edu.ucr.c3.rsummer.controller.instructor.ManageAppointmentLetters">
<interceptor-ref name="noLoginStack"/>
<interceptor-ref name="token" />
<result name="invalid.token">/index.jsp</result>
<result name="error" type="redirectAction">index.do</result>
<result name="input">/instructor/assigned_appts.jsp</result>
<result name="view">/instructor/assigned_appts.jsp</result>
<result type="redirectAction">index.do</result>
</action>
My assigned_appts.jsp:
<s:form action="saveAppointmentLetter" onsubmit="return verifySubmit();">
<s:token name="token" />
.....
</s:form>
If its any clue I always get this in my console
WARN org.apache.struts2.util.TokenHelper - Could not find token name in params.
In struts2 the order of interceptor is very important. you should follow this order.
<interceptor-ref name="token"/>
<interceptor-ref name="noLoginStack"/>
USe TokenSession interceptor.Had to handle result by result name="invalid.token" in struts.xml in specific action.
The page from which your action is generated at that page you have to write <s:token> tag in the header

Resources