Problem with PrettyFaces and Primefaces

Splash Forums PrettyFaces Users Problem with PrettyFaces and Primefaces

This topic contains 12 replies, has 2 voices, and was last updated by  kency 11 years, 3 months ago.

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #17793

    kency
    Participant

    Hello Lincoln i have problem with PrettyFaces, i was found it on stackoverflow and it greatful for pretty URL, i want apply it to my project.

    My Project using Primefaces. After that i apply prettyfaces to it, i config in web.xml and pretty-config.xml , but in my index.xhtml , my template not display, it can’t find path of image, style.css. . . e.g

    And in folder admincp when i enter into it, it occur twice admincp example http://localhost/admincp/admincp/login.jsf

    What’s happen with my project?

    my code

    Mapping in web.xml

    ===============================================================

    <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>

    ====================================================

    Filter user for admincp folder

    =====================================================

    <filter>
    <filter-name>userLoginFilter</filter-name>
    <filter-class>com.mcgraw.controller.UserLoginFilter</filter-class>
    <init-param>
    <param-name>loginPage</param-name>
    <param-value>/login.xhtml</param-value>
    </init-param>
    </filter>
    <filter-mapping>
    <filter-name>userLoginFilter</filter-name>
    <url-pattern>/faces/*</url-pattern>
    <url-pattern>*.jsf</url-pattern>

    </filter-mapping>

    // if url-pattern not use /faces/* it will redirect to admincp/login.jsf/admincp/login.jsf/admincp/login.jsf/admincp/login.jsf/admincp/login.jsf/admincp/login.jsf

    =================================================

    Servlet Filder User login into admincp

    ==================================================

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse res = (HttpServletResponse) response;
    LoginController controller = (LoginController) req.getSession().getAttribute("loginController");
    if (controller == null || !controller.isLoggedIn()) {

    if(!req.getRequestURI().endsWith("admin/login.jsf")){
    res.sendRedirect("admin/login.jsf");

    }else {
    chain.doFilter(request, response);
    }

    } else {

    chain.doFilter(request, response);
    }

    }

    ======================================================

    pretty-config.xml

    ======================================================

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

    <!-- Begin RewriteRules -->

    <rewrite trailingSlash="append" toCase="lowercase" />
    <rewrite match="^/old-url/(w+)/$" substitute="/new_url/$1/" redirect="301" />

    <!-- Begin UrlMappings -->

    <url-mapping id="home">
    <pattern value="/" />
    <view-id>/faces/index.xhtml</view-id>
    </url-mapping>

    </pretty-config>

    #20252

    You need to use an absolute path to the CSS file. If you post your HTML CSS-include source code, we may be able to point you in the right direction.

    #20253

    Also. Remove the example rewrite rules from your pretty-config.xml file… they will break things for you because they are just examples….

    #20254

    kency
    Participant

    My HTML Source Code

    index.xhtml

    ==============================

    <?xml version="1.0" encoding="UTF-8"?>
    <!--
    To change this template, choose Tools | Templates
    and open the template in the editor.
    -->
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.prime.com.tr/ui"
    xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>mcGraw Library - The Library Online</title>
    <p:resources />
    <link href="css/styles.css" rel="stylesheet" type="text/css" />
    <link rel="icon" href="img/icon.ico" />
    <link type="text/css" rel="stylesheet" href="../admin/template/ui-darkness/skin.css" />
    <script type="text/javascript" src="js/iepngfix_tilebg.js"></script>
    <script type="text/javascript" src="js/iepngfix.js"></script>

    </h:head>
    <h:body>
    <p>
    <table id="tableBorder" align="center" >
    <tr>
    <td>
    <div id="mainWrap" >
    <div id="mainPanel" >
    <br/> <br/>
    <ui:include src="/com/header/header.xhtml" id="header"/>

    <br/> <br/> <br/> <br/> <br/> <br/><br/> <br/><br/>
    <div id="leftPanel">
    <ui:include src="demo.xhtml" id="demo"/>

    </div>
    <div id="rightPanel">
    <div class="contacts">
    <h2>Login</h2>
    <p>Username:</p> <h:inputText value="- enter your username -" onfocus="if(this.value=='- enter your name -'){this.value=''}" onblur="if(this.value=='')this.value='- enter your name -'" style="float: right;width: 190px"/>
    <p>Password:</p> <input name="name" type="text" value="- enter your email -" onfocus="if(this.value=='- enter your email -')this.value=''" onblur="if(this.value=='')this.value='- enter your email -'" style="float: right;width: 190px;"/>
    <div class="blank2"></div><div class="blank"></div><div class="blank"></div><div class="blank"></div><div class="blank"></div><a href="#" style="float: right">Submit</a>
    </div>

    </div>
    <ui:include src="/com/footer/footer.xhtml" id="footer"/>
    </div>
    </div>

    </td>
    </tr>
    </table>
    </p>
    </h:body>
    </html>

    ========================

    #20255

    kency
    Participant

    i was remove rewrite example rule, it work normal but not rewrite

    can you give me some rule for write my rewrire rule

    thank you

    #20256

    You probably don’t need <rewrite> rules…

    This is your problem:

    <link href="css/styles.css" rel="stylesheet" type="text/css" />
    <link type="text/css" rel="stylesheet" href="../admin/template/ui-darkness/skin.css" />
    <script type="text/javascript" src="js/iepngfix_tilebg.js"></script>
    <script type="text/javascript" src="js/iepngfix.js"></script>

    These should all use absolute paths from the root of the server, and in fact, you should probably be using JSF2’s resource relocation feature instead:

    <h:outputScript>

    <h:outputStylesheet>

    By specifying relative paths, the browser will attempt to load the files depending on the current URL, and when you add PrettyFaces, the current URL will not be the same as it was before…

    You need something like this:

    <link href="#{request.contextPath}/css/styles.css" rel="stylesheet" type="text/css" />
    <link type="text/css" rel="stylesheet" href="#{request.contextPath}/admin/template/ui-darkness/skin.css" />
    <script type="text/javascript" src="#{request.contextPath}/js/iepngfix_tilebg.js"></script>
    <script type="text/javascript" src="#{request.contextPath}/js/iepngfix.js"></script>

    #20257

    kency
    Participant

    it means i must write JSF Managebeand to get context path?

    the code will be:

    public void getContextPath(){
    ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();xt
    exContext.getRealPath();
    }

    can you give me rule for write rewrite rule?

    #20258

    kency
    Participant

    can i use pretty faces without rewrite rule?

    #20259

    “can i use pretty faces without rewrite rule? “

    Of course.

    “it means i must write JSF Managebeand to get context path?”

    No. It should already be available under the #{request.contextPath} object. If that does not work, try #{requestScope.contextPath}

    I assume you are using JSF1.2?

    You can also just hard-code the context path if that is simpler…

    <link href="/approot/css/styles.css" rel="stylesheet" type="text/css" />

    #20260

    Let me know if you have any more trouble with this and I’ll try to see if I can make more sense :)

    #20261

    kency
    Participant

    i’m using JSF 2.0,requestScope is array requestScope[]

    if i want write rewrite rule how can i write? what rule for write rewrite rule?

    #20262

    kency
    Participant

    Hi Lincoln i have new problem with PrettyFaces when redirect on servlet

    in pretty-config.xml i config my admincp login.xmhtl page follow:

    `<url-mapping id=”adminlogin”>

    <pattern value=”/admin/login” />

    <view-id>/faces/admin/login.xhtml</view-id>

    </url-mapping>`

    but in servlet i filter when user not login into admin but type url into index.xhtml of admincp it will be redirect to login.xhtml

    when it redirect true url is : http://localhost/admin/login

    but it not redirect such link above , it redirect to http://localhost/admin/admin/login

    ===========================================

    i was change servlet Filter User login follow:

    ============================================

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse res = (HttpServletResponse) response;
    LoginController controller = (LoginController) req.getSession().getAttribute("loginController");
    if (controller == null || !controller.isLoggedIn()) {

    if(!req.getRequestURI().endsWith("admin/login")){
    res.sendRedirect("admin/login");

    }else {
    chain.doFilter(request, response);
    }

    } else {

    chain.doFilter(request, response);
    }

    }

    ======================================

    in web.xml i was config for servlet filter

    <filter>
    <filter-name>userLoginFilter</filter-name>
    <filter-class>com.mcgraw.controller.UserLoginFilter</filter-class>
    <init-param>
    <param-name>loginPage</param-name>
    <param-value>/login.xhtml</param-value>
    </init-param>
    </filter>
    <filter-mapping>
    <filter-name>userLoginFilter</filter-name>
    <url-pattern>/admin/*</url-pattern>
    <url-pattern>*.jsf</url-pattern>

    </filter-mapping>

    how can i solve it?

    Thank you

    Best Regards

    #20263

    kency
    Participant

    Hi Lincoln i was solved my problem

    thank you

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

The forum ‘PrettyFaces Users’ is closed to new topics and replies.

Comments are closed.