Primeface 3.0.1 + p:graphicImage + @ViewAccessScope (CODI)

UI Components for JSF
Post Reply
tkernstock
Posts: 65
Joined: 29 Jun 2010, 14:39
Location: Vienna, Austria

16 Jan 2012, 19:25

Hi guys,

I try to upgrade from Primefaces version 2.2.1 to version 3.0.1.

The Problem:

I'm using the DynaImage which doen't work anymore. I have a form with:

Code: Select all

<p:graphicImage id="portrait" value="#{portraitPage.foto}" cache="false" width="140px" height="185px" title="#{msgs.profil_portrait}" />
and I have a bean with @ViewAccesScope from MyFacesCODI that delivers the StreamedContent:

Code: Select all

@Named
@ViewAccessScoped
public class PortraitPage extends AbstractProfilePage {
	
       public StreamedContent getFoto() {
		if((fotoStream==null || fotoStream.getStream()==null)){
			fotoStream= new DefaultStreamedContent(serviceXY.getByteArrayInpuStream());
			if(fotoStream==null || fotoStream.getStream()==null)
					fotoStream= new DefaultStreamedContent(getNoPortrait());
		} else {
			try {
				fotoStream.getStream().reset();
			} catch (IOException e) {}
		}
		return fotoStream;
	}
}
I receive an errormessage in the log =>SCHWERWIEGEND: Error in streaming dynamic resource.

When I change @ViewAccessScope to @SessionScope the image is displayed.

I remember that a similar problem occured in version 2.2 RC2 which was related to parameters in the URL and was fixed here:
http://code.google.com/p/primefaces/iss ... il?id=1543


Has anybody found a solution for that problem in version 3.0.1 ? Is there a fix or a patch somewhere ?

best reagrds
Thomas
Using: Eclipse 2020-06, Java 8, Primefaces 8, Omnifaces 3.6.1, Payara Server 5.201, Deltaspike 1.8.2

User avatar
kwintesencja
Posts: 316
Joined: 08 Feb 2010, 20:33
Location: Brazil

16 Jan 2012, 19:28

Hi Thomas,

It works with JSF @ViewScoped?
Att,

--

Rafael Mauricio Pestano


Primefaces 5.x + JavaEE7(Glassfish 4.x and Wildfly 8)
Conventions Framework
Blog
@realpestano

tkernstock
Posts: 65
Joined: 29 Jun 2010, 14:39
Location: Vienna, Austria

16 Jan 2012, 19:35

Hi Rafael,

thanx for the quick reply.
It works with JSF @ViewScoped?
No it doesn't work either. I checked it right now.

Besides I'm not using any faces scopes but only CDI scopes (including the codi scopes of course)
I see you are using CODI too - does it work for you somehow ?

br
Thomas
Using: Eclipse 2020-06, Java 8, Primefaces 8, Omnifaces 3.6.1, Payara Server 5.201, Deltaspike 1.8.2

User avatar
kwintesencja
Posts: 316
Joined: 08 Feb 2010, 20:33
Location: Brazil

16 Jan 2012, 19:57

tkernstock wrote:
Besides I'm not using any faces scopes but only CDI scopes (including the codi scopes of course)
I see you are using CODI too - does it work for you somehow ?

i'm not using DynaImage(and cannot test it now), i asked you just to see if its a CODI related bug or not... maybe you could file an issue here: http://code.google.com/p/primefaces/issues/ so PF team can take a look.
Att,

--

Rafael Mauricio Pestano


Primefaces 5.x + JavaEE7(Glassfish 4.x and Wildfly 8)
Conventions Framework
Blog
@realpestano

jlucasfs
Posts: 2
Joined: 05 Nov 2011, 21:36

28 Jan 2012, 15:03

I have a similar problem with primefaces 3.0 + spring 3.0
It's working only with annotations in my managed bean:
@Controller
@SessionScoped
if I use any other annotation, it doesn't work, the image doesn't display.
If there are more than one user, the images are merging....this is an error because a singleton scope is default in spring.
Anyone help me?

christian.fischer
Posts: 4
Joined: 29 Jan 2012, 18:21

29 Jan 2012, 23:00

You do not need @Controller
Works for me also only with @SessionScoped

For displaying more than one image, you should reset your datasource (ServiceXY.getRawData)
Roo 1.2.0.RELEASE
Spring 3
PrimeFaces 3.0.1

jlucasfs
Posts: 2
Joined: 05 Nov 2011, 21:36

14 Feb 2012, 05:57

I've resolved this problem.
this is my solution:
I created a MBean ('ImageBean') with annotations @Controller and @SessionScoped and the images attributes only.
My main MBean uses Imagebean by dependency injection, but here we use @Controller and @Scope("session").
That way resolved my problem (the spring's scope was singleton = default = before, I don't declared it).
I hope to help anyone.
thank you.

ps4os
Posts: 21
Joined: 24 Jun 2011, 03:15

17 Feb 2012, 14:26

As I see it's easy to solve. I read http://markmail.org/message/kuoredrgrpqnfwgl

I used the tip and for me some lines are enough.

Code: Select all

public class DynResourceHandlerWrapper extends ResourceHandlerWrapper {
    private ResourceHandler rh;

    public DynResourceHandlerWrapper(ResourceHandler handler) {
        rh = handler;
    }

    @Override
    public void handleResourceRequest(FacesContext context) throws IOException {
        String viewId = getViewId(context);

        if(viewId != null) {
            context.setViewRoot(context.getApplication().getViewHandler().createView(context, viewId));
        }

        rh.handleResourceRequest(context);
    }

    //enough for us
    private String getViewId(FacesContext context) {
        ExternalContext external = context.getExternalContext();
        String base = getApplicationUri(external);
        String viewId = context.getExternalContext().getRequestHeaderValuesMap().get("referer")[0].substring(base.length());

        //or
        //String url = ((HttpServletRequest) external.getRequest()).getRequestURL().toString();
        //String viewId = external.getRequestHeaderValuesMap().get("referer")[0].substring(url.lastIndexOf(external.getRequestServletPath()));

        if(!viewId.contains("?")) {
            return null;
        }
        return viewId.substring(0, viewId.lastIndexOf("?"));
    }

    public String getApplicationUri(ExternalContext external) {
        try {
            URI uri = new URI(external.getRequestScheme(), null, external.getRequestServerName(), external.getRequestServerPort(), external.getRequestContextPath(), null, null);
            return uri.toASCIIString();
        } catch (URISyntaxException e) {
            throw new FacesException(e);
        }
    }

    @Override
    public ResourceHandler getWrapped() {
        return rh;
    }
}
faces-config.xml

Code: Select all

<application><resource-handler>our.DynResourceHandlerWrapper</resource-handler></application>

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 43 guests