Problems with 3.1.0

Splash Forums PrettyFaces Users Problems with 3.1.0

This topic contains 6 replies, has 3 voices, and was last updated by  oprisa_vlad 6 years, 10 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #17830

    oprisa_vlad
    Participant

    Hello

    I am trying to follow the documentation steps to integrate prettyfaces in my webApp using prettyfaces-jsf12-3.1.0.jar.

    So…

    in web.xml the first filter

    <filter>
    <filter-name>Pretty Filter</filter-name>
    <filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
    </filter>

    <filter-mapping>
    <filter-name>Pretty Filter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>ERROR</dispatcher>
    </filter-mapping>

    in pretty-config.xml

    <pretty-config xmlns="http://ocpsoft.com/prettyfaces/3.1.1-SNAPSHOT"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://ocpsoft.com/prettyfaces/3.1.1-SNAPSHOT
    http://ocpsoft.com/xml/ns/prettyfaces/ocpsoft-pretty-faces-3.1.1-SNAPSHOT.xsd">

    <url-mapping id="home">
    <pattern value="/home"/>
    <view-id>#{urlBean.getHomeViewId}</view-id>
    </url-mapping>
    ...
    </pretty-config>

    in faces-config.xml

    <managed-bean>
    <managed-bean-name>urlBean</managed-bean-name>
    <managed-bean-class><...path...>.view.url.UrlBean</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>

    in my UrlBean i have

    String appName = "demo"
    public String getHomeViewId() {
    String rst = "/" + appName + "/pages/test/Home.jsf";
    System.out.println("- verify " + rst);
    return rst;
    }

    I was so surprised to spend a lot of time for nothing…

    The main problem is that i get a HTTP Status 404 – /demo/home page when i provide the

    http://localhost:8080/demo/home&#8221; url.

    With log on debug i get

    10:57:32,875 DEBUG PrettyFilter:66 - Character encoding: null
    10:57:32,890 DEBUG PrettyFilter:66 - Character encoding: null
    10:57:32,968 DEBUG PrettyFilter:66 - Character encoding: null
    11:06:52,953 DEBUG PrettyFilter:66 - Character encoding: null
    11:06:52,953 DEBUG PrettyFilter:66 - Character encoding: null
    - verify /demo/pages/test/Home.jsf
    11:06:52,953 DEBUG PrettyFilter:66 - Character encoding: UTF-8

    If I check with the “unpretty” faces url works just fine.

    If I set /demo/pages/test/Home.jsf in pretty-cofig.xml <view-id> tag works just fine but it’s not what i wanted.

    So … could anyone tell me what i’ve done wrong???

    Thanks in advance.

    PS: Forgot to mention that initially i started with ocpsoft-pretty-faces-1.1.3.jar that worked just fine until i needed

    return “pretty:”

    Now this works but i’m left without dynamic view-id.

    There are no left-over jar’s in my project and I tripple-checked the configuration.

    #20463

    Is demo the context path of your webapp? In that case you won’t need to add demo in front of the view id in your getHomeViewId() method as the view id is expected to be relative to the context path.

    #20464

    oprisa_vlad
    Participant

    I realize now that i did not explain myself in a complete manner.

    The main concept is to have MyDemo.ear (meening MyDemo as a contextPath).

    This app will have more that one View (User interface), just like skins but more custom and not css made, having same jsp file structure.

    Each module will be named

    demo1

    demo2

    demoN

    so the directory structure of my web (directory) is

    MyDemo/web/

    MyDemo/web/demo1/pages/test/Home.jsp

    MyDemo/web/demo1/pages/test/css/test.css

    MyDemo/web/demo2/pages/test/Home.jsp

    MyDemo/web/demoN/pages/test/Home.jsp

    so in the url i will want

    http://localhost:8080/MyDemo/home

    to be managed according to appName variable (demo1, demo2 … demoN)

    (The ambiguity in my first post was that demo (contextpath) and demo as a directory name were the same.)

    so the

    <pattern value=”/home”/>

    considering the relative path i want it to be

    String rst = “/” + appName + “/pages/test/Home.jsf”;

    eg:

    http://localhost:8080/MyDemo / demo1 /pages/test/Home.jsf

    After more digging my friend found a workaround:

    String rst = “/faces/” + appName + “/pages/test/Home.jsp”;

    to be cautgh by the second filter

    <servlet-mapping>

    <servlet-name>Faces Servlet</servlet-name>

    <url-pattern>*.jsf</url-pattern>

    </servlet-mapping>

    <!– this one –>

    <servlet-mapping>

    <servlet-name>Faces Servlet</servlet-name>

    <url-pattern>/faces/*</url-pattern>

    </servlet-mapping>

    I had declared both in my web.xml file.

    I don’t find this normal. Am I wrong ?

    Also if anybody can provide me with a link on how to use prettyfaces to do something like this:

    1.

    first request: ../siteCase/value1/value2

    having

    <url-mapping id=”siteCase”>

    <pattern value=”/siteCase”/#{viewBean.value1}/#{viewBean.value2}>

    <view-id>#{urlBean.getSiteCase}</view-id>

    </url-mapping>

    public String getSiteCase() {

    String rst = “pretty:home”;

    if (loggedIn) {

    rst = “/” + appName + “/pages/test/SiteCase.jsf”;

    } else {

    //here i save the this.desiredUrl

    rst = “pretty:login”;

    }

    return rst;

    }

    2.

    He is not logged in and will be redirected to the login page

    3.

    He passes login and i want to redirect him to the UrlBean.this.desiredUrl

    My problem is that i don’t know how to save this.desiredUrl (and also “parameters”) and how to redirect

    public String login(){

    //login stuff

    return “pretty:???”;//and the parameters ?

    }

    Thanks in advance!

    #20465

    It seems like the dynaview is not working correctly if you are using an extension-based mapping for the FacesServlet. That’s very strange. Could you try to use .xhtml instead of .jsf in your dynaview? Perhaps this will help.

    Regarding your login page: You could either save the original URL by writing it to a query parameter or you could temporarily save it in the session. I personally would prefer the first option. This would look something like this:

    <url-mapping id="login">
    <pattern value="/login">
    <query-param name="url"> #{loginBean.redirectUrl} </query-param>
    </url-mapping>

    In your UrlBean:

    public String getSiteCase() {
    if (loggedIn) {

    // ..

    } else {

    // set value of the query parameter
    loginBean.setRedirectUrl( request.getRequestURI() );

    // perform the redirect. The query parameter value will
    // be read from the loginBean
    return "pretty:login";

    }

    This way you will have the correct URL in the LoginBean and can directly send a redirect in case of a successful login.

    Here are some relevant references to the documentation regarding this:

    http://ocpsoft.com/docs/prettyfaces/3.1.0/en-US/html/Configuration.html#config.queryparams

    http://ocpsoft.com/docs/prettyfaces/3.1.0/en-US/html/navigation.html#navigation.actions

    #20466

    Hey guys, I looked into the DynaView engine and in order to tell what’s wrong, I need to know which page is not found.

    From what you’ve posted so far, it seems like the DynaView method is actually being called just fine. Since your ‘verify – url’ System.out.println() statement does appear.

    This makes me think that there’s something else wrong, but without a closer look, it will be hard to tell.

    If you could step-debug through com.ocpsoft.pretty.faces.event.PrettyPhaseListener (line 113 – in processDynaView()) – and see what’s actually going on for us, that would help a lot.

    Either that or set your log level to TRACE, and see what the DynaView engine tells you is going on:

    log.trace("Invoking DynaView method: " + viewId);
    log.trace("Forwarding to DynaView: " + viewId);

    Thanks,

    Lincoln

    #20467

    Ah, I should have said if you could post the TRACE logs here that would be great :)

    #20468

    oprisa_vlad
    Participant

    Ok, no problem Lincoln. I will reconfigure the test case and i will post whe result.

    Just that I am currently going out of town for 2 days (national hollyday, barbecues and stuff :P) and i will post in like … 48 hours.

    Thanks verry much Christian for the help and references.

    Hope u don’t mind the delay…

    Best regards guys!

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

Comments are closed.