Hi Dave,
no I'm not using Spring.
Dave Newton
<davelnewton@gmai
l.com> Per
Struts Users Mailing List
27/07/12 16.06 <[email protected]>
CC
Per favore, Oggetto
rispondere a Re: RE: Clear field error on submit
"Struts Users
Mailing List"
<[email protected]
he.org>
Are you defining your actions in the Spring config file (which isn't
necessary)?
If so, make sure they're scoped "prototype".
Dave
On Fri, Jul 27, 2012 at 10:03 AM, <[email protected]> wrote:
> Yes. I think this is the problem.
> Struts2 "Stream result type" doesn't refresh page.
>
> Some suggestions?
> Thanks
>
>
>
>
> Puneet Babbar 2
> <pbabbar2@sapient
> .com>
Per
> Struts Users Mailing List
> 27/07/12 15.52 <[email protected]>
>
CC
>
> Per favore,
Oggetto
> rispondere a RE: Clear field error on submit
> "Struts Users
> Mailing List"
> <[email protected]
> he.org>
>
>
>
>
>
>
> My take on your problem - Your page isn't getting refreshed so the field
> errors remain.
>
> Regards
>
> Puneet Babbar
>
>
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]]
> Sent: Friday, July 27, 2012 7:18 PM
> To: Struts Users Mailing List
> Subject: Clear field error on submit
>
>
> Hello.
>
> This is a Struts 2 example to show the use of custom result type to
> download file.
>
> I have in jsp :
> - 1 password textfield
> - 1 submit button
>
> If I push submit button without insert a password I correctly obtain a
> field error "Field required!".
> Then If I set "XYZ" password (correct password), I correctly download
> "downloadfile.txt" but
> field error remain.
>
> Why?
>
> Thanks
>
> DownloadAction.java
>
> package com.example.common.action;
>
> import java.io.File;
> import java.io.FileInputStream;
> import java.io.InputStream;
> import com.opensymphony.xwork2.ActionSupport;
>
> public class DownloadAction extends ActionSupport{
>
> private InputStream fileInputStream;
> private String password;
>
> public InputStream getFileInputStream() {
> return fileInputStream;
> }
>
> public String getPassword() {
> return password;
> }
>
> public void setPassword(String password) {
> this.password = password;
> }
>
> public void validate() {
> if ( (password==null) ||
> (password.trim().equals
> ("")) ) {
> addFieldError
("password",
> "Field
> required!");
> }
> if (!password.equals("XYZ") {
> addFieldError
("password",
> "Wrong
> password!");
> }
> }
>
> public String execute() throws Exception {
> fileInputStream = new FileInputStream(new File
> ("C:\\downloadfile.txt"));
> return SUCCESS;
> }
> }
>
> downloadPage.jsp
>
>
> <%@ taglib prefix="s" uri="/struts-tags" %>
> <html>
>
> <body>
> <h1>Struts 2 download file example</h1>
> <s:form action="download" method="POST">
> <p><s:textfield name="password" /></p>
> <p><s:submit id="submitButton"/></p>
> </s:form>
>
> </body>
> </html>
>
> struts.xml
>
> <?xml version="1.0" encoding="UTF-8" ?>
> <!DOCTYPE struts PUBLIC
> "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
> "http://struts.apache.org/dtds/struts-2.0.dtd">
>
> <struts>
>
> <constant name="struts.devMode" value="true" />
>
> <package name="default" namespace="/" extends="struts-default">
> <action name="">
> <result name="success">pages/downloadPage.jsp</result>
> </action>
>
> <action name="download"
> class="com.example.common.action.DownloadAction">
> <interceptor-ref name="defaultStack" />
> <result name="success" type="stream">
> <param
> name="contentType">application/octet-stream</param>
> <param name="inputName">fileInputStream</param>
> <param
> name="contentDisposition">attachment;filename="fileABC.txt"</param>
> <param name="bufferSize">1024</param>
> </result>
> </action>
> </package>
>
> </struts>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]