Results 1 to 3 of 3
Thread: how to read a form with JFS
- 01-17-2008, 12:59 PM #1
Member
- Join Date
- Jan 2008
- Posts
- 1
- Rep Power
- 0
how to read a form with JFS
hi all,
i have a simple form like this:
now how can i get this data in my doRegistration() method?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>
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!
- 01-20-2008, 05:26 AM #2
Member
- Join Date
- Jan 2008
- Posts
- 2
- Rep Power
- 0
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";
}
}
- 05-01-2008, 03:07 PM #3
Member
- Join Date
- May 2008
- Posts
- 2
- Rep Power
- 0
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
-
Form Notes
By creel in forum Java AppletsReplies: 0Last Post: 02-02-2008, 01:25 AM -
1 form 2 servlets
By sandor in forum Java ServletReplies: 2Last Post: 01-22-2008, 10:47 AM -
center a form
By tommy in forum New To JavaReplies: 2Last Post: 08-06-2007, 08:47 PM -
Some form to read pixels in Java and to handle Another plate VGA?
By Albert in forum Advanced JavaReplies: 1Last Post: 06-07-2007, 05:29 AM -
Form Help Pls
By CoOlbOyCoOl in forum NetBeansReplies: 4Last Post: 05-27-2007, 08:31 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks