Search code examples
jsfprimefacesprettyfaces

how to use prettyface with jsf


I want rewrite URL of my project.

I am using primefaces. My XHTML file like below

<ui:composition template="/html/Template.xhtml">
    <ui:define name="content">
          <h:form id="frmId">
             <p:inputtext value=#{bean.ajavaclass.variable} />
             <p:commandbutton value="check" action=#{bean.ajavaclass.fun1}/>               
           </h:form>
   </ui:define>
</ui:composition>

My sessionscoped bean class

public class Bean implements Serializable{
 private AJavaClass ajavaclass=new AJavaClass();

getter and setter of ajavaclass obj...

}

My AJavaclass

public class AJavaClass implements Serializable{

      private String variable;

      public void fun1(){
        if(variable.equals('CODE')){
          fun2();
      }

    public void fun2(){

          FacesContext.getCurrentInstance().getExternalContext()
                        .redirect("./page2.xhtml");
      }

    }

this is working fine. if user enter CODE in textbox its redirecting to page2.xhtml. but the url is http://localhost:8080/projectname/page2.xhtml

i want to hide the page name from the URL. how to do this using pretty faces.

i might wrongly configured pretty-config.xml, this is my configuration

<url-mapping id="CODE">
        <pattern value="/" />
        <view-id value="page2.xhtml" />
</url-mapping>

but i need to know 1.what i need to return from fun2? 2.fun2 is not directly handling the action operation is that a problem,if it is how could i handle. 3.Or without pretty is there any ways in jsf or primefaces?


Solution

  • You probably just need to use a leading slash in your view-id:

    <url-mapping id="CODE">
        <pattern value="/" />
        <view-id value="/page2.xhtml" />
    </url-mapping>
    

    Using a view-id value of page2.xhtml will not be understood. It must be /page2.xhtml