[solved] Problem with prettyfaces + a4j:commandLink

Splash Forums PrettyFaces Users [solved] Problem with prettyfaces + a4j:commandLink

Tagged: , ,

This topic contains 7 replies, has 5 voices, and was last updated by  Ricardo Amaral 7 years, 2 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #17733

    smitha.h.rao
    Participant

    Hi,

    I have an existing jsf application in which I am trying to use prettyfaces for cleaner urls. For direct urls prettyfaces is working. But when my page has ajax rendered reions like below, the ajax calls are not working.

    for eg. I have a page called testDetails which was earlier to prettyfaces integration used to work using below url:

    localhost/skill/testDetails.faces?testId=12

    Which also has following region using ajax calls for rendering:

    <a4j:outputPanel ajaxRendered=”true”>

    <rich:dataGrid id=”commentList”

    value=”#{testDetailsAction.candidateTestDetails}”

    var=”commentVO” elements=”5″

    columns=”1″ >

    <h:panelGrid columns=”1″ >

    <h:column>

    <h:outputText value=”#{commentVO.comment}” />

    </h:column>

    </h:panelGrid>

    </rich:dataGrid>

    <h:panelGrid columns=”2″ >

    <h:column>

    <a4j:commandLink id=”prevLink”

    action=”#{testDetailsAction.goNext}”

    rendered=”#{testDetailsAction.pageNo > 1}” reRender=”prevLink,nextLink,commentList”>

    <h:outputText value=”previous..” styleClass=”aug” style=”color:blue;”/>

    <f:param name=”commentsPage” value=”#{testDetailsAction.pageNo -1}”/>

    </a4j:commandLink>

    </h:column>

    <h:column>

    <a4j:commandLink id=”nextLink”

    action=”#{testDetailsAction.goNext}”

    rendered=”#{testDetailsAction.displayNext}” reRender=”prevLink,nextLink,commentList”>

    <h:outputText value=”more..” styleClass=”aug” style=”color:blue;”/>

    <f:param name=”commentsPage” value=”#{testDetailsAction.pageNo +1}”/>

    </a4j:commandLink>

    </h:column>

    </h:panelGrid>

    </a4j:outputPanel>

    In pretty-config.xml I have following:

    <url-mapping id=”testDetails”>

    <pattern> /testDetails/#{testDetailsAction.strTestId}</pattern>

    <query-param name=”commentsPage”>#{testDetailsAction.strCommentsPage}</query-param>

    <view-id> /login/testDetails.faces </view-id>

    <action>#{testDetailsAction.getTestDetails}</action>

    </url-mapping>

    Can you please help me how can I make ajax components work with pretty faces?

    Thanks

    Smitha

    #19874

    Could you please post your web.xml mappings? I believe this may be a simple filter configuration issue.

    Take a look at FAQ #2: http://ocpsoft.com/prettyfaces/#FAQ

    Thanks!

    Lincoln

    #19875

    smitha.h.rao
    Participant

    <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>REQUEST</dispatcher>

    <dispatcher>FORWARD</dispatcher>

    <dispatcher>ERROR</dispatcher>

    </filter-mapping>

    My web.xml has all the dispatcher tags.

    full web.xml is pasted below:

    <?xml version=”1.0″ encoding=”UTF-8″?>

    <web-app xmlns=”http://java.sun.com/xml/ns/j2ee&#8221;

    xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221; version=”2.5″

    xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd“>

    <!– Display name for this application –>

    <display-name>skill</display-name>

    <context-param>

    <param-name>org.richfaces.SKIN</param-name>

    <param-value>plain</param-value>

    </context-param>

    <context-param>

    <param-name>contextConfigLocation</param-name>

    <param-value>

    /WEB-INF/applicationContext.xml /WEB-INF/controller-servlet.xml

    </param-value>

    </context-param>

    <context-param>

    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>

    <param-value>client</param-value>

    <description>

    State saving method: “client” or “server” (= default) See

    JSF Specification 2.5.2

    </description>

    </context-param>

    <context-param>

    <param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>

    <param-value>true</param-value>

    <description>

    This parameter tells MyFaces if javascript code should be

    allowed in the rendered HTML output. If javascript is

    allowed, command_link anchors will have javascript code that

    submits the corresponding form. If javascript is not

    allowed, the state saving info and nested parameters will be

    added as url parameters. Default: “true”

    </description>

    </context-param>

    <context-param>

    <param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>

    <param-value>false</param-value>

    <description>

    This parameter tells MyFaces if javascript code should be

    allowed in the rendered HTML output. If javascript is

    allowed, command_link anchors will have javascript code that

    submits the corresponding form. If javascript is not

    allowed, the state saving info and nested parameters will be

    added as url parameters. Default: “false”

    Setting this param to true should be combined with

    STATE_SAVING_METHOD “server” for best results.

    This is an EXPERIMENTAL feature. You also have to enable the

    detector filter/filter mapping below to get JavaScript

    detection working.

    </description>

    </context-param>

    <context-param>

    <param-name>org.apache.myfaces.PRETTY_HTML</param-name>

    <param-value>true</param-value>

    <description>

    If true, rendered HTML code will be formatted, so that it is

    “human readable”. i.e. additional line separators and

    whitespace will be written, that do not influence the HTML

    code. Default: “true”

    </description>

    </context-param>

    <context-param>

    <param-name>org.apache.myfaces.AUTO_SCROLL</param-name>

    <param-value>false</param-value>

    <description>

    If true, a javascript function will be rendered that is able

    to restore the former vertical scroll on every request.

    Convenient feature if you have pages with long lists and you

    do not want the browser page to always jump to the top if

    you trigger a link or button action that stays on the same

    page. Default: “false”

    </description>

    </context-param>

    <context-param>

    <param-name>javax.faces.CONFIG_FILES</param-name>

    <param-value>

    /WEB-INF/faces-config.xml,/WEB-INF/faces-managed-beans.xml,/WEB-INF/faces-navigation.xml

    </param-value>

    </context-param>

    <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>REQUEST</dispatcher>

    <dispatcher>FORWARD</dispatcher>

    <dispatcher>ERROR</dispatcher>

    </filter-mapping>

    <!– Richfaces configuration –>

    <filter>

    <filter-name>richfaces</filter-name>

    <display-name>RichFaces Filter</display-name>

    <filter-class>org.ajax4jsf.Filter</filter-class>

    </filter>

    <!– Richfaces configuration –>

    <!– myfaces configuration starts here –>

    <filter>

    <filter-name>MyFacesExtensionsFilter</filter-name>

    <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>

    <init-param>

    <param-name>maxFileSize</param-name>

    <param-value>20m</param-value>

    <description>Set the size limit for uploaded files.

    Format: 10 – 10 bytes

    10k – 10 KB

    10m – 10 MB

    1g – 1 GB

    </description>

    </init-param>

    </filter>

    <filter>

    <filter-name>GeekFilter</filter-name>

    <display-name>Geek Login Filter</display-name>

    <filter-class>com.skill.view.bean.common.GeekFilter</filter-class>

    </filter>

    <filter>

    <filter-name>ForumFilter</filter-name>

    <display-name>Forum Filter</display-name>

    <filter-class>com.skill.view.bean.common.ForumFilter</filter-class>

    </filter>

    <!– extension mapping for adding <script/>, <link/>, and other resource tags to JSF-pages –>

    <filter-mapping>

    <filter-name>MyFacesExtensionsFilter</filter-name>

    <!– servlet-name must match the name of your javax.faces.webapp.FacesServlet entry –>

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

    </filter-mapping>

    <!– extension mapping for serving page-independent resources (javascript, stylesheets, images, etc.) –>

    <filter-mapping>

    <filter-name>MyFacesExtensionsFilter</filter-name>

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

    </filter-mapping>

    <filter-mapping>

    <filter-name>MyFacesExtensionsFilter</filter-name>

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

    </filter-mapping>

    <filter-mapping>

    <filter-name>MyFacesExtensionsFilter</filter-name>

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

    </filter-mapping>

    <!– myfaces configuration ends here –>

    <filter-mapping>

    <filter-name>GeekFilter</filter-name>

    <url-pattern>/login/*</url-pattern>

    </filter-mapping>

    <filter-mapping>

    <filter-name>GeekFilter</filter-name>

    <url-pattern>/register/*</url-pattern>

    </filter-mapping>

    <filter-mapping>

    <filter-name>GeekFilter</filter-name>

    <url-pattern>/admin/*</url-pattern>

    </filter-mapping>

    <filter-mapping>

    <filter-name>GeekFilter</filter-name>

    <url-pattern>/organization/*</url-pattern>

    </filter-mapping>

    <filter-mapping>

    <filter-name>GeekFilter</filter-name>

    <url-pattern>/question/*</url-pattern>

    </filter-mapping>

    <!–

    <filter-mapping>

    <filter-name>ForumFilter</filter-name>

    <url-pattern>/forum/*</url-pattern>

    </filter-mapping>

    –>

    <filter-mapping>

    <filter-name>richfaces</filter-name>

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

    </filter-mapping>

    <!– For Forum integration –>

    <filter>

    <filter-name>clickstream-jforum</filter-name>

    <filter-class>net.jforum.util.legacy.clickstream.ClickstreamFilter</filter-class>

    </filter>

    <filter-mapping>

    <filter-name>clickstream-jforum</filter-name>

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

    </filter-mapping>

    <!– ******* –>

    <!–

    <listener>

    <listener-class>

    org.springframework.web.context.request.RequestContextListener

    </listener-class>

    </listener>

    –>

    <listener>

    <listener-class>com.skill.view.util.SkillSessionListener</listener-class>

    </listener>

    <listener>

    <listener-class>com.skill.view.util.SkillFileLoaderCache</listener-class>

    </listener>

    <listener>

    <listener-class>

    org.springframework.web.context.ContextLoaderListener

    </listener-class>

    </listener>

    <!– For Forum integration –>

    <listener>

    <listener-class>net.jforum.ForumSessionListener</listener-class>

    </listener>

    <!– ******* –>

    <!– Richfaces configuration –>

    <!–

    <servlet>

    <servlet-name>SpringContextServlet</servlet-name>

    <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>

    <load-on-startup>1</load-on-startup>

    </servlet>

    –>

    <servlet>

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

    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>

    <load-on-startup>1</load-on-startup>

    </servlet>

    <servlet>

    <servlet-name>action</servlet-name>

    <servlet-class>

    org.apache.struts.action.ActionServlet

    </servlet-class>

    <init-param>

    <param-name>config</param-name>

    <param-value>/WEB-INF/struts-config.xml</param-value>

    </init-param>

    <init-param>

    <param-name>debug</param-name>

    <param-value>3</param-value>

    </init-param>

    <init-param>

    <param-name>detail</param-name>

    <param-value>3</param-value>

    </init-param>

    <load-on-startup>0</load-on-startup>

    </servlet>

    <servlet>

    <servlet-name>TilesServet</servlet-name>

    <servlet-class>

    org.apache.struts.tiles.TilesServlet

    </servlet-class>

    <init-param>

    <param-name>definitions-config</param-name>

    <param-value>/WEB-INF/tiles-defs.xml</param-value>

    </init-param>

    <init-param>

    <param-name>definitions-parser-validate</param-name>

    <param-value>true</param-value>

    </init-param>

    <load-on-startup>2</load-on-startup>

    </servlet>

    <!– For apache chart component –>

    <servlet>

    <servlet-name>Chartlet</servlet-name>

    <servlet-class>net.sf.jsfcomp.chartcreator.Chartlet</servlet-class>

    </servlet>

    <servlet>

    <servlet-name>controller</servlet-name>

    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

    <load-on-startup>1</load-on-startup>

    </servlet>

    <!– Jforum integration –>

    <!– JForum Controller –>

    <servlet>

    <servlet-name>jforum</servlet-name>

    <servlet-class>net.jforum.JForum</servlet-class>

    <init-param>

    <param-name>development</param-name>

    <param-value>true</param-value>

    </init-param>

    </servlet>

    <!– Installer –>

    <servlet>

    <servlet-name>install</servlet-name>

    <servlet-class>net.jforum.InstallServlet</servlet-class>

    <init-param>

    <param-name>development</param-name>

    <param-value>true</param-value>

    </init-param>

    </servlet>

    <!– Servlet for logout –>

    <servlet>

    <servlet-name>ForumLogoutFilter</servlet-name>

    <servlet-class>com.skill.forum.ForumLogoutFilter</servlet-class>

    </servlet>

    <servlet>

    <description>Servlets helps adding tag data to a Test or Guru</description>

    <display-name>Tag Servlet</display-name>

    <servlet-name>TagServlet</servlet-name>

    <servlet-class>com.skill.view.bean.guru.test.TagServlet</servlet-class>

    </servlet>

    <servlet>

    <description>This is the description of my J2EE component</description>

    <display-name>This is the display name of my J2EE component</display-name>

    <servlet-name>GuruTagServlet</servlet-name>

    <servlet-class>com.skill.view.bean.guru.GuruTagServlet</servlet-class>

    </servlet>

    <!– ************ –>

    <servlet-mapping>

    <servlet-name>controller</servlet-name>

    <url-pattern>/servlet/*</url-pattern>

    </servlet-mapping>

    <!– Faces Servlet Mapping –>

    <servlet-mapping>

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

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

    </servlet-mapping>

    <servlet-mapping>

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

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

    </servlet-mapping>

    <!– For apache chart component –>

    <servlet-mapping>

    <servlet-name>Chartlet</servlet-name>

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

    </servlet-mapping>

    <!– Jforum Integration –>

    <!– Mapping –>

    <servlet-mapping>

    <servlet-name>install</servlet-name>

    <url-pattern>/install/install.page</url-pattern>

    </servlet-mapping>

    <servlet-mapping>

    <servlet-name>jforum</servlet-name>

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

    </servlet-mapping>

    <servlet-mapping>

    <servlet-name>ForumLogoutFilter</servlet-name>

    <url-pattern>/servlet/ForumLogoutFilter</url-pattern>

    </servlet-mapping>

    <servlet-mapping>

    <servlet-name>TagServlet</servlet-name>

    <url-pattern>/servlet/TagServlet</url-pattern>

    </servlet-mapping>

    <servlet-mapping>

    <servlet-name>GuruTagServlet</servlet-name>

    <url-pattern>/servlet/GuruTagServlet</url-pattern>

    </servlet-mapping>

    <!– *********** –>

    <session-config>

    <session-timeout>35<!– minutes –></session-timeout>

    </session-config>

    <error-page>

    <error-code>500</error-code>

    <location>/login/sessionExpired.faces</location>

    </error-page>

    <!– <error-page>

    <error-code>404</error-code>

    <location>/login/sessionExpired.faces</location>

    </error-page>–>

    <error-page>

    <exception-type>javax.servlet.ServletException</exception-type>

    <location>/login/sessionExpired.faces</location>

    </error-page>

    <error-page>

    <exception-type>java.lang.NullPointerException</exception-type>

    <location>/login/sessionExpired.faces</location>

    </error-page>

    <error-page>

    <exception-type>java.lang.RuntimeException</exception-type>

    <location>/login/sessionExpired.faces</location>

    </error-page>

    <taglib>

    <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>

    <taglib-location>/WEB-INF/struts-html.tld</taglib-location>

    </taglib>

    <taglib>

    <taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri>

    <taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>

    </taglib>

    <taglib>

    <taglib-uri>/WEB-INF/jsf_core.tld</taglib-uri>

    <taglib-location>/WEB-INF/jsf_core.tld</taglib-location>

    </taglib>

    <taglib>

    <taglib-uri>/WEB-INF/html_basic.tld</taglib-uri>

    <taglib-location>/WEB-INF/html_basic.tld</taglib-location>

    </taglib>

    </web-app>

    #19876

    But your other filters don’t… they need to:

    <filter-name>ForumFilter</filter-name>

    <display-name>Forum Filter</display-name>

    <filter-class>com.skill.view.bean.common.ForumFilter</filter-class>

    </filter>

    <!– extension mapping for adding <script/>, <link/>, and other resource tags to JSF-pages –>

    <filter-mapping>

    <filter-name>MyFacesExtensionsFilter</filter-name>

    <!– servlet-name must match the name of your javax.faces.webapp.FacesServlet entry –>

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

    </filter-mapping>

    <!– extension mapping for serving page-independent resources (javascript, stylesheets, images, etc.) –>

    <filter-mapping>

    <filter-name>MyFacesExtensionsFilter</filter-name>

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

    </filter-mapping>

    <filter-mapping>

    <filter-name>MyFacesExtensionsFilter</filter-name>

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

    </filter-mapping>

    <filter-mapping>

    <filter-name>MyFacesExtensionsFilter</filter-name>

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

    </filter-mapping>

    #19877

    smitha.h.rao
    Participant

    Thanks Lincoln,

    Its working now. Prettyfaces is a great work!!

    #19878

    Anonymous

    Hi Smitha.h.rao, hi Lincoln,

    I see you have solved this problem.

    Can you please post your solution :)?

    What have you changed? pretyy-config.xml.

    Thanks,

    Alex

    #19879

    goutham.rao
    Participant

    Hi Lincoln, smitha,

    I would like to have a look at the changes made to web.xml as well.

    “Take a look at FAQ #2: http://ocpsoft.com/prettyfaces/#FAQ

    I am using primefaces (jsf 2.0 env ) and it uses only a servlet . Should I define a new filter and specif the primefaces servlet same within its tags?.

    Regards,

    Goutham

    #19880

    Ricardo Amaral
    Participant

    Hi guys,

    First of all, Lincoln, congratulations for your nice work!

    I’m also having problem with pretty faces + richfaces (a4j). Probably it’s something i’m doing wrong.

    Here is my problem:

    All my app is in AJAX with a4j and jquery, and i’m developing something like an online store.

    Two major problems with an ajax only app is history and access things by URL.

    With pretty faces I think I can fix both. But i’m not getting the right config yet.

    I managed to access products by URL configuring to something like this w/ pretty faces: http://localhost:8080/myappname/search/coke, and everything works great, and the page with products is returned.

    The page returned have a4j components like commandLinks, commandButtons and a form.

    Looking to the rendered html code I could see the commandLink is becoming the following:

    <a href="#" id="generalForm:j_id23:0:j_id28:7:category" name="generalForm:j_id23:0:j_id28:7:category" onclick="A4J.AJAX.Submit('generalForm',event,{'similarityGroupingId':'generalForm:j_id23:0:j_id28:7:category','parameters':{'generalForm:j_id23:0:j_id28:7:category':'generalForm:j_id23:0:j_id28:7:category'} ,'actionUrl':'/myappname/search/coke;jsessionid=A7E70CC70CB271F353B04E5A867F3F07'} );return false;">Link Label</a>

    Pay attention to the param ‘actionUrl’, it is being rendered with the actual URL /myappname/search/coke, and every time I click the link, the same backing bean method is being called, but another method in the same backing bean should be called. This is going on because the pretty faces mapping is working! :)

    Debugging the a4j javascript code, I could see this actionUrl param is used to mount the XmlHttpRequest object destination.

    The question is obvious, how to make it work? :)

    My env: tomcat 6.0.24 + JSF 1.2 (myfaces implementation 1.2.8) + richfaces 3.3.2 + servlet 2.5 + JSP 2.1 + facelets 1.1.15

    Thanks in advance!

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

You must be logged in to reply to this topic.

Comments are closed.