Hi,

When I change the value in the selectOneMenu which has
an attached valueChangeListner, valueChangeListner
event on an inputText control is also getting fired.
This happens only the first time I submit after the
page is loaded. Subsequent submits work fine. I
couldn't figure out whether I am doing anything wrong.
Following is the code.. 

jsp:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd";>
<%@ page
contentType="text/html;charset=windows-1252"%>
<%@ taglib uri="http://java.sun.com/jsf/html";
prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core";
prefix="f"%>
<%@ taglib uri="http://myfaces.apache.org/tomahawk";
prefix="t"%>
<f:view>
        <html>
                <head>
                        <meta http-equiv="Content-Type" content="text/html;
charset=windows-1252" />
                        <title>
                                Select Test
                        </title>
                </head>
                <body>
                        <h:form id="frm001">
                                <h:panelGrid columns="2" cellpadding="2"
cellspacing="0" border="0">
                                        <h:outputText value="List Code" />
                                        <h:inputText id="listcode"
binding="#{selecttest.listCode}"
valueChangeListener="#{selecttest.onListCodeChange}"
onchange="submit()" />
                                        <h:outputText value="List Type" />
                                        <h:selectOneMenu id="listtype"
binding="#{selecttest.listType}"
valueChangeListener="#{selecttest.onListTypeChange}"
onchange="submit()">
                                        </h:selectOneMenu>
                                </h:panelGrid>
                        </h:form>
                </body>
        </html>
</f:view>


Java:
package test;

import javax.faces.component.UISelectItem;
import javax.faces.component.html.HtmlInputText;
import javax.faces.component.html.HtmlSelectOneMenu;
import javax.faces.event.ValueChangeEvent;

import org.apache.shale.view.AbstractViewController;

public class SelectTest extends AbstractViewController
{

            private HtmlSelectOneMenu _listtype = new
HtmlSelectOneMenu();
            private HtmlInputText _listcode = new
HtmlInputText();

                public SelectTest() {
                }
                
                public HtmlInputText getListCode() {
                        return this._listcode;
                }
                public void setListCode(HtmlInputText _listcode) {
                        this._listcode = _listcode;
                }
                public HtmlSelectOneMenu getListType() {
                        return this._listtype;
                }
                public void setListType(HtmlSelectOneMenu _listtype)
{
                        this._listtype = _listtype;
                }
                
                public void onListCodeChange(ValueChangeEvent event)
{
                        System.out.println("List Code changed");
                }
                
                public void onListTypeChange(ValueChangeEvent event)
{
                        System.out.println("List Type changed");
                }
                
                @SuppressWarnings("unchecked")
                public void prerender()
                {
                        super.prerender();
                        if (!isPostBack()) 
                        {
                                UISelectItem item = new UISelectItem();
                                item.setItemValue("");
                                item.setItemLabel("");
                                _listtype.getChildren().add(item);
                                item = new UISelectItem();
                                item.setItemValue("DV");
                                item.setItemLabel("Discrete Values");
                                _listtype.getChildren().add(item);
                                item = new UISelectItem();
                                item.setItemValue("QR");
                                item.setItemLabel("Query Result");
                                _listtype.getChildren().add(item);
                                item = new UISelectItem();
                                item.setItemValue("RV");
                                item.setItemLabel("Range of Values");
                                _listtype.getChildren().add(item);
                        }
                }
        }



__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Reply via email to