4

I have a list of users(dataTable with a link on userId that points to /user/view/{userId}). On clicking this userId link, the browser is redirected to the 'view' page as expected.

I have a page that accepts the url pattern http://localhost:8080/user/view/1 for first user and http://localhost:8080/user/view/2 for the second etc, but I don't know how to use the userId value once this page loads.

How can I achieve this with PrettyFaces URLRewriteFilter? How can I load data using the value of #{bean.userId} (1,2, etc) from the backing bean once PrettyFaces has injected it when the page is accessed. Can anybody explain?

<url-mapping id="view">
<pattern value="/user/view/#{bean.userId}/" />
<view-id value="/userview.jsf" />
</url-mapping>

I am using JSF2+Primefaces.3.0.M3+Prettyfaces-jsf2.3.3.2 with GAE.

Lincoln
  • 3,151
  • 17
  • 22
lofa in
  • 317
  • 1
  • 8
  • 26

2 Answers2

5

You need a page-load action, specified by the <action> element in your URL-mapping configuration. First, you will need a method in your bean, like this:

@Named("bean")
@RequestScoped
public class LoginBean {

public String loadLoggedUser() {
    if ( userId != null ) {
        this.user = user.findById(userId);
        return null;
    }
    return "failure";
}
}

Second, you will need to add the <action> to your URL-mapping:

<url-mapping id="view">
     <pattern value="/user/view/#{bean.userId}/" />
     <view-id value="/userview.jsf" />
     <action>#{bean.loadLoggedUser}</action>
</url-mapping>

Here we have defined a page-action to be executed on a bean, #{bean.loadLoggedUser}, when a URL matching our pattern is requested. For example: /user/view/2.

Lincoln
  • 3,151
  • 17
  • 22
Kushan
  • 10,657
  • 4
  • 37
  • 41
0
<url-mapping id="login">
        <pattern> /user/view/1 </pattern>
        <view-id> /legacy/user/login.jsp </view-id> <!-- Non JSF View Id -->
    </url-mapping>
    <url-mapping id="register">
        <pattern>/user/view/1 </pattern>
        <view-id>/faces/user/register.jsf</view-id> <!-- JSF View Id -->
    </url-mapping>
<url-mapping id="login1">
        <pattern> /user/view/2 </pattern>
        <view-id> /legacy/user/login2.jsp </view-id> <!-- Non JSF View Id -->
    </url-mapping>
    <url-mapping id="register2">
        <pattern>/user/view/2 </pattern>
        <view-id>/faces/user/register2.jsf</view-id> <!-- JSF View Id -->
    </url-mapping>

refer http://ocpsoft.com/prettyfaces/

Hemant Metalia
  • 29,730
  • 18
  • 72
  • 91
  • But I have a lot of users . So I need something like ` /user/view/#{bean.userId} `. And I was asking how can I process this `#{bean.userId}` in the backing bean? – lofa in Jan 31 '12 at 09:20
  • To clarify, I think what you mean is "I want to load data using the value of `#{bean.userId}` when the page is accessed." – Lincoln Feb 02 '12 at 04:47