How to handle "query-param" on bean surfaces?

I have a list of users (dataTable with a link to userId that points to /user/view/{userId} ). When this userId link is clicked, 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 the first user and http://localhost:8080/user/view/2 for the second, etc., but I don’t I know how to use the userId value after loading this page.

How can I achieve this with PrettyFaces URLRewriteFilter ? How can I load data using the value #{bean.userId} (1,2 etc.) From the bean backup as soon as PrettyFaces enters it when the page is available. Can someone 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.

+4
source share
2 answers

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

 @Named("bean") @RequestScoped public class LoginBean { public String loadLoggedUser() { if ( userId != null ) { this.user = user.findById(userId); return null; } return "failure"; } } 

Secondly, you need to add <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 defined the action of the page to be performed on the bean, #{bean.loadLoggedUser} , when the URL matching our pattern is requested. For example: /user/view/2 .

+5
source
 <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> 

send http://ocpsoft.com/prettyfaces/

0
source

Source: https://habr.com/ru/post/1393931/


All Articles