0

I have a JSF 1.2 page which has radio buttons to choose one of 2 options. I have a jQuery function to submit the form with a change in action, but give this error.

javax.servlet.ServletException: viewId:/buildVehicle.jsf - View /buildVehicle.jsf could not be restored.
root cause 
javax.faces.application.ViewExpiredException: viewId:/buildVehicle.jsf - View /buildVehicle.jsf could not be restored.
com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:189)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)

Here is the jQuery function which submits to to render the same view with some change in request param:

var make = $('input:radio[name=selectMake]:checked').val(); //returns NI/IN     
$("form#buildVehicleForm").attr("action", "/buildVehicle/buildVehicle.jsf?action=initTrim&make=" + make);
$('form#buildVehicleForm').submit();

In the JSF page I am using simple HTML radio buttons. I cannot change it to JSF <h:selectOneRadio> component, because the HTML code that was given to me, it is not easy to convert to JSF code.

<div class="filedItem margin-10px floatLeft">   
    <input type="radio" id="id1" name="selectMake" onchange="changeMake()" value="N"  />                       
</div>
<div class="filedItem margin-10px floatLeft">
<input type="radio" id="id2"  name="selectMake" onchange="changeMake()" value="I"  />
</div>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Surya Govi
  • 35
  • 1
  • 6

1 Answers1

0

You're completely working your path around JSF. This is not going to work. JSF requires the POST request to have a reference to the view state which is in normal JSF forms identified by a hidden field with the name javax.faces.ViewState. If you'd like to take full control over HTML, then you should rather use simple JSP/Servlet instead or an action based MVC framework like Spring MVC, not a JSF page with a managed bean.

As to your real problem for which you thought that this is the solution,

In the JSF page I am using simple HTML radio buttons. I cannot change it to JSF <h:selectOneRadio> component, because the HTML code that was given to me, it is not easy to convert to JSF code.

In that case, Tomahawk's <t:selectOneRadio> component may be very helpful. That component comes with an additional layout attribute of spread which allows you to position the radio buttons everywhere in the markup you want using <t:radio>, without ending up in a <table> as the JSF standard <h:selectOneRadio> component does.

E.g.

<t:selectOneRadio id="foo" value="#{bean.foo}" layout="spread">
    <f:selectItems value="#{bean.foos}" />
</t:selectOneRadio>
...
<div class="filedItem margin-10px floatLeft">
    <t:radio for="foo" index="0" />
</div>
<div class="filedItem margin-10px floatLeft">
    <t:radio for="foo" index="1" />
</div>
...

(by the way, your CSS classes are somewhat fishy, I'd suggest to work on that as well, but that's a completelely separate subject)

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks BalusC for the quick reply! I am using Sun's RI Mojarro JSF implementation. I cannot have the t:radio, is there somethign with richfaces? I am supposed to use JSF, JSTL & Richfaces only. – Surya Govi Feb 13 '12 at 02:30
  • Well, that's bad luck. Your best bet would be writing a custom renderer for ``. Tomahawk is open source, so that may give some insights. RichFaces doesn't have a similar component. Only Tomahawk, ICEfaces and PrimeFaces have. The ICEfaces one is actually a clone of Tomahawk. Alternatively you could also convince your lead to use Tomahawk. In less than a hour you'd be ready instead of days or maybe weeks. – BalusC Feb 13 '12 at 03:37
  • Oh, by the way, please don't be victim of the old myth that Tomahawk only works with MyFaces, not with Mojarra. That is complete nonsense. – BalusC Feb 13 '12 at 03:41
  • Hi BalusC, what is the best way for me to hit the server based on a radio button change (with the change in value)? I hate using selectoneradio, beacuse it puts a table in the generated html, if I did use it, there is no action attribute for selectoneradio. If I use HTML input radio elements and submit from JS it does not work. This seems pretty simple with other frameworks, but with JSF it seems liek my hands are tied. – Surya Govi Feb 13 '12 at 04:43
  • Your hands are not tied by JSF. Your hands are tied by business restrictions you have. It's not JSF's fault that you may not use Tomahawk. It's a matter of dropping one or two JARs in `/WEB-INF/lib` and replacing `` by `` with ``. Before ranting on JSF, I suggest to start reading here: http://stackoverflow.com/questions/4421839/what-is-the-need-of-jsf-when-ui-can-be-achieved-from-css-html-javascript-jquery Once again, discuss with your lead. The restriction to not use Tomahawk ends nowhere. – BalusC Feb 13 '12 at 04:45