Gatling and JSF viewState

Hi guys,

I’m trying to make a simple get request and save jsf viewState like described here:

but i’m receiving “regex(=“javax.faces.ViewState” value=”([^"]*)").find(0).exists 1 (100,0%)
, found nothing"

My simulation is pretty simple and all code can be found here:

here is some code:

val httpProtocol = http
  .acceptEncodingHeader("gzip, deflate")
  .connection( """keep-alive""")
  .userAgentHeader("Mozilla/5.0 (Windows NT 6.3; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0")

val jsfViewStateCheck = regex( """="javax.faces.ViewState" value="([^"]*)"""")

def jsfGet(name: String, url: Expression[String]) =

def jsfPost(name: String, url: Expression[String]) = http(name)
  .formParam("javax.faces.ViewState", "${viewState}")

val loginScenario = scenario("login")
    .resources(http("request_resources").get( "/"))

  loginScenario.inject( atOnceUsers(1) )

and here is the error:

regex(=“javax.faces.ViewState” value="([^"]*)").find(0).exists 1 (100,0%)
, found nothing

full debug output can be fond here:

its probably a detail,

any help is appreciated.

Did you check that your HTML indeed matches this regular expression?

Also, parsing HTML with a regular expression is definitively not convenient. You should try css selectors which is way more versatile (doesn’t break if you have an extra space, or a reverse order in name and value, etc).

Hi Stephane,

thanks for your reply, css selector like css(“input[name=‘javax.faces.ViewState’]”) did the trick, maybe the docs should be updated?

also note that this selector will not work for partial request (header Faces-Request: partial/ajax)
which returns a partial response where viewState is like this:

thanks again!

Hi Rafael,

Hi Stephane,

Already done:

that was fast, great!

Interesting. Is this format vendor specific (like PrimeFaces would be different from RichFaces?) or is it specified in the JSR?

Partial request is for dealing with ajax and is in the spec since JSF 2.0 (section 14.2.4 - Request Sending Specifics). In practice every time you use tag f:ajax execute=“some html component” or in primefaces with p:ajax process=“some component” will generate a JSF partial request and response.

Would it be possible for you to provide a Pull Request for this?

sure, I will work on some more JSF examples and then send the PR to update the docs.

Hi again,

I’ve just hacked a little bit and created a sample project which fires JSF requests here:

basically I’ve used two checkers, one for normal and another for partial requests:

val jsfViewStateCheck = css("input[name='javax.faces.ViewState']", "value")

val jsfPartialViewStateCheck = xpath("//update[contains(@id,'ViewState')]")

both examples of partial and non partial requests can be found here: and the demo
fires both kinds of requests at that primefaces showcase page.

The example is quite simple, the only gotcha is that it needs a first GET request save the viewState and also buttons and form ids (they are generated by jsf) that will be used in subsequent request.

Note that there are others scenarios to explore in the JSF land and the demo shows very simple but common cases.

I hope it helps.

Thanks Rafael.
I added a link to your sample project:

Great! I plan to evolve the examples and if I find something useful I will share it here.

thanks and congratulation for the great work!

Just added an example of JSF ajax event (eg: fire ajax request on keyup). The idea is the same but for this case you need to add 2 additional form params:

.formParam("javax.faces.behavior.event", "keyup")
.formParam("javax.faces.partial.event", "keyup")

I’ve updated the project readme which shows this example:

I think there is no need to update Gatling docs as it is something a JSF developer must know.