I am experimenting with Open Liberty and wanted to try out JSF-2.3 support. I must be doing something silly because when trying implicit navigation I immediately get the exception:
javax.faces.application.ViewExpiredException: View "/view/index.xhtml" could not be restored.
at org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(RestoreViewExecutor.java:181)
I can render an initial Facelets-page using the following server.xml features:
<featureManager>
<feature>servlet-4.0</feature>
<feature>jsf-2.3</feature>
<feature>el-3.0</feature>
<feature>cdi-2.0</feature>
<feature>jsp-2.3</feature>
</featureManager>
My page is really simple and looks like this:
<h:body>
<h:outputText value="It works!"/>
<br/>
<h:form>
<h:commandLink value="NAvigate" action="view/page2" />
<h:commandButton value="NAvigate 2" action="view/page2" />
</h:form>
</h:body>
I have a corresponding page2.xhtml.
When clicking on either the commandLink or commandButton I get the exception:
javax.faces.application.ViewExpiredException: View "/view/index.xhtml" could not be restored.
at org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(RestoreViewExecutor.java:181)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:195)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:142)
Have I mis-configured something in Open Liberty or are my JSF-mojo just lacking severely?
Ugh.. after testing in another browser (Safari) it worked. Hard-resetting Chrome site storage then fixed the original problem.
This problem must have surfaced somewhere in between automatic restarts.
Related
I'm working with JSF and PrimeFaces, and I can't handle the following situation:
I have a dialog, and I placed a dataTable on it. In one of the cells of the table I would like to display given data in 3 different ways, and I'd like to switch between them. So far I managed to switch between these rendering types via commandLink, but my problem is that when I click on one of the 3 links, the dialog closes! Can I update the content of the dialog, and be able to keep it open the same time? (I'm updating which render type to use via myMethod)
my commandLink looks like this:
<p:commandLink id="id" update=":myForm:myDialog" ajax="false"
action="#{myBean.myMethod}" oncomplete="dialog.show()">
If i don't use the ajax=false attribute, the method is not called, and I also tried imediate=true, but that's not it either.
You need to define an p:outputPanel inside your dialog and update the outputpanel, not the dialog itself (that's why your dialog closes):
<p:dialog id="myDialog" ...>
<p:outputPanel id="myOutputPanel">
... your dialog content goes here
</p>
</p:dialog>
and change your commandlink
<p:commandLink id="id" update=":myForm:myDialog:myOutputPanel" ajax="true"
action="#{myBean.myMethod}" oncomplete="dialog.show()">
Regarding the oncomplete="dialog.show()" - I'm not entirely sure if you need that. A precise answer can be given if you provide more code regarding your table and code.
I had the same problem, and solution is to update a form instead of dialog. For example:
<p:dialog id="id_dialog" ...>
<h:form id="id_form">
... content
</h>
</p:dialog>
and commandLink:
<p:commandLink update=":id_form" process="#all" ...>
This worked for me!
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.
I'm using JSF 2.0 and I have a problem with navigation after both commandLink and commandButton. I use following code:
<h:commandLink action="login?faces-redirect=true"
value="#{showElementBean.showElement()}"> Login </h:commandLink>
<h:commandButton action="login?faces-redirect=true" value="Move to login.xhtml" />
These tags are inside a form, login is just an example. Result of clicking on rendered controls is always POST with refresh of a current page. What do I wrong?
Edit:
According to comments of BalusC I' adding real code fragment:
<h:commandLink actionListener="#{showElementBean.showElement(element)}"
value="View" > </h:commandLink>
I have a page with a list of elements and I want to add links that leads to element view page. Thus I need to pass this element to a show page. I'm JSF primer, e.g. in Rails I'd use GET and URL params, but I don't know how to do it 'in JSF-way'.
There are a lot of possible causes for this behaviour. They are all cited in the following answer, along with solutions: commandButton/commandLink/ajax action/listener method not invoked or input value not updated.
However, in your particular case, you seem rather to be interested in plain GET requests instead of POST requests, as all you want is simple page-to-page navigation. In that case, you need a <h:link> or <h:button> instead:
<h:link outcome="login" value="Login" />
<h:button outcome="login" value="Move to login.xhtml" />
(I have no idea what you're trying to do with both #{showElementBean.showElement()} and Login as command link value, so I omitted the former)
See also:
When should I use h:outputLink instead of h:commandLink?
Refer this info: JSF HTML Tags
h:commandButton
The commandButton tag renders an HTML submit button that can be
associated with a backing bean or ActionListener class for event
handling purposes. The display value of the button can also be
obtained from a message bundle to support internationalization (I18N).
Example
<h:commandButton id="button1" value="#{bundle.checkoutLabel}" action="#{shoppingCartBean.checkout}" />
HTML Output
<input id="form:button1" name="form:button1" type="submit" value="Check Out" onclick="someEvent();" />
h:commandLink
The commandLink tag renders an HTML anchor tag that behaves like a
form submit button and that can be associated with a backing bean or
ActionListener class for event handling purposes. The display value of
the link can also be obtained from a message bundle to support
internationalization (I18N).
Example
<h:commandLink id="link1" value="#{bundle.checkoutLabel}" action="#{shoppingCartBean.checkout}" />
HTML Output
Check Out
Noticed that backing bean method is not called if the form is for file upload:
<h:form name="searchForm" enctype="multipart/form-data" method="post" action="/search">
I also faced with that issue and adding the
<h:form><h:commandLink></h:commandLink> </h:form>
solved my problem.
In my JSF application I have one JSP page which keeps generating a warning which sometimes gets rendered. In the log files I can see something like this:
WARNING: getClientId should not be called while the view is being constructed.
Component-ID: j_id18
The component which generates the warning looks like this:
<tr:panelCaptionGroup captionText="Jobs">
<tr:poll pollListener="#{jobBean.update}" id="poll" interval="#{msg.cfg_pollingInterval}" />
<tr:table allDetailsEnabled="true" partialTriggers="::poll ::groupFilter">
<f:facet name="detailStamp" >
<tr:table var="trg" value="#{subbean}" >
...stuff...
</tr:table>
</f:facet>
<tr:column>
<h:panelGroup>
<tr:commandLink />
</h:panelGroup>
</tr:column>
<tr:column />
</tr:table>
Could it be an issue with polling in the table?
I'm using Trinidad 2.0.0.
I've tried the option org.apache.myfaces.trinidad.CLIENT_ID_CACHING in web.xml and I observe the behavior with all options ON, OFF and DEBUG.
As it seems, there was a NPE occurring somewhere while creating a dropdown in the screen.
The code has been fixed, and the warning doesn't appear any more.
My solution was to refresh any parent programatically in a backing bean prior to ending up in this state.
Note, it looks like this message was added to java/org/apache/myfaces/trinidad/component/UIXComponentBase.java in May 2010 at revision 942933 to prevent and NPE when clientId is null.
I'm trying to make a JSF reload the locale (which is defined in the view)
<f:view locale="#{admin.userLocale}">
<h:commandButton image="images/ukflag.gif" action="#{admin.returnToEnglish}" immediate="true" onclick="window.location.reload()" />
<h:commandButton value="1" action="#{admin.returnToEnglish}" immediate="true" onclick="window.location.reload()" />
<h:commandButton value="2" action="#{admin.returnToEnglish}" immediate="true" onclick="history.go(0)" />
<h:commandButton value="3" action="#{admin.returnToEnglish}" immediate="true" onclick="window.location.href=window.location.href" />
<h:commandLink value="4">
<a4j:support event="onclick" reRender="GeneralConfigForm" action="#{admin.returnToEnglish}" />
</h:commandLink>
</f:view>
I tried all of the above buttons.
They all do the same thing - They call the method the changes the locale, the page reloads but the new locale labels are not loaded correctly.
At this point, if I reload again the changes catch up and the locale is shown correctly.
How do I make the buttons update the local earlier so the page will show the new locale when it is brought up?
Thanks!
P.S - On JSF 1.2
I'm not sure how you got it to work after a refresh. Is the #{admin.userLocale} stored in the request scope instead of the session scope? The first four buttons won't invoke any JSF action at all. The JS function in the onclick get executed first and it changes the current page and hereby the default action is totally aborted. The fifth seem to be the only which should work, although a <h:form> is missing for all those buttons, but I'll bet that it's just the oversimplification of the code example.
Regardless, the usual practice is to store the user-specified locale in the session scope. When you want to change it by a JSF action method, then you need to send a redirect afterwards so that a new view will be created with the desired locale. Otherwise the initial locale will indeed be used in the response and thus you have to change it in the current view yourself by
FacesContext.getCurrentInstance().getViewRoot().setLocale(newLocale);
in the action method.