I see that primeface p:graphicImage in my form is causing a new windowId to be created with in the same browser tab.
All my beans are window scoped. @WindowScoped of Myface CODI.
Since my business logic is tied to the initial login, the environment variables are tied to the windowContext.
When p:graphicImage tries to access the bean with a new windowId/windowContext, the application is failing.
Is there a way to avoid this?
Here is my view file
<h:form enctype="multipart/form-data">
<p:messages />
<p:panelGrid style="width:75%;margin:5px auto;">
<f:facet name="header">
<p:row>
<p:column colspan="3">
<h:outputText value="#{title.update}" />
</p:column>
</p:row>
</f:facet>
<p:row>
<p:column>
<p:graphicImage alt="Your Photograph" id="photo" value="#{employeeUpdateBean.photoStream}" width="80" height="80" />
</p:column>
<p:column colspan="2">
<p:fileUpload mode="advanced"
fileUploadListener="#{employeeUpdateBean.addPhotoFile}"
allowTypes="/(\.|\/)(gif|jpe?g)$/" sizeLimit="100000"
invalidSizeMessage="Please limit photo size to 100Kb"
/>
</p:column>
</p:row>
<f:facet name="footer">
<p:row>
<p:column colspan="3">
<p:commandButton value="Update" action="#{employeeUpdateBean.employeeUpdate}" ajax="false"
style="margin-left:5px;margin-right:5px;" />
</p:column>
</p:row>
</f:facet>
</p:panelGrid>
</h:form>
Here is part of my bean
@Named
@WindowScoped
public class EmployeeUpdateBean implements Serializable{
static final long serialVersionUID = 7l;
private static final Log log = LogFactory.getLog(EmployeeUpdateBean.class);
@Inject
private HibernateUtil hibernateUtil;
@Inject
securityHelper secHelper;
@Inject
WindowContext windowContext;
public EmployeeUpdateBean() {
}
@PostConstruct
public void getData() {
System.out.println("In Get Data");
System.out.println("windowId: "+this.windowContext.getId());
//Thread.dumpStack();
Integer id= secHelper.getEmployeeId();
System.out.println("ID"+id);
}
Below is the output I see.
In Get Data
windowId: f75
ID11117
In Get Data
windowId: f75
ID11117
In Get Data
windowId: 1f9
IDnull
This first two 'in Get Data' are related to a preRenderView call to getData (not shown in code here) and the PostContruct call.
The third is clearly from the call to @PostConstruct when a new bean instance is created when p:graphicImage tries to access the photoStream with a new windowId.
I have tried this by removing the p:graphicImage from the form, and in that case the third call is never made.
I have to use p:graphicImage becasue I need to stream data from the DB. And I am trying to avoid writing a seperate servlet to stream images.
Also, the seperate servlet is not a good option as I need to know the employee who is logged in to be able to show the image.
Please let me know if there are any good solutions to get over this.
My full environment is Tomcat 7 Openwebbeans Myfaces CODI Myfaces + Primefaces