p:imageswitch enhancement

UI Components for JSF
Post Reply
timotius_pamungkas
Posts: 117
Joined: 19 May 2010, 03:50

29 Jun 2010, 02:50

Hi, I have some issue for p:imageswitch:

On tomcat 6.0.26, primefaces 2.1RC1, mojarra 2, this code

Code: Select all

                <p:imageSwitch effect="FlyOut" slideshowAuto="false">
			<ui:repeat var="imagePath" value="#{testBean.listTest}">
				<p:graphicImage value="#{imagePath}" />
			</ui:repeat>
		</p:imageSwitch>
produce an error

Code: Select all

exception

javax.servlet.ServletException: com.sun.faces.facelets.component.UIRepeat cannot be cast to org.primefaces.component.graphicimage.GraphicImage
	javax.faces.webapp.FacesServlet.service(FacesServlet.java:325)
	org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)

root cause

java.lang.ClassCastException: com.sun.faces.facelets.component.UIRepeat cannot be cast to org.primefaces.component.graphicimage.GraphicImage
	org.primefaces.component.imageswitch.ImageSwitchRenderer.encodeMarkup(ImageSwitchRenderer.java:90)
	org.primefaces.component.imageswitch.ImageSwitchRenderer.encodeEnd(ImageSwitchRenderer.java:40)
	javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:878)
	javax.faces.component.UIComponent.encodeAll(UIComponent.java:1620)
	javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
	javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:848)
	javax.faces.component.UIComponent.encodeAll(UIComponent.java:1613)
	javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
	javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
	com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:380)
	com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:126)
	javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:273)
	com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:127)
	com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
	com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
	javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
	org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)

And this won't work too. If i have all 800px * 600px images, using "width" on p:graphicImage doesn't work, so this code basically give a imageSwitch with all images on their original size:

Code: Select all

<p:imageSwitch effect="FlyOut">
    <p:graphicImage value="image1.jpg" width="400"/>
    <p:graphicImage value="image2.jpg" width="400"/>
</p:imageSwitch>

Thanks a lot
Tomcat 7.0.25
Mojarra 2.1.6
Primefaces 3.1, 3.2
Firefox 10 and IE 7/IE 8

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

30 Jun 2010, 11:53

Can you try c:forEach insteadof ui:repeat?

timotius_pamungkas
Posts: 117
Joined: 19 May 2010, 03:50

02 Jul 2010, 06:38

c:forEach works fine. Thanks a lot
Tomcat 7.0.25
Mojarra 2.1.6
Primefaces 3.1, 3.2
Firefox 10 and IE 7/IE 8

User avatar
edwini
Posts: 4
Joined: 23 Sep 2010, 21:36

28 Sep 2010, 01:12

c:forEach works fine. Thanks a lot
Hi, timotius_pamungkas can you please tell how do you make <p:imageSwitch make works? It's no switches for me, it's stay one static image.
Net Beans 6.9 | GlassFish 3.1 | Java Developer

jsfdvp
Posts: 3
Joined: 20 Oct 2010, 18:48

21 Oct 2010, 03:41

Hi, i'm trying to execute a simple example (from showcase) and a got the same erro. I tryied c:foreach and got the same error!

Plz, could anyone help me?

I'm using: jsf 1.2, primefaces 1.1, netbeans 6.9, firefox 3.6, glassfish v2 (and glassfish v3)

jsfdvp
Posts: 3
Joined: 20 Oct 2010, 18:48

21 Oct 2010, 03:45

the error when using c:forEach:

Code: Select all

<p:imageSwitch effect="fade">
                                    <c:forEach items="#{imageSwitchBean.images}" var="image">
                                        <p:graphicImage value="/images/#{image}" />
                                    </c:forEach>>
                                </p:imageSwitch>
com.sun.facelets.compiler.UIInstructions cannot be cast to org.primefaces.component.graphicimage.GraphicImage

the erros using ui:repeat:

Code: Select all

<p:imageSwitch effect="fade">
                                    <ui:repeat value="#{imageSwitchBean.images}" var="image">
                                        <p:graphicImage value="/images/#{image}" />
                                    </ui:repeat>
                                </p:imageSwitch>
com.sun.facelets.component.UIRepeat cannot be cast to org.primefaces.component.graphicimage.GraphicImage

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

21 Oct 2010, 09:58

Try new ImageSwitch of 2.2.RC, it supports ui:repeat, live demo;

http://www.primefaces.org/showcase/ui/imageSwitch.jsf

jsfdvp
Posts: 3
Joined: 20 Oct 2010, 18:48

21 Oct 2010, 23:23

I need to use the library mojarra 1.2 (JSF 1.2). When I add the 2.2 primefaces the project does not run! How do I configure the project with the libs primefaces jsf 2.2 and 1.2? What can I enter in web.xml? Thanks.

I tried a new project with, glassfish v3, jsf 2, primefaces 2.2 and the following code:

Code: Select all

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
        <title>Facelet Title</title>
        <p:resources/>
    </h:head>
    <h:body>
        <div align="center">
            <p:imageSwitch effect="FadeIn">
                <ui:repeat value="#{imageSwitchBean.images}" var="img">
                    <p:graphicImage url="/images/#{img}"/>
                </ui:repeat>
            </p:imageSwitch>
        </div>
    </h:body>
</html>
Bean:

Code: Select all

@ManagedBean
@RequestScoped
public class ImageSwitchBean {
     private List<String> images;

    public ImageSwitchBean() {
        images = new ArrayList<String>();
        images.add("nature1.jpg");
        images.add("nature2.jpg");
        images.add("nature3.jpg");
        images.add("nature4.jpg");
    }

    public List<String> getImages() {
        return images;
    }
}
Web.xml

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <servlet>
        <servlet-name>Resource Servlet</servlet-name>
        <servlet-class>org.primefaces.resource.ResourceServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Resource Servlet</servlet-name>
        <url-pattern>/primefaces_resource/*</url-pattern>
    </servlet-mapping>
    <context-param>

        <param-name>com.sun.faces.allowTextChildren</param-name>

        <param-value>true</param-value>
    </context-param>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>faces/index.xhtml</welcome-file>
    </welcome-file-list>
</web-app>
and i got this error, again:

com.sun.faces.facelets.component.UIRepeat cannot be cast to org.primefaces.component.graphicimage.GraphicImage

any other suggestion?

Thanks!

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 43 guests