Submit a form with a value from a list...help me....

Hi guys,

i've a question for you.

I'm developing a jsf application,i have a login page in which the user has tree fields to insert, a login(free text), a password(free text) and a team.

I want the user can choices team(student or worker) from a scrollable list of two values.

The form have to be authenticated by this action method called by backing bean.

My doubles are about how can submit the value selected from the 2values-list(selectOneMenu i think..) to authenticationBean.

Please help me,i need your help because google hasn't helped me..thanks...can you help me with simple code?

Thanks very much

publicclass AuthenticationBeanextends BaseBean{

/**

*

*/

privatestaticfinallong serialVersionUID = 1;

private String loginName;

private String password;

private String teamName;

boolean registered;

public AuthenticationBean(){

}

publicvoid setLoginName(String loginName){

this.loginName = loginName;

}

public String getLoginName(){

return loginName;

}

publicvoid setPassword(String password){

this.password = password;

}

public String getPassword(){

return password;

}

publicvoid setTeamName(String teamName){

this.teamName = teamName;

}

public String getTeamName(){

return teamName;

}

public String login(){

String risultato=null;

try{

DataSource dataSource=Singleton.getInstance().getDataSource();

Connection connection=dataSource.getConnection();

if (connection !=null){

Statement statm = connection.createStatement();

String query ="SELECT * FROM user " +"WHERE username = '"

+ loginName +"' " +"AND password = '" + password

+"' " +"AND teamname ='" + teamName +"'";

ResultSet rs = statm.executeQuery(query);

registered =false;

if (rs.next()){

registered =true;

connection.close();

risultato="login";

}

else risultato="failure";

}

}

[4042 byte] By [giubata] at [2007-10-3 1:30:49]
# 1

Hello again - you will have to send some javascript over as part of an onchange event on the menu and set the value of the menu to the value of the selected option:

for instance

<f:selectOneMenu id="menu" onchange="document.forms['formName'][formName:menu'].value = document.forms[formName']['formName:menu'].options[document.forms['formName']['formName:menu'].selectedIndex].value; return false;" />

** change the form name and menu to what ever you call it

I usually put stuff like this into a bean - like an onchangeBean and call the bean i.e.

<f:selectOneMenu id="menu" onchange="#onchangeBean.menuOnchange}" />

in the bean you would create a function called

public class onchangeBean{

public onchangeBean(){}

public String getMenuOnchange(){

return "document.forms['formName'][formName:menu'].value = document.forms['formName']['formName:menu'].options[document.forms['formName']['formName:menu'].selectedIndex].value; return false;" ;

}

}

and then register it as a request scoped managed bean in faces-config.xml

paroconsulta at 2007-7-14 18:28:41 > top of Java-index,Java Essentials,Java Programming...