开发者

JSF 2 View Expired Weirdest Bug (Update - Occurs when saving state to server only)

The bug is this - I have several forms in my JSF application. If I activate AJAX calls outside a specific form for 20 clicks or more, I get a "No Sav开发者_开发百科ed View State Could be found for the view identifier" exception.

UPDATE 1 This only occurs when the state is saved on the server. When this option is set, the problem doesn't occur:

<context-param>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
</context-param>

END OF UPDATE 1

For example, suppose I have a form A, form B, form C in my app: (The actuall app is very complex, I will try to bring all the relevant information)

<h:form>
  <h:commandButton value="A">
    <f:ajax render="@form"/>
  <h:commandButton>
<h:form>

<h:form>
  <h:commandButton value="B">
    <f:ajax render="@form"/>
  <h:commandButton>
<h:form>

<h:form>
  <h:commandButton value="C">
    <f:ajax render="@form"/>
  <h:commandButton>
<h:form>

One more important factor, only one form is visible at each point in time, the other forms have display:none. Finally, All beans are session scoped.

Now, The following clicks will cause the exception (For each row, the last click causes the exception)

  1. Ax20, B
  2. Ax19, B, C
  3. Ax10, Cx10, B
  4. Bx5, Cx5, Bx5, Cx5, A

This will not cause an exception:

  1. Ax18, B, C, A.

In other words, If a button in a form is not clicked in the last 20 clicks, the next time it is clicked, a No save view state exception is thrown.

All buttons in the same form are equivalent to the form, meaning, if form A had buttons A1 and A2 then the following would not cause an exception:

  1. A1x20, A2
  2. A1x19, B, A2
  3. A1, A2x20, B, A1

Any Idea?!? This is driving me nuts.


You've exceeded the number of views in session limit from a single page on. The limit is by default 15, but is configureable by a context param in web.xml. Each form is technically a separate view with its own view state. When you continuously ajax-update one form while untouching other forms, then their view state in server side will slowly but surely expire.

Saving the view state in the client side will indeed solve this problem, as nothing in the server side session will be stored. It only makes the response size a bit larger (bandwidth is however cheap nowadays).

If you want to keep the view state in the server side, then you should render the other forms from the single ajax form as well so that their view state will be updated as well:

<h:form id="A">
  <h:commandButton value="A">
    <f:ajax render="@form :B :C"/>
  <h:commandButton>
<h:form>

<h:form id="B">
  <h:commandButton value="B">
    <f:ajax render="@form :A :C"/>
  <h:commandButton>
<h:form>

<h:form id="C">
  <h:commandButton value="C">
    <f:ajax render="@form :A :B"/>
  <h:commandButton>
<h:form>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜