Results 1 to 3 of 3
  1. #1
    crispy is offline Member
    Join Date
    Jan 2008
    Posts
    1
    Rep Power
    0

    Default how to read a form with JFS

    hi all,
    i have a simple form like this:

    Java Code:
    <h:form styleClass="form" id="registrationForm">
    	<table>
    		<tr>
    			<td>Lastname:</td>
    			<td><h:inputText id="lastname" value=""></h:inputText></td>
    		</tr>
    		<tr>
    			<td>Firstname:</td>
    			<td><h:inputText id="firstname" value=""></h:inputText></td>
    		</tr>
    		<tr>
    			<td>Username:</td>
    			<td><h:inputText id="username" value=""></h:inputText></td>
    		</tr>
    		<tr>
    			<td>E-Mail:</td>
    			<td><h:inputText id="email" value=""></h:inputText></td>
    		</tr>
    		<tr>
    			<td><br>
    			</td>
    			<td></td>
    		</tr>
    		<tr>
    			<td>Password:</td>
    			<td><h:inputSecret id="password1" styleClass="inputSecret" value=""></h:inputSecret></td>
    		</tr>
    		<tr>
    			<td>Confirm Password:</td>
    			<td><h:inputSecret id="" styleClass="inputSecret" value="test3t2"></h:inputSecret></td>
    		</tr>
    	</table>
    	<br>
    	<hx:commandExButton value="Submit"
    				action="#{pc_Register.doRegistration}" styleClass="commandExButton"
    				id="button1"></hx:commandExButton>
    	<br>
    </h:form>
    now how can i get this data in my doRegistration() method?

    when i do something like this
    this.getRequestParam().values().toArray();

    i get an array with all my data, but i'm sure there's a way to get a specific value, for example the username by something like getRequestParam().getParam('username'); or something similar.

    thanks for any help!

  2. #2
    loveshore is offline Member
    Join Date
    Jan 2008
    Posts
    2
    Rep Power
    0

    Default

    Crispy,
    What i understand is that, you want to get all your component values in the doRegisteration() method.For this you don't need to put any extra effort. Since all managed beans are POJO's you can use the instance variables directly in the instance method.
    I'm also a junior in the JSF world and hope i'm not confusing you.Anyway i'm attaching a piece code that can give you a more clear picture on this.


    public class UserBean
    {
    private String firstName;

    /**
    * @return
    */
    public String getFirstName() {
    return firstName;
    }

    /**
    * @param string
    */
    public void setFirstName(String string) {
    firstName = string;
    }
    public String registerUser() // your doRegistration method here
    {
    System.out.println("***ADDING REGISTERED USER ** ***"+firstName);
    //You may add this user details to database or process in some other way, as usual
    return "registered";
    }

    }

  3. #3
    Join Date
    May 2008
    Posts
    2
    Rep Power
    0

    Default solution to your JSF parameters problem

    hi,

    I am new to this forum, anyways, the solution to your problem:

    In the "doRegistration" method of your bean, get the HttpServletRequest object as below:

    HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstanc e().getExternalContext().getRequest();

    then,

    use the below code to get the paramters of each of the "id":

    String x = request.getParameter("registrationForm:lastname");

    NOTE: The "colon" is very important. formid:component_id

    Hope this definitely help you.

    Srinivas.

Similar Threads

  1. Form Notes
    By creel in forum Java Applets
    Replies: 0
    Last Post: 02-02-2008, 01:25 AM
  2. 1 form 2 servlets
    By sandor in forum Java Servlet
    Replies: 2
    Last Post: 01-22-2008, 10:47 AM
  3. center a form
    By tommy in forum New To Java
    Replies: 2
    Last Post: 08-06-2007, 08:47 PM
  4. Replies: 1
    Last Post: 06-07-2007, 05:29 AM
  5. Form Help Pls
    By CoOlbOyCoOl in forum NetBeans
    Replies: 4
    Last Post: 05-27-2007, 08:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •