Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Showing the selected value in h:selectOneMenu

Ruhi Ghosh
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All JSF Gurus,
Actually I am populating the list in a h:selectOneMenu from the database. I am facing the following problems:
1. I have initialzed a variable in the faces-config/managed bean(neither of them works) and mapped it to the value in my JSP but by default it displays the last record in the database.
2. In case of an error, I am displaying the error message in the same page being refreshed. All the other h:selectOneMenu with the values being populated hard=coded and not from database show the stored values that were set by the user previously but this h:selectOneMenu filled from database simply displays the default value as the last entry from database.
I am stuck past 2 days

Please help me friends
My code looks like this...

<h:selectOneMenu id="clientFirm" value="#{pmtBean.paymentTypeDesc}" onchange="SetValue()" required="true" >
<f:selectItems value="#{pmtBean.paymentTypesList}" />

private String paymentTypeDesc;
private Collection paymentTypesList;
public Collection getPaymentTypesList() {
if (null == paymentTypesList) {
paymentTypesList = Collections
.synchronizedList(new java.util.ArrayList());
} else {
try {
CashwebDAO dao = CashwebDAO.getInstance();
StringBuffer where = new StringBuffer();
where.append(" where payment_type = '");
System.out.println(" INSIDE getPaymentTypesList paymentType ---------" );
dao.setupPaymentTypes(new CashwebDAOBridgeAdapter() {
public void processPaymentTypes(ResultSet rs) throws SQLException {
System.out.println(" INSIDE processPaymentTypes ---------");
System.out.println(" <><><><><><><><> getPaymentTypeType ---------" +getPaymentTypeType());
String finalPaymentType;
//paymentTypesList.add(new SelectItem(" ", " ", " "));
valuesMap = new HashMap();
while ( {
paymentTypeType = rs.getString("payment_code");
paymentTypeDesc = rs.getString("description");
finalPaymentType = paymentTypeType + " " + paymentTypeDesc;
paymentTypesList.add(new SelectItem(paymentTypeDesc, paymentTypeDesc, paymentTypeDesc));


//String finalPaymentType = getPaymentTypeType();

System.out.println(" <><><><><><><><> valuesMap ---------" +valuesMap);
/*if(null != getPaymentTypeType() && !"null".equals(getPaymentTypeType()) && !"".equals(getPaymentTypeType())){
//If a Payment Type was selected, then get its desc and set the default
finalPaymentType = paymentTypeType;
paymentTypesList.add(new SelectItem(finalPaymentType, finalPaymentType, finalPaymentType));
}, where);
} catch (Exception exc) {
MasterBean.log("Exception getting Payment Types List.", exc);

return paymentTypesList;

public void setPaymentTypesList(Collection paymentTypesList) {
this.paymentTypesList = paymentTypesList;
public String getPaymentTypeDesc() {
return paymentTypeDesc;

public void setPaymentTypeDesc(String paymentTypeDesc) {
this.paymentTypeDesc = paymentTypeDesc;

<value>Margin Excess - 01</value>

Thanks in advance,
Ruhi Ghosh
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought this forum was to help the people in need but it was a big mistake to have spend my time in posting my problem here inspite of having so many good JSF experts here...
g madhava
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try changing the scope of the bean to request rather than session.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic