requestContext update/execute... doesn't work when <h:head> is present - jsf

I have a portlet deployed in liferay 6.2 (Tomcat 7.0.42).
I use Primefaces 4 and liferay bridge 3.2.4-ga5.
I am aware of this post:
RequestContext won't work
But I have a strange problem here:
Primefaces doesn't work without the h:head tags, but when I add them the site won't update when I send the data to the bean. According to the server log the fields get updated, the p:log will say that the DOM has been updated, but nothing happens on the site, unless I remove the h:head tags. In that case the site will update with the new data, but primefaces won't work/display properly.
I even tried this demo example 1:1:
http://www.primefaces.org/showcase/ui/misc/requestContext.xhtml
But the outcome is the same.
I'm not sure what might be causing this.
Any ideas?
Thanks&BR
Edit:
Ok, I just found out, that I need to add the namespace to the update method.
So in the case of portlets it's not enough to use update("form:obj"), but update("namespace:form:obj) ... that head tag thing is still kinda strange.

try
context.update(":formId:panelId");
or
context.update(":panelId");

Related

Is it possible to use PrimeFaces dataTable in IceFaces environment?

I have an application using IceFaces 3.3 (non-EE version) for user interface. I would like to replace some of the pages to PrimeFaces.
As a trivial case, I created a new page with only HTML and PrimeFaces tags on it. There is a sortable and filterable lazy dataTable on the page and nothing else. The table first loads fine but when I initiate a sorting or filtering operation, the entire table disappears.
When I inspect the page, I see IcePush is operating and the IceFaces Bridge is loaded. In case of the above mentioned partial page reload, in the response XML, the dataTable appears within delete tags however, it should be present within update tags instead.
It seems that adding org.icefaces.subtreeDiff=false to web.xml solves the problem.

Using binding attribute causes javax.faces.FacesException: Cannot find component with identifier

I have a problem I can't quite get a handle on.
First the context: I am developing a web application using Primefaces 3.5 (yes, unfortunately I am stuck with this old version for now), running on JBoss 7.
There is a form with id "form" encompassing all following xhtml code.
I have a component in my view which is provided by usage of the binding attribute:
<p:dashboard id="dashboard" binding="#{myBackingBean.dashboard}" />
Then sometimes I would like to perform an ajax update on this component, this is done by using the RemoteCommand component of primefaces:
<p:remoteCommand
actionListener="#{myBackingBean.someActionListener()}"
process="#this" id="myRmtCmd" oncomplete="myJsFunction();"
update=":form:dashboard" name="myRemoteCommand" />
The RemoteCommand is triggered by a clicking on a Link:
Some Text
This works pretty well so far. However after deploying this code to production I sometimes get a FacesException:
javax.faces.FacesException: Cannot find component with identifier ":form:dashboard"
referenced from "form:myRmtCmd".
This is where my problem lies because I cannot reliably reproduce this exception. My question is this: What could lead to this exception being thrown? It seems to work 95 % of the time but being the perfectionist I am (and many of you reading this are as well, I'm sure ;) ) I would like this code to work 100 % of the time. What am I missing?
Before answering please consider these constraints:
yes, i have to use the binding attribute for providing the dashboard as I need a great deal of control over what gets added to the component
to avoid using IDs I also tried updating the dashboard by its css class via one of primefaces' advanced selectors: #(.ui-dashboard) - this also does not work!
yes, it would be possible to use a commandbutton/link instead of wiring up the remotecommand component to a simple html link but in this case the link is rendered by a JSF renderer component and I made some bad experiences with dynamically adding buttons etc (due to JSF Spec Issue 790)
Cheers,
p.s.
I also had this weird behavior.
There are probably more than one component bindded to #{myBackingBean.dashboard}, so the first one sets the id and there will be no one called "dashboard".

JSF Multiple components in grid

I am trying to get the reusable group of jsf 1.2 components inside a panelgrid using Facelet tag file. #Balusc's previous answer at How to make a grid of JSF composite component? was a fabulous resource. I have a couple of followup questions:
In my c:when how do I test for the tagName itself instead of checking for the attributes. Instead of
<c:when test="#{type != 'submit'}">
I want to check tagName itself to decide how to format it. If 'input' do xxx.
2 Is this approach is still valid with jsf 1.2 other than f:ajax? If yes, can I replace with a4j:support...?
In my c:when how do I test for the tagName itself instead of checking for the attributes.
I'm not sure how this question makes sense. It sounds like that you're approaching something not entirely right. Do you maybe have copypasted exactly the same piece of code over multiple tag files? You should not do that. Make it a reuseable <ui:composition> or maybe <ui:decoration> instead which you compose/decorate in every tag file along with a fixed and unique <ui:param> value depending on the taglib file.
Is this approach is still valid with jsf 1.2 other than f:ajax? If yes, can I replace with a4j:support...?
Being able to create tag files is not necessarily specific to JSF, but to the view technology used, which is in this case Facelets. You can even do similar stuff in its predecesor JSP, see also this answer for an example: JSF 1.2 custom component from jsp:include It should work just fine in every JSF version supporting the view technology in question.
As to ajax support, it doesn't matter to the tag file what you're all doing inside the tag file. If you want and can use <a4j:support> then just do it.

Faces messages not shown until the page is refreshed

I'm using JSF1.2, Tomcat 6.0, RichFaces 3.3.3, and Java 6u31.
I do an action in the managed bean, and show a message to the user. That's OK.
After that, I do another action in managed, and then the messages doesn't work anymore until I refresh the page.
I can assure you that the problem isn't in the managed bean, because I just removed all the method impl, leaving it empty, and the bug still happens.
So, the problem is something in the xhtml pages. I tried to put an a4j:status, but it doenst show any error.
So, I see myself without hope. I will not post all the code here, because it's too big and complex.
I wonder if one of you ever seen something like this, or if you have one guess of whats happening. I can edit the question adding any info you want.
I solve this problem.
I has a onupload in the rich:fileupload.
I just remove it, and add a a4j:support, like this:
<a4j:support event="onupload" oncomplete="foo()" />
That's it. I just don't understand why it works that way, and doesnt in the old way.
BTW, thanks.

How to change the pictures related to links in JSF?

I have links and pictures related to these links on my page. I want to change the pictures everytime when onmouseover event occurred in the links. I want to do this in JSF.
A lot of Thanks to everyone.
You are looking specifically for JSF to do it, or you are open to other Javascript frameworks that provide a slick and easy solution on this? For example Jquery and Dojo etc may be easy to incorporate in your application and will give Rich UI effects.
On the other hand if you are looking at JSF specifically for these UI effects than probably I can try to think of some ways and let you know.
JSF isn't designed directly to do this; It's designed to give you the tools to do this yourself. In order to do this you would need to create a custom JSF component to do this and you would use Java script to do it.
You could possibly find a JSF framework that does this already (a4j, IceFaces, etc.) but this is such a simple and well documented JavaScript thing that just tossing a little Java script among your JSF is perfectly acceptable. However, if you don't want to reinvent the wheel, take a look at those other options.
Javascript solution:
Define onmouseover event on the commandLink tag calling some kind of javascript you may give link address from like onmouseover="doSomething('addressOfImage')" then in doSomething javascript method, first find the image, then set src attribute of a default image to given address.
JSF Solution:
You might want to use a4j for this.
Add a4j:support to link for onmouseover event then just rerender graphicImage component ofcourse you need to give value of graphicImage dynamically. There is an example of using a4j support below. You can add this a4j:support between your link tags for mouseonover event. Then manage everything on backing bean to handle which image to be displayed.
example
<h:graphicImage id="imageToBeRendered" value="#{myBean.imageAddress}"/>
Just google a4j if you have no idea.

Resources