f:param returns null

UI Components for JSF
Post Reply
MrNotSoWebDevelop
Posts: 9
Joined: 06 Nov 2014, 12:34

21 Nov 2014, 21:45

Hi, I have a data table with the following code. Basically you upload a picture and it appears on the list, you can enter the picture and the button redirects you to the Image.xhtml. When the image is uploaded it shows a minimized picture of it, but when I click enter the f:param send null values to the method. No idea why is this happening, would appreciate some help. Sincerely.


Home.xhtml

Code: Select all

<div class="dataTable">
			<h:form id="imageList">
				<p:dataTable var="img" value="#{imageView.images}" rowKey="#{img.id}" rows="10" lazy="true" paginator="true">
					<p:column width="50" headerText="Id">
						<h:outputText value="#{img.id}"/>
					</p:column>
					<p:column headerText="Image">
						<p:graphicImage style="width:80px; height:80px" value="#{imageView.tempImg}">
							<f:param name="something" value="#{img.id}" />
						</p:graphicImage>
					</p:column>
					<p:column width="200" headerText="Name">
						<h:outputText value="#{img.name}"/>
					</p:column>
					<p:column width="200" headerText="Edit">
						<h:commandButton value="Enter"  action="Image?faces-redirect=true" />
					</p:column>
				</p:dataTable>


			</h:form>
		</div>
Image.xhtml

Code: Select all

<h:form onsubmit="#{getComponents.getAllComponents()}" id="home">
		<div>
			<p:graphicImage  id="tempImg" value="#{imageView.tempImg}" />
		</div>
</h:form>
ImageView.java

Code: Select all

public StreamedContent getTempImg() throws IOException
	{
		FacesContext context = FacesContext.getCurrentInstance();
		
        if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
            // So, we're rendering the HTML. Return a stub StreamedContent so that it will generate right URL.
            return new DefaultStreamedContent();
        }
        else {
            // So, browser is requesting the image. Return a real StreamedContent with the image bytes.
            String imgId = context.getExternalContext().getRequestParameterMap().get("something");
        System.out.println(imgId);
        System.out.println("done");
            Image image = ((ImageLazyLoad) images).getRowData(imgId);
            tempImg= new DefaultStreamedContent(new ByteArrayInputStream(image.getByteData()));
            return this.tempImg;
        }
	}

MrNotSoWebDevelop
Posts: 9
Joined: 06 Nov 2014, 12:34

24 Nov 2014, 11:34

600 views , no one?

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 62 guests