0

I need a understanding. Why did i find my self still on the same page when submitting some inputs in JSF file , have a look :

<!--<b>codes below belong to <i>page1.xhtml</i></b>-->      
   <h:form>
        <table>
           <tr> 
                <td>Name:</td>
                <td><h:inputText value="#{user.name}"/></td>
            </tr>
         </table>   
    </h:form>
    <p><h:commandButton value="Login" action="page2"/></p>

After pressing "Login" , it showed value of #{user.name} from page2.xhtml, but the link itself is still faces/page1.xhtml , why not faces/page2.xhtml ? Could someone explain it to me ? does it mean that in JSF we access everything just from one page?

I try to make something like this :

<h:form action="page2.xhtml"> 

but then i realize there is no such "action" on "<h:form>" tag

Fevly Pallar
  • 3,059
  • 2
  • 15
  • 19
  • The `action` button must be set in `h:commandButton` and not in `h:fom`. You still don't mention which version of JSF are you working with. – Aritz Jul 19 '14 at 17:08
  • you must refer to this page to get your answer I think this will help you http://stackoverflow.com/questions/11670129/how-to-create-hcommandbutton-in-jsf-to-open-a-new-page – Prikshit Jul 19 '14 at 17:05

2 Answers2

1

in JSF when you submit a value it's normally to a java bean: a class who process the information,to creat a bean you could you use a code like this:

package beans

import javax.faces.bean.RequestScoped
import javax.faces.bean.ManagedBean

@RequestScoped
@ManagedBean
public class SignInBean {

private String username;

//getter and setter for username

  public void register(){
    //add to data base
    //redirect to new page
  }
}

and in th xhtml file

<h:inputText value="#{signInBean.username}"/>

<h:commandButton value="Login" action="#{signInBean.register"/>
user1928596
  • 1,503
  • 16
  • 21
  • this is kinda good solution too, but redirecting to a new page from bean class is just something that i haven't learnt before.. – Fevly Pallar Jul 20 '14 at 06:21
  • this how you do it: http://stackoverflow.com/questions/5955130/jsf-page-redirecting-from-java-bean It can be very useful if you redirect to multiple pages depending on a certain condition – user1928596 Jul 20 '14 at 14:12
1

I believe what you are looking for is the answers to this question: How to make URL reflect the current page (and not the previous one).

In your example I would say you ideally would want to use the option

Send a redirect after POST.
For example, showing list of all data after successful create/update/delete, etc.
Community
  • 1
  • 1
Jaqen H'ghar
  • 4,305
  • 2
  • 14
  • 26