Programatically GraphicImage and other components

UI Components for JSF
Post Reply
lmmoreira
Posts: 60
Joined: 08 Jul 2010, 14:15

23 Sep 2010, 20:48

Hi, I have got to create some Dynamic components.

Like Joomla my software has to add some imagens that are added on the database.

I can be one or ten.

For Example, to create an TextBox I do It:

Code: Select all

HtmlInputText text1 = new HtmlInputText();
text1.setValue("TEST");
oBanda.getChildren().add(text1);
Right?

On Prime GraphicImage I have got this:

Code: Select all

GraphicImage img = new GraphicImage();
img.setValue(new DefaultStreamedContent(new ByteArrayInputStream(imagem.getFigura()), ""));
oBanda.getChildren().add(img);
Where imagem.getFigura() is a byte array from database, (Hibernate).

I dont get any error on the debug, but have got an Nullpointer at the rendering page.

Code: Select all


java.lang.NullPointerException
        at org.primefaces.component.graphicimage.GraphicImageRenderer.getImageSrc(GraphicImageRenderer.java:59)
        at org.primefaces.component.graphicimage.GraphicImageRenderer.encodeEnd(GraphicImageRenderer.java:38)
        at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:879)
        at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:308)
        at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:101)

How wold I create prime components programatically?

Thank you
Tomcat 7 + jsf-api - 2.0.3-SNAPSHOT + Primefaces 2.1

lmmoreira
Posts: 60
Joined: 08 Jul 2010, 14:15

23 Sep 2010, 21:54

Just more details.

I am getting the error at the method

protected String getImageSrc(FacesContext facesContext, GraphicImage image), line image.getValueExpression("value"); of the GraphicImageRenderer.java

Sounds Like It is because I am not configureing the property setValueExpression.

But what should I put here, once the value of my component is the stream I passed to value
Tomcat 7 + jsf-api - 2.0.3-SNAPSHOT + Primefaces 2.1

User avatar
MISS_DUKE
Posts: 273
Joined: 08 Aug 2010, 05:52

24 Sep 2010, 04:36

One of the easiest way to dynamically "add" component is having the markup as follows and defining your isRendered() method in your backing bean.

Code: Select all

<h:outputText rendered="{myBean.rendered}"/>
JSF implementation: Mojarra V2.1.7
JSF component library: Primefaces V3.1.1
Server: GlassFish Open Source Edition V3.1.1 (build 12)

lmmoreira
Posts: 60
Joined: 08 Jul 2010, 14:15

24 Sep 2010, 13:35

Sorry friend, this way I would have to add one hundred images for example.

Just guessing how many images the user will put is not the best option

Thank you for the answer
Tomcat 7 + jsf-api - 2.0.3-SNAPSHOT + Primefaces 2.1

lmmoreira
Posts: 60
Joined: 08 Jul 2010, 14:15

27 Sep 2010, 20:50

shamefull bump
Tomcat 7 + jsf-api - 2.0.3-SNAPSHOT + Primefaces 2.1

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Google [Bot] and 58 guests