jsf 2 - primefaces graphicImage f:param doesn't work -
this question has answer here:
i have jsf:
<p:graphicimage value="#{chatview.userphoto}"> <f:param name="userid" value="#{user.id}"/> </p:graphicimage> user.id valid have checked.
and bean:
@managedbean @viewscoped public class chatview extends baseview { /* * injecting managed beans in each other * http://balusc.blogspot.com/2011/09/communication-in-jsf-20.html#injectingmanagedbeansineachother */ @managedproperty("#{chatusers}") private chatusers users; public streamedcontent getuserphoto() { // there output {} system.out.println(facescontext.getcurrentinstance().getexternalcontext().getrequestparametermap()); return new defaultstreamedcontent(); } } but have empty map in debug output requestparametermap. idea why?
updated:
i created simple project such pom.xml:
<?xml version="1.0" encoding="utf-8"?> <project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <groupid>grim</groupid> <artifactid>grim</artifactid> <version>1.0-snapshot</version> <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <project.build.sourceencoding>utf-8</project.build.sourceencoding> <version.jboss.bom>9.0.0.cr1</version.jboss.bom> <version.primefaces>5.2</version.primefaces> <version.atmosphere>2.3.1</version.atmosphere> <version.jboss.logging>3.2.1.final</version.jboss.logging> </properties> <dependencymanagement> <dependencies> <dependency> <groupid>org.wildfly.bom</groupid> <artifactid>jboss-javaee-7.0-wildfly-with-tools</artifactid> <version>${version.jboss.bom}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencymanagement> <dependencies> <!-- first declare apis depend on , need compilation. of them provided jboss wildfly --> <!-- import cdi api, use provided scope api included in jboss wildfly --> <dependency> <groupid>javax.enterprise</groupid> <artifactid>cdi-api</artifactid> <scope>provided</scope> </dependency> <!-- import common annotations api (jsr-250), use provided scope api included in jboss wildfly --> <dependency> <groupid>org.jboss.spec.javax.annotation</groupid> <artifactid>jboss-annotations-api_1.2_spec</artifactid> <scope>provided</scope> </dependency> <!-- import jax-rs api, use provided scope api included in jboss wildfly --> <dependency> <groupid>org.jboss.resteasy</groupid> <artifactid>jaxrs-api</artifactid> <scope>provided</scope> </dependency> <!--hibernate--> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-core</artifactid> <scope>provided</scope> </dependency> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-entitymanager</artifactid> <scope>provided</scope> </dependency> <!-- import jpa api, use provided scope api included in jboss wildfly --> <dependency> <groupid>org.hibernate.javax.persistence</groupid> <artifactid>hibernate-jpa-2.1-api</artifactid> <scope>provided</scope> </dependency> <!-- import ejb api, use provided scope api included in jboss wildfly --> <dependency> <groupid>org.jboss.spec.javax.ejb</groupid> <artifactid>jboss-ejb-api_3.2_spec</artifactid> <scope>provided</scope> </dependency> <!-- jsr-303 (bean validation) implementation --> <!-- provides portable constraints such @email --> <!-- hibernate validator shipped in jboss wildfly --> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-validator</artifactid> <scope>provided</scope> <exclusions> <exclusion> <groupid>org.slf4j</groupid> <artifactid>slf4j-api</artifactid> </exclusion> </exclusions> </dependency> <!-- import jsf api, use provided scope api included in jboss wildfly --> <dependency> <groupid>org.jboss.spec.javax.faces</groupid> <artifactid>jboss-jsf-api_2.2_spec</artifactid> <scope>provided</scope> </dependency> <!-- declare tools needed --> <!-- annotation processor generate jpa 2.0 metamodel classes typesafe criteria queries --> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-jpamodelgen</artifactid> <scope>provided</scope> </dependency> <!-- annotation processor raising compilation errors whenever constraint annotations incorrectly used. --> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-validator-annotation-processor</artifactid> <scope>provided</scope> </dependency> <!-- needed running tests (you may use testng) --> <dependency> <groupid>junit</groupid> <artifactid>junit</artifactid> <scope>test</scope> </dependency> <!-- optional, highly recommended --> <!-- arquillian allows test enterprise code such ejbs , transactional(jta) jpa junit/testng --> <dependency> <groupid>org.jboss.arquillian.junit</groupid> <artifactid>arquillian-junit-container</artifactid> <scope>test</scope> </dependency> <dependency> <groupid>org.jboss.arquillian.protocol</groupid> <artifactid>arquillian-protocol-servlet</artifactid> <scope>test</scope> </dependency> <!-- import servlet api, use provided scope api included in jboss wildfly. --> <dependency> <groupid>org.jboss.spec.javax.servlet</groupid> <artifactid>jboss-servlet-api_3.1_spec</artifactid> <scope>provided</scope> </dependency> <!--primefaces--> <dependency> <groupid>org.primefaces</groupid> <artifactid>primefaces</artifactid> <version>${version.primefaces}</version> </dependency> <!--atmosphere--> <dependency> <groupid>org.atmosphere</groupid> <artifactid>atmosphere-runtime</artifactid> <version>${version.atmosphere}</version> <exclusions> <exclusion> <artifactid>slf4j-api</artifactid> <groupid>org.slf4j</groupid> </exclusion> </exclusions> </dependency> <!--jboss logging--> <dependency> <groupid>org.jboss.logging</groupid> <artifactid>jboss-logging</artifactid> <version>${version.jboss.logging}</version> <scope>provided</scope> </dependency> </dependencies> </project> view:
@managedbean @viewscoped public class testview { public streamedcontent getimg() { facescontext context = facescontext.getcurrentinstance(); if (context.getcurrentphaseid() == phaseid.render_response) { // so, we're rendering html. return stub streamedcontent generate right url. return new defaultstreamedcontent(); } else { // so, browser requesting image. return real streamedcontent image bytes. string studentid = context.getexternalcontext().getrequestparametermap().get("shashistid"); shashist student = shashistservice.find(long.valueof(studentid)); return new defaultstreamedcontent(new bytearrayinputstream(student.getphoto())); } } } and xhtml:
<?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://xmlns.jcp.org/jsf/html" xmlns:ui="http://xmlns.jcp.org/jsf/facelets" xmlns:p="http://primefaces.org/ui" xmlns:f="http://xmlns.jcp.org/jsf/core"> <f:view> <h:outputlabel value="hello, world"/> <p:graphicimage value="#{testview.img}"> <f:param value="1" name="s"/> </p:graphicimage> </f:view> </html> but anyway empty request parameter map in debug output.
thank answer https://stackoverflow.com/a/25425111/836701 found solution. problem in @viewscope should @sessionscope getting parameters f:param.
Comments
Post a Comment