JSF commandLink not working on redirected error page - jsf

I'm redirecting all exceptions to a simple error page with the following entry in my web.xml file:
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/error.xhtml</location>
</error-page>
My error page contains:
<ice:form id="errorForm">
<ice:outputText value="#{guiProps.UnknownError}"/><br/><br/>
Click <ice:outputLink value="/"> here</ice:outputLink> to attempt to return to the previous page.<br/>
Click <ice:commandLink value=" here" action="#{UserBean.logoutAction}"/> if you are unable to do so.
</ice:form>
The problem is, the commandLink DOES NOT work when it's clicked. The logoutAction method is never fired. You get a brief hourglass, I observe a little bit of XMR action (via Chrome browser) but nothing really happens. I've also tried using vanilla JSF tags (h:commandLink, h:form, etc) and the same thing happens, so its a JSF problem, not an ICEfaces problem
Also weird...this problem only happens using Glassfish v2.1.1, not v2.1. I don't know if it's a v2.1.1 bug, per se, but in any case, if there is a way to work around it or a way of figuring out what is going on, I'd appreciate any help, because we are certainly using v2.1.1.

Are you sure it is supposed to be UserBean and not userBean?
#{userBean.logoutAction}

Related

JSF DocumentViewer fails to display PDF in #ViewScope

I am relatively new to JSF thus need some help.
Problem: I have webpage that displays a PDF. Thus I created a xhtml as follow
<p:panel rendered="#{mainAppView.getMessages().isEmpty()}" styleClass="preview-panel">
<div class="document-viewer-wrapper">
<pe:documentViewer
url="#{previewView.previewUrl}"
download="Document.pdf"
id="pdfPreview"/>
</div>
</p:panel>
URL is provided by a BackingBean previewView. Thus when the jsf tries to display the document, it makes a call to WebServlet. The WebServlet downloads the document and displays it and if it fails to download, an error message is shown on the DocumentViewer.
Is there a way to I can notify the ViewScope Bean about the failure? I want to disable a tab on the screen if the document download fails. I read that servlet can't make call to viewScope Bean.
Do not use ViewScoped with PDFViewer use RequestScoped/SessionScoped/ApplicationScoped instead.
See: https://github.com/primefaces-extensions/primefaces-extensions.github.com/issues/796
BalusC explains why ViewScoped can't be used as well: https://stackoverflow.com/a/18994746/502366
I ended up writing a JS to achieve the desire result. JS monitored the pdfviewer and if it fails to load the document, I updated the message on the pdfviewer.

forwarding request to a page with p:outputpanel make it load forever

i m developing a web-app using primefaces 6.0 on wildfly 10, my problem is:
redirecting to a page that contain a primefaces outputpanel cause the outputpanel to load forever :/
by redirecting i mean code like:
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/aboutUs.xhtml");
dispatcher.forward(request, response);
i will appreciate any help :D
after some testing, i got it:
-lets say i've sent a requset to my servlet, the requset got forwared and a nice web page it returned
-now the javascript code in my outputpanel widget try to load its contents, so it send another request
-this time the servlet my just decide to not forward to the same page, or it my not forward at all or ...
the problem is i did not write this servlet (its faces servlet in my case, and since even faces-config.xml won't do the trick it's hopless)
what i've done is using a parameter to enable/disable outputpanel lazy loading like this:
<p:outputPanel deferred="#{request.getParameter('lazy') == 'off'? false : true}">
then i used this in my auto forward pages:
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/login.xhtml?lazy=off</form-login-page>
<form-error-page>/login.xhtml?lazy=off</form-error-page>
</form-login-config>
</login-config>
the rest is ensuring than any ajax call these pages do should also include this parameter so i've added this parameter in my "change language" menuitem
<p:menuitem ...>
<f:param name="lazy" value="#{request.getParameter('lazy')}" />
</p:menuitem>
now these pages load without lazy loading insdead of loading forever, not a perfect solution but better than nothing :D
this is the best idea that i got until now :/

RichFaces a4j:poll not working

My code in RichFaces 3.3.3:
<a:region>
<h:form>
<a:poll id="feed" enabled="true" reRender="feedReader" interval="100"/>
</h:form>
</a:region>
<h:form>
<h:outputText value="#{feedReader2.title}" id="feedReader" />
</h:form>
This is close to the example here: http://www.mastertheboss.com/richfaces/using-ajax-with-jboss-richfaces
What it should do is poll the server which reads an rss feed and gives back the title.
However, this is not working. In Chrome developer tools I can't see any AJAX requests made to the server. Instead, I see an error Uncaught TypeError: Cannot read property action of null on framework.pack.js. The line in which the error occurs is:
this._actionUrl=(this._form.action)?this._form.action:this._form
I can only guess that this is releated to the <h:form> which doesn't have an action attribute. But I don't see why I need this here, as it is not included in all of the examples you can find.
Moreover, I do not want the <h:outputText> to query the bean on page load. My aim is to use AJAX to read the feed after the page is done rendering.
If this is an issue related to my RichFaces version, could someone please give me an example on how to do this in 3.3.3?
I found the issue. It was an error outside the above markup i've included. Had two <h:form> nested, which caused the second one to malfunction.

Why JSF POST requests don't work with PrettyFaces

I have been using JSF (MyFaces) with PrettyFaces for a while. Everything works perfectly, excepting POST requests.
The only problem I have is that I can’t make POST requests to any of the pages that are rewritten by PrettyFaces.
I would really appreciate your help, because it’s a show stopper.
pretty-config.xml
<url-mapping id="market-view-item">
<pattern value="/market/#{viewItem.itemId}" />
<view-id value="/market/view-item.xhtml" />
</url-mapping>
pom.xml
<dependency>
<groupId>org.ocpsoft.rewrite</groupId>
<artifactId>rewrite-servlet</artifactId>
<version>2.0.5.Final</version>
</dependency>
<dependency>
<groupId>org.ocpsoft.rewrite</groupId>
<artifactId>rewrite-config-prettyfaces</artifactId>
<version>2.0.5.Final</version>
</dependency>
I used 2.0.4.Final until today. I hoped that it will work by upgrading to 2.0.5, but nothing.
web page form:
<h:form prependId="false">
<p:inputTextarea rows="3" style="width:450px; margin:5px 0;" autoResize="false"/>
<h:commandButton action="#{test.doSomething}" class="pg-button" value="Add comment"/>
</h:form>
CDI bean:
#Named("test")
#RequestScoped
public class TestB {
public void doSomething() {
System.out.println("I work.........");
}
}
Any ideas why POST requests are not executed? Whatever I do, they just don’t happen. No error at all. Just nothing.
When I press the submit (Add comment) button, Chrome makes a request (ajax / non-ajax (I tried both)), but method doSomething is not triggered.
I tried withing bean viewItem also (the one specified in pretty config), but nothing. I tried in 100 ways…
I have to mention that all pretty faces config mappings work perfectly on GET requests, just that I can’t post from them.
I couldn't find any solution/answer to this until now.
I would really appreciate any help.
Thanks a lot!
CDI bean:
#Named("test")
#RequestScoped
public class TestB {
public void doSomething() {
System.out.println("I work.........");
}
}
Is it possible that your 'CDI' bean lacks constructor method and that could be causing the problem here?
I have been using TomEE+ ever since TomEE+ 1.5.1 'SNAPSHOT', then I migrated to TomEE+ 1.5.2 'SNAPSHOT' as soon as it was available, and then I migrated to TomEE+ 1.6.0 'SNAPSHOT', and always try to use latest versions of the 'SNAPSHOT' JAR file. I only use 'SNAPSHOT' versions this way, and 'SNAPSHOT' = 'latest and greatest'. :)
First of all, thanks for helping. It is something strange, that's why I couldn't isolate the problem (to get it happen in another project), which is not executing the POST requests at first try, but from the second one.
I have removed the filters I had in web.xml without any difference. The same behavior.
I've just had the idea of testing the project in other Tomee version than 1.5.2. Surprisingly, dev version 1.6.0 from 29.07.2013 seems to don't have this problem. Why didn't I think at this sooner? :( I had to write separate Servlet components for my post functionalities. Aaaah!
Well, this means that not PrettyFaces was problematic (Huraay!), but, probably, Apache MyFaces, CDI impl. or something else in Tomee.
Uf...I'm so happy that it works now.
Thanks again for trying to help.
///////////////////////////////News//////////////////////////////////
It seems that it didn't work in other versions of Tomee neither.
The problem was having a c:forEach in that page (inside a custom component used in that page), even though the commandButton was not inside the loop. By switching to ui:repeat, the problem is gone in all versions of Tomee.
It is probably a bug in MyFaces, because Glassfish 3.1.2.2 (with Majorra) doesn't have this problem. (tested)
///////////////////////////////News 2//////////////////////////////////
Ha...even more interesting.
If h:form is after c:forEach, the POST method is not triggered at first try. It works just from the second try. That's the original problem.
If h:form is before c:forEach, the Post method (action of the form) is executed properly from the first time/click.

JSF 2.0; myfaces with JavaScript disabled; CommandButton has no class in rendered page

that's my first post here on stackoverflow.
I'm searching around a while for solving my problem.
In my JSF-Page I got a <h:commandButton> with styleClass set and on web.xml I disabled JavaScript (JavaScript isn't allowed on the hole page).
On then rendered page on Firefox, the CommandButton will not change its style, because the "class"-tag is missing.
If I turn on JavaScript, everything works fine and also the "class"-tag for the CommandButton is on the rendered page.
What I'm doing wrong or is this a bug in myfaces 2.1?
Best wishes and many thanks.
Tobi
This is definitely a bug in MyFaces. Report it to MyFaces guys over there on apache.org.

Resources