0

So I've read some about JSF and I've come to think about the creation of web application where website describes the XHTML document. These documents are connected to special java program, "beans", which can provide enhanced functionality on the server side such as database or complex calculations.

If a method in a bean is called from an XHTML document linked to a command button component (this typically happens when the user clicks a button) and returns a string X, it means that the next site will be called and opened(X.xhtml.)

In this way the web application can toggle between different sites. Now I've been wondering is this appropriate? And what are the advantages and disadvantages this entails way to switch sides?

Jack Bonneman
  • 1,821
  • 18
  • 24
  • This is a bad practice. You should use `h:button`, not `h:commandButton`. See also http://stackoverflow.com/a/15523045/ Note that I fixed the completely wrong question title. The kind of subjective question as indicated in original title should be asked in a discussion forum or chat box, not here on a Q&A site. – BalusC Jun 05 '13 at 13:33

1 Answers1

0

First, XHTML is not always JSF, you'd rather talk of facelets in your case (which might help you better conduct your research and learning btw). Otherwise, a typical scenario is to call the action attribute of a h:commandLink or h:commandButton, it's up to you to fill that attribute with the String result of whatever bean methode you see fit.

Example :

<h:commandButton value="submit" type="submit" action="#{yourBean.redirectMethod}" />

The redirectMethod should return a String type containing the redirection to some page :

public String redirectMethod() {
        return "somePage.xhtml?faces-redirect=true";
    }

Now I've been whondering is this appropriate?

In my experience, yes.

and what are the advantages and disadvantages this entails way to switch sides?

This link seem to carry some elements of answer : forward vs redirection in JSF. The conclusion relates to the pros and cons, it appears that : "Default page forward mechanism is more faster if compare to page redirection, because the page redirect added extra HTTP request to the server."

And in order to do a simple forward, you just go back to redirectMethod and take off the ?faces-redirect=true piece of code, thus having something like :

public String redirectMethod() {
        return "somePage.xhtml";
    }

Good luck !

P.S : start whith this, really helpfull : https://stackoverflow.com/tags/jsf/info

Community
  • 1
  • 1
Akheloes
  • 1,352
  • 3
  • 11
  • 28
  • Still, there's a deepth to your question I feel haven't been answered (the pros and cons), the reason for that is that I am still a beginner myself, I made some research and found this link that might be of help : http://www.mkyong.com/jsf2/jsf-page-forward-vs-page-redirect/ – Akheloes Jun 05 '13 at 12:51
  • I edited the answer, hope it's clearer now and I think the pros and cons part of your question have been fairly answered now, at least hope so ! – Akheloes Jun 05 '13 at 13:05
  • WoW, I really appreciate the time that you took to search the answer down and all information I can actually get is really helpfull, dont matter if your a beginner or a highly skilled professional. Thanks for the information digging!:) –  Jun 06 '13 at 06:49
  • My pleasure, have a great adventure in your learning :D ! – Akheloes Jun 06 '13 at 08:56