0

I start JSF 2, I create a xhtml page is index.xhtml, this page have a button:

<h:commandButton value="Submit" action="welcome" />

And I create a page welcome.xhtml.

But when I view source of index.xhtml, I don't see any "link" from index.xhtml file to welcome.xhtml file, how jsf can pass from index to welcome?

When I view source, source page is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body lang="en">
<form id="j_idt5" name="j_idt5" method="post" action="/Test/index.xhtml" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="j_idt5" value="j_idt5" />
<input type="submit" name="j_idt5:j_idt6" value="Submit" /><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="-5517223312856481273:-1605099621977497303" autocomplete="off" />
</form></body> 
</html>

I realy don't see a "link" or action to "welcome", in hidden field, I see ViewState but it auto generate and change when I refesh page. I also don't see any JavaScript code for load welcome page.

After run with <h:link>, I think, when first time, jsf read index.xhtml and show it, after submit be press, jsf read index.xhtml and get action of this button and show welcome page.

BuZZ-dEE
  • 6,075
  • 12
  • 66
  • 96
Son Le
  • 229
  • 5
  • 16
  • You do see a `
    ` and a ``, right? You'd better learn some [basic HTML](http://htmldog.com/guides/html/beginner/) before diving into JSF. For starters: this approach is bad design. Related: http://stackoverflow.com/questions/15521451/how-to-make-url-reflect-the-current-page-and-not-the-previous-one, http://stackoverflow.com/questions/4317684/when-should-i-use-houtputlink-instead-of-hcommandlink/ and http://stackoverflow.com/questions/3909267/differences-between-action-and-actionlistener/
    – BalusC Sep 22 '14 at 08:06

1 Answers1

0

from Mkyong site - http://www.mkyong.com/jsf2/jsf-2-0-hello-world-example/

In JSF 1.x, you had to declare the “navigation rule” in “faces-config.xml“, to tell which page to display when the button is clicked. In JSF 2.0, you can put the page name directly in the button’s “action” attribute. For simple navigation, it’s more than enough, but, for complex navigation, you are still advised to use the “navigation rule” in “faces-config.xml“.

I suggest read some tutorials for JSF 2 or buy book -> Give me a JSF 2.0 tutorial

Community
  • 1
  • 1
MWL
  • 9
  • 2