Hello Andreas,
I included the phase listener as you instructed, and it does intercept
the rendering. However, I can't seem to actually DO something to
interrupt the request
What does work is to send a redirect to another page, but then I can't
set the error messages :P
I changed your code and it's now like this:
/*-----------------------**/
public void beforePhase(PhaseEvent event) {
                // RENDER_RESPONSE Phase
                try {
                        //                      if 
(event.getPhaseId().equals(PhaseId.RENDER_RESPONSE)) {

                        FacesContext fc = FacesContext.getCurrentInstance();
                        HttpServletRequest req = (HttpServletRequest)
fc.getExternalContext().getRequest();
                        String message = null;
                        if (req instanceof MultipartRequestWrapper) {
                                MultipartRequestWrapper mpreq = 
(MultipartRequestWrapper) req;
                                Object m = 
mpreq.getAttribute("org.apache.myfaces.custom.fileupload.exception");
                                FileItem ff = 
mpreq.getFileItem("formulario:documento");//the file
being uploaded
                                if (m != null) {
                                        message = m.toString().toLowerCase();
                                }
                                if ((message != null) && 
(message.indexOf("sizelimitexceeded") > -1)) {
                                        
MessageUtils.addMessage(FacesMessage.SEVERITY_ERROR,
"msg_FileSizeLimitExceeded", null);
                                } else {
                                        NavigationHandler nh = 
fc.getApplication().getNavigationHandler();
                                        if (ff != null) {
                                                if (ff.getSize() > 2097152) {
                                                        ...
                                                        
MessageUtils.addMessage(FacesMessage.SEVERITY_ERROR, "MSG1", null);
                                                }
                                        } else {
                                                
MessageUtils.addMessage(FacesMessage.SEVERITY_ERROR, "MSG2", null);
                                                HttpServletResponse resp = 
(HttpServletResponse)
fc.getExternalContext().getResponse();
                                                resp.sendRedirect("...same 
page...");
                                        }
/*-----------------------**/
I noticed that this exception attribute never gets set, so I use the
FileItem to decide what to do. If it's below the size limit, ff is not
null. If it exceeds the limit, the FileItem is then null.
How can I tell Faces to stop trying to process this request and go
back to the previous page, while maintaining the error messages?
Thanks,
--
Khristian Alexander Schönrock
http://derkosak.blogspot.com - Meu blógue!



On Thu, Nov 19, 2009 at 5:41 AM,  <[email protected]> wrote:
> Hello Khristian,
>
> you have to get the error in the phase listener (Render Phase in before
> Phase).
>
> public class myPhaseListener implements PhaseListener {
>
> ...
>
>        public void beforePhase(PhaseEvent event) {
>
>                // RENDER_RESPONSE Phase
>                if (event.getPhaseId().equals(PhaseId.RENDER_RESPONSE)){
>
>                        //error fileupload ?
>                        Object req =
> context.getExternalContext().getRequest();
>                        String message=null;
>                        if (req instanceof MultipartRequestWrapper) {
>                                MultipartRequestWrapper mpreq =
> (MultipartRequestWrapper) req;
>                                Object m =
> mpreq.getAttribute("org.apache.myfaces.custom.fileupload.exception");
>                                if(m!=null)
> message=m.toString().toLowerCase();
>                                if (message!= null &&
> message.indexOf("sizelimitexceeded")>-1) {
>
> MessageUtils.addMessage(FacesMessage.SEVERITY_ERROR,"msg_FileSizeLimitExceeded",null);
>                                }
>                        }
>
>
>
>                }
>
>        }
>
> }
>
>
> best regards
> Andreas
>
>
>
>
> Khristian <[email protected]>
>
> 18.11.2009 20:28
> Bitte antworten an
> "MyFaces Discussion" <[email protected]>
>
>
> An
> [email protected]
> Kopie
>
> Thema
> [fileupload] need help dealing with large files!
>
>
>
>
>
>
> Hello,
> I'm trying to limit the size of files users can upload in my app, but
> I can't figure out what to do when a user tries to upload some file
> larger than the limit.
> The limit is set in the web.xml file. Any file smaller than the limit
> is handled without problem; when I try to upload a larger file, I
> never get a response (not a exception, nor error, nor timeout).
> How can I handle this situation correctly?
> TIA,
> --
> Khristian Alexander Schönrock
> http://derkosak.blogspot.com - Meu blógue!
>
>

Reply via email to