unable to update p:graphicsImage - jsf-2

My html code is as follows
<p:graphicImage id="graphImg" value="#{imageMB.img1}" width="740" height="480"
cache="false" />
<p:commandButton type="submit" value="Next" process="#all"
action="#{imageMB.nextImg()}"
update=":mainFORM:graphImg"/>
Note:In the above code i have tried most of the options for Process (#this,#form,...)
In by Bean i basically pass the StreamedContent
public void nextImg(){
img1=new streamed content;
}
Note: My images are not stored in the project location/glassfish its stored in /Test folder.
When i click the next button actually the img1 data changes, but the image in p:graphicsImage remains same.
The same works fine if i refresh the whole page (using F5 or javascript).
I really don't know why it doesn't get refreshed from the update command but works when the page is reloaded.
I use Primeface4.0/Glassfish 3.1.2.2

There is a issue with updating p:graphicimage on PrimeFaces 4.0 public version. Take a look at the offical forum: http://forum.primefaces.org/viewtopic.php?f=3&t=34658

Related

Render or update a page while still running inside a method

I was wondering if you could render or update a page while you still inside a method;
here is an example:
the .xhtml file:
<h:form id="form">
<h:commandButton value="change" actionListener="#{bean.changeText}">
<f:ajax render="out" />
</h:commandButton>
<h:outputLabel id="out" value="#{bean.text}" />
</h:form>
and here is the changeText Method:
public void changeText() throws InterruptedException{
text = "test1";
FacesContext.getCurrentInstance().renderResponse();
Thread.sleep(2000);
text = "test2";
}
Now is it possible to set the output label (id = out) to be rendered (or changed) to "test1", then after the 2 second have elapsed it changes to "test2"?
Well looking at the JSF life cycle i thought it isnt possible, but maybe i got the life cycle wrong, or one of you guys know a work around.
No, that's not possible. The render response only starts once the action method returns.
There are basically 2 ways to achieve the desired behavior: polling or pushing. Based on your question history, you're using Java EE 7 + JSF 2.2 + PrimeFaces. You could for pushing use PrimeFaces <p:socket> or homegrow one using Java EE 7's new WebSocket API (JSR-356).

Event 'onsave' in rich:editor doesn't fire

I'm implementing some kind of frontend editor in my web page, using rich:editor. When clicking a link, the editor should open, and after saving editor's content, the editor should close again. I'm having trouble with onsave event for closing the editor. Here is my code.
This is the link that opens the editor, due to setting the property bean.show to true. It works ok:
<h:commandLink>
...
<f:setPropertyActionListener value="true" target="#{bean.show}" />
</h:commandLink>
This is the editor itself, only rendered when show evaluates to true:
<h:form>
<rich:editor value="..." onsave="showEditor(false)" rendered="#{bean.show}" />
</h:form>
The onsave event should close the editor by setting the show property to false again, but the editor stays open, because showEditor() is not called:
<a4j:jsFunction name="showEditor">
<a4j:param name="param1" assignTo="#{bean.show}" />
</a4j:jsFunction>
Am I doing something completely wrong? Or do you have any other ideas how to realize this? Any help is appreciated.
just double-checked: in version richfaces 4.x, there is no onsave attribute at all, but
oninit
onblur
onfocus
ondirty
onchange
like pointed out in the org.richfaces.component.UIEditor class. The same is true, if you want to use f:ajax to ajaxify the editor.
Right now, the "save"-icon in the editor just sends a form.submit() or something. So either try to add your jsFunction on that event or to introduce an own save-button.
Edit: Richfaces 4 uses the javascript based CKEditor, so if you want to overwrite their "save"-button, this forum entry regarding CKEditor's save implementation might be of your help.
Also a valueChangeListener might be a possibility solution to trigger your Bean.setShow(boolean show) property.
xhtml:
<rich:editor value="#{bean.editorValue}"
valueChangeListener="#{bean.valueChanged}" />
method in managed bean:
public void valueChanged(ValueChangeEvent e) {
// do the code to close the window here
}
The valueChangeListener also works in Richfaces 4.3, but maybe starting within the javascript of the CKEditor is the better choice.
Hope, that helps... L.

Request scope issue in IBM portal 8.0

I have a JSR 286 portlet running in a Websphere Portal Server 8.0. There, I do a file upload and after show the results of processing. Initially my managed bean responsible to process this file has a Request Scope (#RequestScoped). When I Click in command button to upload file, the method in MB process correctly and fills a collection of results (dadosCarga attribute in MB below) that must be showed in JSP page. However, when I the page is rederized I got a stacktrace explaining that my Managed Bean class was not found (ClassNotFoundException) and results are not shown. I got the same results using ViewScoped. Just when I changed scope from Request to Session (#SessionScoped), the results are shown.
After I googled for some answer, I found this page explaining about difference between action and render request in Portlets. It was suggested to use JSF Portlet bridge. However, this page is not active anymore. There is a Portlet bridge for Apache Myfaces (IBM portal runs over MyFaces). However, I could not see how use it. Is it just put both jars (api and implementation) in WEB-INF/lib? I tried, but I got a exception when I tried load the pages in application. So I remove them.
Below, I show My Portlet configuration, Managed Bean and JSP page. Is there any alternative, a better Idea about how to deal with this? Or may be a explanation about how to use correclty MyFaces Bridge (I could not found none in its home page).
Thanks,
Rafael Afonso
Portlet configuration:
<portlet>
<portlet-name>CargaUsuarios</portlet-name>
<display-name>CargaUsuarios</display-name>
<portlet-class>com.ibm.faces20.portlet.FacesPortlet</portlet-class>
<init-param>
<name>com.ibm.faces.portlet.page.view</name>
<value>/pages/carga/cargaUsuarios.jsp</value>
</init-param>
<init-param>
<name>wps.markup</name>
<value>html</value>
</init-param>
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
</supports>
<portlet-info>
<title>Carga de Usuarios</title>
<short-title>Carga deUsuarios</short-title>
<keywords>Carga Usuario</keywords>
</portlet-info>
</portlet>
Manged Bean:
#ManagedBean(name = "cargaUsuariosMB")
#RequestScoped
public class CargaUsuariosMB extends AbstractMB {
private String nomeArquivo; // FIle name
private Collection<CargaUsuarioInfoBean> dadosCarga; // processing result.
public String doUploadArquivo() {
this.dadosCarga = ... // process file and receives a collection
this.nomeArquivo = ... // get uploaded file name
return null; // Return to same origin page
}
// Getters...
}
JSP page (cargaUsuarios.jsp):
<%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%#taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%#taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%#taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%#taglib
uri="http://www.ibm.com/xmlns/prod/websphere/portal/v6.1/portlet-client-model"
prefix="portlet-client-model"%>
<%#page language="java" contentType="text/html"
pageEncoding="ISO-8859-1" session="false"%>
<portlet:defineObjects />
<portlet-client-model:init>
<portlet-client-model:require module="ibm.portal.xml.*" />
<portlet-client-model:require module="ibm.portal.portlet.*" />
</portlet-client-model:init>
<f:view>
<h2>Carga de Usuários</h2>
<h:form enctype="multipart/form-data">
<p>
<label for="arquivoCarga"> <span>File:</span> </label> <input
type="file" name="arquivoCarga" id="FileCarga" />
</p>
<br />
<br />
<h:commandButton value="Salvar File"
action="#{cargaUsuariosMB.doUploadArquivo}"></h:commandButton>
</h:form>
<h:panelGroup id="pnlProcessamento"
rendered="#{not empty cargaUsuariosMB.dadosCarga }">
<h:outputText
value="Dados do File #{cargaUsuariosMB.nomeArquivo} processados com sucesso."></h:outputText>
<br />
<h:dataTable id="tblDadosProcessamento"
columnClasses="numLinha,cpf,status"
value="#{cargaUsuariosMB.dadosCarga}" var="dadosCarga"
styleClass="dadosProcessamento" width="100%" border="1">
<%-- Show processing results. --%>
</h:dataTable>
</h:panelGroup>
<h:messages styleClass="messages" id="msgsPesquisaCadastro"
errorClass="mensagensErro" errorStyle="color: red;"></h:messages>
</f:view>
Please try adding the following in the portlet.xml and see if it works:
<container-runtime-option>
<name>javax.portlet.actionScopedRequestAttributes</name>
<value>true</value>
</container-runtime-option>
For more information please download and check the following section in Portlet V2.0 specification:
PLT.10.4.4 Runtime Option
javax.portlet.actionScopedRequestAttributes
You are right about the render and action request, JSF (or CDI) Request and ViewScoped doesn't work properly. But solution could be using JBoss Portlet Bridge which contains brand new scopes - PortletLifecycleScoped and PortletRedisplayScoped. The first will behave exactly like a RequestScope, you will find more info in the docs. However, I am not sure if will able to use these scopes in other portals except GateIn.
When you use request scope, the data needs to be carried from portlet action to portlet render phase. The data is normally carried for request scoped beans via the portlet render parameters are a String. In order to get your data saved there, your object needs to be Serializable.
Besides that, you might want to upgrade your WebSphere Application Server beneath the WebSphere Portal to version 8.0.0.6 to avoid PM79460 and Portal itself to the latest FixPack as well.
Hope this helps.
BTW: JSR286 and JEE6 do not specify how CDI shall interact with the Portlet programming model. You might want to look at JSR362 for that.
IBM uses its own portlet bridge. It is not recommended to use any bridges in addition to that.

target="_blank" in h:commandlink not opening page in new tab of browser

My h:commandLink is opening/previewing the pdf document on same page/window when h:commandlink used with target="_blank". I want it to be opened in new tab of the browser
where can be the error?
Preview.xhtml code:
<h:commandLink id="DocUpoadPreview" action="#{documentController.previewUploadedFile}" value="Preview" target="_blank" >
</h:commandLink>
In previewuploadedFile() action encription/decryption and some other process with pdf is required that is why necessary to use and that is why not using h:outputlink here. After the action process i want to redirect to another page(previewUploadedDoc.xhtml) which uses primefaces p:media tag to preview the document.
public String previewUploadedFile() throws Exception {
//decryption process and adding water mark here//
FacesContext.getCurrentInstance().getExternalContext()
.redirect("previewUploadedDoc.xhtml");}
Try it:
<h:commandLink id="DocUpoadPreview" action="#{documentController.previewUploadedFile}" value="Preview" target="_new" />
target="_new" is not valid value of target. It defines _new as a name of new page.
This is the valids values: https://www.w3schools.com/tags/att_a_target.asp

How to hide messages with id javax_faces_developmentstage_messages

sometimes, i see generated info messages (not validation) at bottom of xhtml pages
with id javax_faces_developmentstage_messages
how can i prevent such messages from being generated in a specific page, i don't want to change the attribute of javax.faces.PROJECT_STAGE
i am facing such issue exactly when trying to override default message for uploading file in icefaces it shows both the new and old message (even when using clear before adding the new message), here:
How to override default file upload h:message in ICEfaces
please advise, thanks.
UPDATE:
code:
<ace:fileEntry id="fileEntryComp"
label="File Entry"
relativePath="uploaded"
useSessionSubdir="false"
fileEntryListener="#{myBean.listener}" />
i resolved it by adding the new messages to null clientId:
context.addMessage(null, new FacesMessage(message));
and in the view, i added:
<h:messages id="summary" styleClass="summary" infoStyle="Color:blue;" errorStyle="Color:red;" fatalStyle="margin-right: 85%; Color:red;" globalOnly="true"/>
<!-- i had to add the following one too -->
<h:messages for="fileEntryComp" style="display:none;"/>
if you want to hide " 'File Entry' uploaded successfully 'filename' " message which is generated after the successful upload of a file just add the following in your view
<h:message for="fileEntryComp" infoStyle="display:none" />

Resources