I am trying to dynamically display an image using this code:
<p:graphicImage value="#{bean.imageSrc}" >
<f:param name="image_id" value="#{bean.id}"/>
</p:graphicImage>
The code for the getImageSrc method in the backing bean is:
String image_id = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("image_id");
But for some reason image_id is always being set to null in the corresponding getImageSrc method. The method is also called more than once. When I use a commandLink the parameter is retrieved correctly. Any idea what is going on?
Thanks.
Problem with graphicImage and f:param
- bumble.bee
- Posts: 723
- Joined: 29 Sep 2010, 21:39
- Location: United States
As far as the getter method being called more than once, see this thread:
http://primefaces.prime.com.tr/forum/vi ... f=3&t=5239
As far as associating arbitrary data with a component, you might want to use attributes since they are accessible via a map on the server. Just swap f:param with f:attribute in the facelets page. The server code would then look like:
Bean code:
where formId is the ID of the form and componentId is the ID of the graphicImage.
The f:param tag is treated differently in a command component such as a commandButton or commandLink. In a command component the parameter is added to the request map. Otherwise it isn't.
Make sure to read the user guide on how to use the PrimeFaces graphicImage tag since it is different than the JSF graphicImage tag. See
http://www.primefaces.org/documentation.html
http://primefaces.prime.com.tr/forum/vi ... f=3&t=5239
As far as associating arbitrary data with a component, you might want to use attributes since they are accessible via a map on the server. Just swap f:param with f:attribute in the facelets page. The server code would then look like:
Bean code:
Code: Select all
UIComponent component = FacesContext.getCurrentInstance().getViewRoot().findComponent("formId:componentId");
Map attributes = component.getAttributes();
String imageId = (String)attributes.get("image_id");
The f:param tag is treated differently in a command component such as a commandButton or commandLink. In a command component the parameter is added to the request map. Otherwise it isn't.
Make sure to read the user guide on how to use the PrimeFaces graphicImage tag since it is different than the JSF graphicImage tag. See
http://www.primefaces.org/documentation.html
-
- Information
-
Who is online
Users browsing this forum: No registered users and 57 guests