Newbie: what is the equivalent of passing request parameters?

Hi-
I am new to JSF. I have read many tutorials and articles. I still don't get one concept about passing parameters. Note: I don't want to store stuff in the session unless I have to.
Let's say I have a page with a list of users. I layout the page with a panelGrid. Each row of the table has the first and last name of the user. If a user clicks on the name of a user on the user list, it should go to the user profile page. The backing bean for the user list page will be the UserListBean. It has a method called getUsers() that returns a List of User objects.
For the View User page, I have a ViewUserBean. The ViewUserBean retrieve the entire profile for that user.
How do I pass the user ID to the ViewUserBean? In struts, I would pass it as a request parameter (I would manually write the link URL with the userID). I know I can use the request like that in JSF, but that seems ugly. I looked at the code of the J2EE bookstore tutorial and it does a funky thing with all sorts of data stored in the session.
What is the best way to request a page and "pass in" a userID?
Thanks for your help.
Adam

I have a case on my current project very similar to your case. What you want, very simply, is an easy way to allow faces to handle URLs like http://www.domain.com/showUserDetails?userId=50
The natural trouble is that when loading the page, there is no action to use to prefetch the User object based on the Request Parameters in JSF.
All the solutions above either rely on the session or they are exceedingly complex. This case is actually very easy to do and is very straight forward using Managed Properties and a Request Scope bean...
Here is the rather straight forward solution I used...
First, make a "ShowUserDetailsBean" which represents the "logic" for this page.
public class ShowUserDetailsBean
    /** Will point to the actual user service after dependency injection*/
    private UserService userService;
    /** Will hold the userId from the HTTP Request Parameters*/
    private String userId;
    /** Will hold a lazy loaded copy of the User object matching userId*/
    private User user;
    public void setUserService(UserService userService) {
        this.userService = userService;  //dependecy injection
    public void setUserId(String userId) {
       this.userId = userId;  //dependency injection
    /** Lazy loads the User object matching the UserId */
    public User getUser() {
        //Trap the case where the URL has no userId
        if (userId == null) return null;
        if (user == null) {
            user = userService.getUser(userId);  //Lazy Load
        return user;
}Next, configure the managed properties in faces-config.xml
<faces-config xmlns="http://java.sun.com/JSF/Configuration">
  <managed-bean>
    <managed-bean-name>userService</managed-bean-name>
    <managed-bean-class>foo.UserServiceImpl</managed-bean-class>
    <managed-bean-scope>application</managed-bean-scope>
  </managed-bean>
  <managed-bean>
    <managed-bean-name>showUserDetails</managed-bean-name>
    <managed-bean-class>foo.ShowUserDetailsBean</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
    <managed-property>
      <property-name>userService</property-name>
      <property-class>foo.UserService</property-class>
      <value>#{userService}</value>
    </managed-property>
    <managed-property>
      <property-name>userId</property-name>
      <property-class>java.lang.String</property-class>
      <value>#{param.userId}</value>
    </managed-property>
  </managed-bean>Finally, you just make your webpage as you normally would...
<h:outputText value="#{showUserDetails.user.userId}"/>
<h:outputText value="#{showUserDetails.user.firstName}"/>
<h:outputText value="#{showUserDetails.user.lastName}"/>
Now you're ready to test, so you visit the page
http://www.domain.com/showUserDetails?userId=50
And your user details with userId=50 appears!
It's just that simple!
Regards,
Doug
Caveat: I haven't added any sample logic to handle cases where you visit:
http://www.domain.com/showUserDetails
without specifying a userId. I suggest you add some basic logic to your page to handle this case more gracefully.

Similar Messages

  • What is the equivalent selection in BI7? (Following BW 3.5 How to...Set up

    Hi,
    What is the equivalent selection in BI7? (Following BW 3.5 How to...Set up BW Statistics)
    I am trying to install BW statistics and all the good things that come with it for BI7. Following the instructions in a document that I was directed to on this site, in SBIW, I installed and replicated all the datasource in under “TCT” tree (Technical content)
    The instruction is for versions prior to BI7 and I had to make modifications as I go.
    Now, this instruction direct me to go to:
    rsa1, “Bi Content” (left) and then “InfoProviders by InfoAreas” and select all InfoProviders for the InfoAreas ”BW Statistics” and “BW Metadata” under the node “Technical Content”.
    1.
    In BI7, there is no ”BW Statistics” and “BW Metadata” infoareas under “Technical Content” if I follow the directions strictly.
    What is the equivalent of this in BI7?
    2.
    In the instructions, the author continues to collect these InfoAreas from under “Technical Content”:
    BW Data Slice
    BW Features characteristics
    BW Metadata
    BW Statistics
    In BI7, do we need exactly these? Or, now different? Should I just transfer all the infoareas under “Technical Content”? What is the disadvantage of collecting a ALL?
    Thanks

    Thanks for the link and i believe it will come in handing.
    Yet, it does not have the step by step installation information on page 46 of this link:
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/c8c4d794-0501-0010-a693-918a17e663cc
    Do you have the BI7 version of this link?
    Also, ssame stewise info is on page 4 of this:
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/5401ab90-0201-0010-b394-99ffdb15235b   
    If you have the BI7 version of this link also, it will answer my question.
    Thanks

  • What is the equivalent for 'On Change of' Event in ABAP OBJECTS?

    What is the equivalent for 'On Change of' Event in ABAP OBJECTS?  and how to use it in LOOP control?

    hi,
    There is no such Equivalent in OO ABAP.
    You have to Raise your own Event within tha class checking the value of the field whose value is changing.
    Regards
    Sumit Agarwal

  • What is the equivalent function of this...

    the following codes are in awt form, what are the equivalent swt form of the following function? thank you for your help
    ActionListener listener = new MenuItemActionListener(panel);
    *MenuItemActionListener(panel); is the awt
    Component parent; (Component is the awt)
    and using Color.<what_color>
    Again thank you!

    if you're planning on coming here getting the forum to re-write all your awt code in swt bit by bit, forget it. as far as I know, there's only 2 or 3 people who post here that know swt, and nobody's in the business of rewriting code on other people's behalf anyway. the swt documentation that comes with eclipse, plus the javadocs for swt, are more than good enough for you to manage this

  • What is the use of passing String[] args in main() method?

    what is the use of passing String[] args in main() method?
    Is there any specific use for this ?

    actually my sir asked me the same question & I gave
    the same reply as given by you........but he further
    asked what is the use of this also??
    ie accepting cmd line args at runtime??is there any
    specific purpose ??Apart from the one you just mentioned? No

  • What is the equivalent subtype of 'Text'?

    Hi experts,
    i have created one field using 'user defined field-management' menu with "type alphanumeric and structure text". now i want to create that field by code. so, i have selected oUserFieldsMD.Type = SAPbobsCOM.BoFieldTypes.db_Alpha but the option for subtype "text" is not coming in intellisense.
    so, what is the equivalent subtype for structure "text".
    Thanking
    Vishwajit Kumar

    It's actually a strange one - it's not a subtype in the DI for some reason, it appears as a main type under "Memo"
    oUserFieldsMD.Type = SAPbobsCOM.BoFieldTypes.db_Memo
    That will get you what you require it will appear in B1 as type alphanumeric and subtype text! Like I said, it's a weird one

  • What is the Equivalent tool of CHDBPASS in NetWeaver 7

    I want to change the password of SYSTEM  and SYS in NetWeaver 7. What is the Equivalent tool of CHDBPASS in NetWeaver 7
    Edited by: Sebastian Sebaraj on Apr 3, 2008 3:34 PM

    Hai,
    For the SAP BASIS >= Release 6.10:
    Use the oradbusr.sql script. This script is attached to the note 50088. The script is valid for Oracle and Unix. Use the following syntax
               sqlplus /NOLOG @oradbusr. sql SCHEMAOWNER UNIX SAP_SID x
    The SCHEMAOWNER is either SAPR3 or has to start with SAP followed by the three digit schema id (example: SAPPRD).
    On Unix x is a dummy parameter and may e. g. be set to  X.
    To change the password for the SAPR3 or SAP<SID> user you have to use the following command:
               brconnect -u system/<syst_pwd> -f chpass -o SAPR3 -p <new_sap_pwd>
    or
               brconnect -u system/<syst_pwd> -f chpass -o sap< sid> -p <new_sap_pwd>
    Thanks and Regards,

  • What is the use of passing object reference to itself ?

    What is the use of passing object reference to itself ?
    regards,
    namanc

    There is an use for returning an object reference from itself, for instance:
    class C {
    public:
         C append(C c) {
             // do something interesting here, and then:
             return this;
    }You can "chain" calls, like this:
    C c = new C();
    C d = new C();
    C e = new C();
    c.append (d).append (e);Maybe the OP has "inverted" the common usage, or thought about a static method of a class C that requires a parameter of type C (effectively being a sort of "non-static method").
    class C {
        static void doAnotherThing (C c) {
            c.doSomething(); //-- effectively C.doAnotherThing(c) is an "alternative syntax" for c.doSomething()

  • Help! what is the equivalent focal length of ipad 4 camera?

    what is the equivalent focal length of ipad 4 camera?

    Your apps is not providing enough information.
    I use ExifWizPro App.
    http://i1224.photobucket.com/albums/ee374/Diavonex/51b4d31dae7f841332878c77bfe13 9f1_zpscc0bd8a4.jpg

  • What's the equivalent of Windows' Alt+F in OSX?

    Hi all,
    Noob questions... What's the equivalent of Alt+F (too choose the File menu) in OS X?
    -Al

    Hello again Al,
    Simple answer is:
    *Control+F2 then F-key*
    (or *control+F2 then FI* if there is another menu beginning with an F)
    Enable (keep it permanently enabled) Full Keyboard Access by hitting control+F1.
    Now you can use all control+F commands listed in
    System Preferences > Keyboard & Mouse > Keyboard Shortcuts
    In your "alt+F" equivalent example, here's what you would do:
    Control+F2 then Arrow (left or right) then Arrow Down,
    and you can also type the first letter(s) of a command's name:
    Example in Safari, File menu:
    hit "P" to get "Page Setup"
    or
    hit "PR" to get "Print"
    Return key commands the action itself once you've reached it.
    Axel

  • What's the equivalent of Choice() in Swing

    What's the equivalent of java.awt.Choice() in javax.swing?
    I've been stuck on that one for a while.
    Thank you

    Here is a link showing all the Swing components:
    http://java.sun.com/docs/books/tutorial/uiswing/components/components.html
    Take some time to go through the Table of Contents as well. Its a great introduction to Swing.

  • What is the difference between workbench request and customizing request

    hi gurus
    can anyone suggest me
    what is the difference between
    workbench request and
    customizing request
    abaper ll work on which request
    thank you
    regards
    kals.

    A quick  search in the forum would have taken you to this answer
    Workbench Requests
    When you change a Repository object of the ABAP Workbench, a query window appears in which you need to specify a Workbench request. You can only save the changes if you have assigned the object to a change request.
    Workbench requests and the tasks assigned to them are normally used to record changes to Repository objects and Customizing for all clients. However, you can also include client-specific Customizing.
    Whether the changes to Repository objects are transported depends on whether a transport route is defined from the current SAP System for the package of these objects. From the system settings, the system automatically determines whether the change requests are transportable and to which target system they should be transported.
    Customizing requests
    Customizing requests record client-specific Customizing settings made in a single client (the source client of the request).
    Automatic recording of configuration activities in the Customizing work for a client can be activated or deactivated for each client with Client Control. If automatic recording is active, a query window appears when you change Customizing settings, asking you to specify a Customizing request.
    Whether Customizing requests are transported or not, does not depend on the objects entered, as is the case with Workbench change requests. The Customizing requests in an SAP System (or in a client if you use Extended Transport Control) are either all transportable or all local, depending on the system setting. The system uses the standard transport layer to determine automatically whether the change requests are transportable and to which target system they should be transported. However, you can change this manually.

  • What is the equivalent Windows laptop?

    What's the best Windows laptop equivalent to the MBP 15.4"? My vote goes to the Thinkpad T60p.

    sigh
    He asked what's the equivalent. When people ask for the "equivalent", they mean comparable hardware at a similar price. Most techies (who are what Apple's trying to court right now) will want to see similar specs, maybe compare weights, size, etc. We don't really care about immeasurable things like "design" and relatively useless stuff like the "patent pending magnetic power connector" (I have never, ever tripped over my laptops' wires. Neither has my family. And over the course of the last 10 years I've owned 6 laptops).
    As for trying to compare, if you honestly don't know what you're talking about, please don't speak. Dual Athlons are not the equivalent of an Intel Core Duo. Dual Athlons are a lot faster and guzzle tremendous amounts of energy. If you want to make a valid comparison, look at the Inspiron 9300 with Core Duo and a similar video card.
    Please don't let the reality distortion field and marketingspeak affect what you say to others. This is a big year for Apple to court us geeks, and we really, REALLY don't like the reality distortion field and marketingspeak. Just give us specs and benchmarks. Thanks.

  • Passing Request Parameters to Non JSF Page

    I want to pass request parameters from a JSF page (Page1.jsp) to a non JSF page (paramTest.jsp) and am having trouble.
    The parameters are 'null' in the non JSF page.
    Here is code (in Page1.java) that is called when 'button1' is clicked in Page1.jsp (modified from JSF, Bergsten p.167):
    public String button1_action() {
            FacesContext context = javax.faces.context.FacesContext.getCurrentInstance();
            ExternalContext ec = context.getExternalContext();
            try {
                ec.redirect("http://xxx/paramTest.jsp");
            } catch (Exception e) {
                // print exception information in the server log
                log("Exception occurred when redirecting page", e);
                error("Trouble redirecting page");
                return null;
            context.responseComplete();
            return "success";
        }Here is Page1.jsp code: <?xml version="1.0" encoding="UTF-8"?>
    <jsp:root version="1.2" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:jsp="http://java.sun.com/JSP/Page">
        <jsp:directive.page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"/>
        <jsp:text><![CDATA[
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    ]]></jsp:text>
        <f:view>
            <html lang="en-US" xml:lang="en-US">
                <head>
                    <meta content="no-cache" http-equiv="Cache-Control"/>
                    <meta content="no-cache" http-equiv="Pragma"/>
                    <title>Page1 Title</title>
                    <link href="resources/stylesheet.css" rel="stylesheet" type="text/css"/>
                </head>
                <body style="-rave-layout: grid">
                    <h:form binding="#{Page1.form1}" id="form1">
                        <h:inputText binding="#{Page1.name}" id="name" style="left: 144px; top: 96px; position: absolute"/>
                        <h:outputLabel binding="#{Page1.componentLabel1}" for="componentLabel1" id="componentLabel1" style="left: 72px; top: 96px; position: absolute">
                            <h:outputText binding="#{Page1.componentLabel1Text}" id="componentLabel1Text" value="Name:"/>
                        </h:outputLabel>
                        <h:commandButton action="#{Page1.button1_action}" binding="#{Page1.button1}" id="button1" onclick="this.form.submit() style="left: 120px; top: 144px; position: absolute" value="Submit"/>
                        <h:messages binding="#{Page1.messageList1}" errorClass="errorMessage" fatalClass="fatalMessage" id="messageList1" infoClass="infoMessage"
                            showDetail="true" style="left: 480px; top: 72px; position: absolute" warnClass="warnMessage"/>
                    </h:form>
                </body>
            </html>
        </f:view>
    </jsp:root>Here is the rendered Page1.jsp html: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xml:lang="en-US" lang="en-US">
    <head>
    <meta http-equiv="Cache-Control" content="no-cache"/><meta http-equiv="Pragma" content="no-cache"/>
    <title>Page1 Title</title>
    <link type="text/css" rel="stylesheet" href="resources/stylesheet.css"/>
    </head>
    <body style="-rave-layout: grid">
    <form id="form1" method="post" action="/cenwkd/faces/Page1.jsp;jsessionid=79A5577F53DAAEDF164C5D33F33D8327" enctype="application/x-www-form-urlencoded">
    <input id="form1:name" type="text" name="form1:name" style="left: 120px; top: 96px; position: absolute" />
    <label id="form1:componentLabel1" for="form1:componentLabel1" style="left: 72px; top: 96px; position: absolute">
    <span id="form1:componentLabel1Text">Name:</span></label>
    <input id="form1:button1" type="submit" name="form1:button1" value="Submit" onclick="" style="left: 120px; top: 144px; position: absolute" />
    <input type="hidden" name="form1" value="form1" />
    </form>
    </body>
    </html> Here is the source for a test jsp, paramTest.jsp: <html>
    <head>
    <title>
    paramTest
    </title>
    </head>
    <body>
    <h2><%= request.getParameter("form1:name")%></h2>
    <%-- Also tried: request.getParameter("name"), "name" is the original 'id' value for the text field entered in Creator
         it apparently is changed to "form1:name" when the html is rendered--%>
    </body>
    </html>Here is the rendered html from paramTest.jsp: <html>
    <head>
    <title>
    paramTest
    </title>
    </head>
    <body>
    <h2>null</h2>
    </body>
    </html>Any help would be much appreciated.

    Hi,
    I dont see any parameters that you are trying to pass in the below code.
    public String button1_action() {
    FacesContext context = javax.faces.context.FacesContext.getCurrentInstance();
    ExternalContext ec = context.getExternalContext();
    try {
    ec.redirect("http://xxx/paramTest.jsp");
    } catch (Exception e) {
    // print exception information in the server log
    log("Exception occurred when redirecting page", e);
    error("Trouble redirecting page");
    return null;
    context.responseComplete();
    return "success";
    }

  • HT5509 What is the guided acess pass code because I didn't set one....

    Okay so I put my guided acess on my iPod not knowing what it was and now I can't change apps.. What's the pass code because I didn't set one.

    See:
    How To Get Out Of Guided Access On iOS6? : TechNGuide
    In case i forget my guided access...: Apple Support Communities
    SOS I cannot Exit Guided access: Apple Support Communities

Maybe you are looking for