Url mapping with bean

Splash Forums Rewrite Users Url mapping with bean

Tagged: 

This topic contains 7 replies, has 3 voices, and was last updated by  Christian Kaltepoth 2 years, 4 months ago.

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

    vished
    Participant

    Hello,

    first of all: prettyfaces is very nice!
    I´m very new in prettyfaces and spend some hours for create a URL with a bean.

    I´m using CDI
    I try it with the annotations and with the pretty-config.
    If I have no bean in my pattern, the url will rewrite correct. But if I have an bean in the pattern, the page isn´t rewrite.

    I use primefaces as well.

    Here my code:

    <url-mapping id="viewCategory">
    		<pattern value="/store/#{ contentEditController.content.title }/" />
    		<view-id value="/contentEdit.jsf" />
    	</url-mapping>

    my web.xml_

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    	version="2.5">
    
    	<context-param>
    		<param-name>primefaces.THEME</param-name>
    		<param-value>none</param-value>
    	</context-param>
    
    	<context-param>
    		<param-name>com.ocpsoft.pretty.BASE_PACKAGES</param-name>
    		<param-value>com.eventplanner</param-value>
    	</context-param>
    
    	<context-param>
    		<param-name>com.ocpsoft.pretty.DEVELOPMENT</param-name>
    		<param-value>true</param-value>
    	</context-param>
    
    	<filter>
    		<filter-name>OCPsoft Rewrite Filter</filter-name>
    		<filter-class>org.ocpsoft.rewrite.servlet.RewriteFilter</filter-class>
    		<async-supported>true</async-supported>
    	</filter>
    
    	<filter-mapping>
    		<filter-name>OCPsoft Rewrite Filter</filter-name>
    		<url-pattern>/*</url-pattern>
    		<dispatcher>FORWARD</dispatcher>
    		<dispatcher>REQUEST</dispatcher>
    		<dispatcher>INCLUDE</dispatcher>
    		<dispatcher>ASYNC</dispatcher>
    		<dispatcher>ERROR</dispatcher>
    	</filter-mapping>
    
    	<!-- WIEDER AKTIVIEREN !!! <context-param> <param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE 
    		</param-name> <param-value>true</param-value> </context-param> <context-param> 
    		<param-name>javax.faces.STATE_SAVING_METHOD</param-name> <param-value>server</param-value> 
    		</context-param> <context-param> <param-name>javax.faces.PROJECT_STAGE</param-name> 
    		<param-value>Production</param-value> </context-param> -->
    
    	<context-param>
    		<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    		<param-value>server</param-value>
    	</context-param>
    
    	<context-param>
    		<param-name>com.sun.faces.writeStateAtFormEnd</param-name>
    		<param-value>false</param-value>
    	</context-param>
    
    	<filter>
    		<filter-name>PrimeFaces FileUpload Filter</filter-name>
    		<filter-class>org.primefaces.webapp.filter.FileUploadFilter
    		</filter-class>
    	</filter>
    	<filter-mapping>
    		<filter-name>PrimeFaces FileUpload Filter</filter-name>
    		<servlet-name>Faces Servlet</servlet-name>
    	</filter-mapping>
    
    	<context-param>
    		<param-name>primefaces.UPLOADER</param-name>
    		<param-value>commons</param-value>
    	</context-param>
    
    	<!-- Um richtige Uhrzeit anzuzeigen -->
    	<context-param>
    		<param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE
    		</param-name>
    		<param-value>true</param-value>
    	</context-param>
    
    	<!-- Start For activate Shrio -->
    	<listener>
    		<listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener
    		</listener-class>
    	</listener>
    
    	<filter>
    		<filter-name>ShiroFilter</filter-name>
    		<filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
    	</filter>
    
    	<filter-mapping>
    		<filter-name>ShiroFilter</filter-name>
    		<url-pattern>/*</url-pattern>
    		<dispatcher>REQUEST</dispatcher>
    		<dispatcher>FORWARD</dispatcher>
    		<dispatcher>INCLUDE</dispatcher>
    		<dispatcher>ERROR</dispatcher>
    	</filter-mapping>
    	<!-- End For activate Shrio -->
    
    	<!-- Für Paging bei JSF (Anfang) -->
    	<filter>
    		<filter-name>noCacheFilter</filter-name>
    		<filter-class>com.eventplanner.util.NoCacheFilter</filter-class>
    	</filter>
    	<filter-mapping>
    		<filter-name>noCacheFilter</filter-name>
    		<url-pattern>*.jsf</url-pattern>
    		<url-pattern>*.xhtml</url-pattern>
    	</filter-mapping>
    	<!-- Ende Paging bei JSF (Anfang) -->
    
    </web-app>

    here my commandLink in contentList.xhtml which redirect to my contentEdit.xhtml (this page should rewrite to the ID of the entity (content):

    		<p:commandLink ajax="false" resetValues="true"
    					update=":addContentForm"
    					action="#{contentListController.viewDetailPage(content)}">
    					<h:graphicImage url="#{resource['images/icons/pencil.png']}"
    						title="Editieren" alt="Editieren" />						
    				</p:commandLink>

    Should I have some code in contentEdit.xhtml ?

    my pom.xml:

    		<dependency>
    			<groupId>org.ocpsoft.rewrite</groupId>
    			<artifactId>rewrite-servlet</artifactId>
    			<version>2.0.11.Final</version>
    		</dependency>
    		<dependency>
    			<groupId>org.ocpsoft.rewrite</groupId>
    			<artifactId>rewrite-config-prettyfaces</artifactId>
    			<version>2.0.11.Final</version>
    		</dependency>
    
    		<dependency>
    			<groupId>org.ocpsoft.rewrite</groupId>
    			<artifactId>rewrite-integration-cdi</artifactId>
    			<version>2.0.11.Final</version>
    		</dependency>

    Thank you so much for your help!

    #26005

    You are missing the most interesting part. What do you return from this method.

    action="#{contentListController.viewDetailPage(content)}"

    In your case it should do something like this:

    public String viewDetailPage(String content) {
    
      // or something similar
      this.content = content;
    
      return "pretty:viewCategory";
    
    }
    

    BTW: Calling an action method in a table row which initializes the details view is bad practice. This typically breaks bookmarking. You view page URL should contain all the information that is required to identify the item that is viewed. And initialization of the page should work even if the URL is manually entered into the browser bar. Typically you can than use a h:link in your table which simply renders a standard HTML link.

    #26039

    vished
    Participant

    thanks.
    Have you a specific example for this?
    Are there any examples with CDI Annotations and Primefaces (p:commandLink / p:commandButton…)

    #26043

    What are you looking for an example of, specifically?

    #26044

    You could have a look at this old demo I created some time ago:

    https://github.com/chkal/wjax11-demo

    #26045

    vished
    Participant

    thank you very much. Nice example.

    Have you an example for primefaces Button (p:commandButton, p:commandLink), too?
    How looks there the mapping?

    I want to use all in the CDI-Beans. So should I need the pretty-config.xml ?

    • This reply was modified 2 years, 4 months ago by  vished.
    #26049

    You should also have a look at Rewrite, which is the successor of Rewrite.

    http://ocpsoft.org/rewrite/

    In Rewrite you build your configuration with a fluent Java API. You should have a look at it.

    There is also a migration guide if you want to convert your existing PrettyFaces application to Rewrite:

    http://ocpsoft.org/rewrite/docs/migration/prettyfaces3

    #26055

    BTW: There is a Rewrite version of the sample I posted before:

    https://github.com/ocpsoft/rewrite/tree/master/showcase/bookstore

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

You must be logged in to reply to this topic.

Comments are closed.