Valuechangelistener

hi
plz help me with this.
in my page i have a <h:selectOneMenu>. and i have populated it with an arraylist from the backing bean. i have bounded a valuechangelistener to this so that i could get the changed value when the new value is selected/but here im getting a null pointer exception.
plz help me with this.
<h:selectOneMenu
value="#{regBean.selectedState}" valueChangeListener="#{regBean.comboEvent}"     
binding="#{regBean.cmbState}"     onchange="this.form.submit();"
style=" position:absolute;left:400px;top:300px;width:135px;">
     <f:selectItems value="#{regBean.stateList}" />
</h:selectOneMenu>
public void comboEvent(ValueChangeEvent ve){
          try {
               String val=ve.getOldValue().toString();
               System.out.println(ve.getNewValue().toString());
          } catch (Exception e) {
               e.printStackTrace();
when i try to print the old value its coming.but when i try to print the newvalue im getting the error.
rgds

Hi,
Why don't you try to put the autosubmit property of the component to true instead of using the "onchange" to submit the changes ? Wouldn't that be better ? Along with the valuePassThru to true as well. So as to assure to pass the exactly value instead of the index of the selectItems.
Hope this helps.
Best Regards

Similar Messages

  • Get Updated values in valueChangeListener of af:selectManyShuttle

    I am using Jdeveloper 11.1.1.3.0
    I have applied the valueChangeListener in selectManyShuttle to get the values in backing bean.
    But the problem is, it's not giving me the updated values.
    For example, for the 1st time, the left side list is empty. So, 1st time when I moves some values, it doesn't give me any value but next time, it gives me the the ID of previously moved items.
    How to resolve this problem?

    You can try to put the following line as the 1st line in your valuechangelistener method.
    valueChangeEvent.getComponent().processUpdates(FacesContext.getCurrentInstance());
    Thanks and Regards,
    S R Prasad

  • Getting selected values from selectManyChoice component inside valueChangeListener

    Hwo do I get the selected values from the selectManyChoice component inside the valueChangeListener.
    The API docs for valueChangeEvent.getNewValue() show the return type as java.lang.object. This is good for single value what does it return in case of multiple values.
    My drop down has string values so I am expecting a set of string values.

    JDev - 11.1.2.3
    public void onRegionSelect(ValueChangeEvent event) {
    event.getComponent().processUpdates(FacesContext.getCurrentInstance());
    if (!PhaseId.INVOKE_APPLICATION.equals(event.getPhaseId())) {
    event.setPhaseId(PhaseId.INVOKE_APPLICATION);
    event.queue();
    } else {
    List<Object> values = Arrays.asList(event.getNewValue());
    System.out.println("Value changed ==>> "+values.size());
    DCBindingContainer dc =
    (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
    DCIteratorBinding iter = dc.findIteratorBinding("RegVO1Iterator");
    ViewObject vo = iter.getViewObject();
    StringBuffer regions = new StringBuffer();
    for(Object index : values){
    String iIndex = (String)index;
    Row row  = vo.getRowAtRangeIndex(Integer.parseInt(iIndex));
    regions.append((String)row.getAttribute("Region")+",");
    String reg = regions.toString();
    if(reg.endsWith(","))
    reg = reg.substring(0,reg.lastIndexOf(","));
    System.out.println(reg);

  • Values from event and from bindings are not same in valueChangeListener

    Hi, in a valueChangeListener method of an af:selectOneChoice component I get
    the new value from the event with:
    valueChangeEvent.getNewValue()
    and from bindings with:
    JsfUtils.getExpressionValue("#{bindings.Parflag.inputValue}")
    But the value from bindings is the previous value set in UI.
    Why is this happening? In ADF Page lifecycle manual it is referenced that “update model values” face runs before “invoke application” so why the value in bindings is the previous value?
    Any comment will be helpful,
    Thanks.

    That’s right.
    Could anyone comment why a valueChangeListener is regarder as a
    Validation Process and not an Application Action that commits business changes.
    I mean if I need a validator I can put an f:validator to the component and that’s all.
    The immediate attribute didn’t change the result, the method is run before bindings set.

  • Help needed with valueChangeListener problem

    I have the following code:
    <h:dataTable border="0" id="constituyentes" value="#{db_inserta.constituyentes}" var="vl" style="text-align: center;" bgcolor="#F5F5F5" cellpadding="8">
         <h:column>
              <f:facet name="header">
                   <h:outputText value="Constituyente" style="color:#800027;font-weight: bold;"/>
              </f:facet>
                <h:outputText value="#{vl.Descripcion}" style="color:#0000FF;"/>
         </h:column>
         <h:column>
              <f:facet name="header">
                   <h:outputText value="Resultado" style="color:#800027;font-weight: bold;"/>
              </f:facet>          
              <h:inputText value="#{db_almacena.valores}" style="color:#0000FF;" valueChangeListener="#{db_almacena.almacenoVector}" immediate="true"/>
              <f:param name="orden" value="#{vl.Orden}"/>
         </h:column>
    </h:dataTable>
    the db_almacena bean:
            ArrayList vect_valores=new ArrayList();
         public void almacenoVector(ValueChangeEvent event)
                 System.out.println("Going to change the System");
                 vect_valores.add(new SelectItem(new String(g)));
           public String getValores(){
              return valores;
         public void setValores(String set) {
              valores = set;
         }The dataTable is filled from a Resultset. It gives 5 sets (rows).
    My idea is to get the values from the inputText of each row and store it in an ArrayList. That is why I use the valueChangeListener.
    I have 2 problems:
    1. The values of the inputText are not got by the db_almacena (session scope).
    2. If I have in the valueChangeListener method of the bean the line: "vect_valores.add(new SelectItem(new String(g)));"
    I get an error caused by the ProcessValidationPhase.
    Any ideas?
    Thanks in advance

    Right now I am at the following point:
    <h:dataTable border="0" id="constituyentes" value="#{db_inserta.constituyentes}" var="vl" style="text-align: center;" bgcolor="#F5F5F5" cellpadding="8">
       <h:column>
         <f:facet name="header">
              <h:outputText value="Constituyente" style="color:#800027;font-weight: bold;"/>
         </f:facet>
           <h:outputText value="#{vl.Descripcion}" style="color:#0000FF;"/>
       </h:column>
       <h:column>
         <f:facet name="header">
              <h:outputText value="Resultado" style="color:#800027;font-weight: bold;"/>
         </f:facet>          
         <h:inputText value="#{db_almacena.valores}" style="color:#0000FF;" valueChangeListener="#{db_almacena.almacenoVector}"/>
         <f:param name="orden" value="#{vl.Orden}"/>
       </h:column>
       <h:column>
         <f:facet name="header">
              <h:outputText value="Unidades" style="color:#800027;font-weight: bold;"/>
         </f:facet>
         <h:outputText value="#{vl.Unidades}" style="color:#405172;"/>
       </h:column>
    </h:dataTable>
    <br />     
    <br />         
    <h:commandButton action="adelante" value="SIGUIENTE -->" />
    My db_almacena bean:
         public String getValores(){
              System.out.println("El valor es: "+valores);
              return valores;
         public void setValores(String set) {
              valores = set;
         public void almacenoVector(ValueChangeEvent event)
                 System.out.println("Going to change the System");
                 String valor = (String) event.getNewValue();
                 vect_valores.add(new SelectItem(new String(valor)));
         }The getter getValores does not get any value, it always shows: "El valor es: null"
    Moreover, if I am not misunderstanding (I am sure I am) the getNewValue method returns the current UIComponent value. So, do I have to make a binding?
    I start thinking that my approach is not correct. Is there any other way of getting the inputText values of a dataTable that comes from a resultset??
    Thanks again

  • Possible to skip the validate phase in a valuechangelistener?

    Hi,
    I'm using MyFaces 1.1.6. Does anyone know how I can skip the validation phase of the JSF lifecycle from within a valuechangelistener method? I'm trying this ...
        public void updateTimePrefs(ValueChangeEvent vce) {
            vce.setPhaseId(PhaseId.UPDATE_MODEL_VALUES);
        }but it is not working (Validation errors get displayed). Ultimately, what I want to do is change the value of a selectOneMenu on my page when the value of a text field changes, but since I'm just reloading the page with new selectOneMenu list items, I don't want to annoy the user with validation errors.
    Thanks, - Dave

    Hi again,
    1. Its absolutely true that
       the whole data of TABU-contents,
       (all the records with the primary key specified)
      are,
      in fact,
      contained (with the full data)
      in the data file.
    2. Its the same mystery, as it was in the beginning.
    3. Nobody has found out the
       encryption/format
       of this file.
    4. In other words,
       its just like an winzip file,
       which contains data.
      to use this winzip file,
      we need the software 'Winzip'.
    regards,
    amit m.

  • ValueChangeListener is not working.for disable property

    valueChangeListener is not working for disable property with following details. Requirement is to enable to date if from to date is entered.
    Field 1:
    <af:inputDate value="#{bindings.PrintFromDate.inputValue}"
    label="#{bindings.PrintFromDate.hints.label}"
    required="#{bindings.PrintFromDate.hints.mandatory}"
    shortDesc="#{bindings.PrintFromDate.hints.tooltip}"
    id="id2" autoSubmit="true"
    *valueChangeListener="#{reprintBean.enableToDate}">*
    <f:validator binding="#{bindings.PrintFromDate.validator}"/>
    <af:convertDateTime pattern="#{bindings.PrintFromDate.format}"/>
    </af:inputDate>
    <af:inputDate value="#{bindings.PrintToDate.inputValue}"
    label="#{bindings.PrintToDate.hints.label}"
    required="#{bindings.PrintToDate.hints.mandatory}"
    shortDesc="#{bindings.PrintToDate.hints.tooltip}"
    id="id1"
    *disabled="#{!requestScope.enableToDate}"*
    *partialTriggers="id2"*>
    <f:validator binding="#{bindings.PrintToDate.validator}"/>
    <af:convertDateTime pattern="#{bindings.PrintToDate.format}"/>
    </af:inputDate>
    public void enableToDate(ValueChangeEvent valueChangeEvent) {
    System.out.println("IN enableToDate");
    if (valueChangeEvent.getNewValue() != null) {
    FacesContext context = FacesContext.getCurrentInstance();
    System.out.println("Enable to Date");
    context.getExternalContext().getRequestMap().put("enableToDate",true);
    Please suggest me what is wrong on this.
    Edited by: SrinivasA on Jan 28, 2011 5:34 PM

    I still not able to achive this. (null the to date value if the FromDate has changed)
    <af:inputDate value="#{bindings.PrintFromDate.inputValue}"
    label="#{bindings.PrintFromDate.hints.label}"
    required="#{bindings.PrintFromDate.hints.mandatory}"
    shortDesc="#{bindings.PrintFromDate.hints.tooltip}"
    id="id2" autoSubmit="true"
    *binding="#{reprintBean.fromDate}"*
    *valueChangeListener="#{reprintBean.enableToDate}"*>
    <f:validator binding="#{bindings.PrintFromDate.validator}"/>
    <af:convertDateTime pattern="#{bindings.PrintFromDate.format}"/>
    </af:inputDate>
    <af:inputDate value="#{bindings.PrintToDate.inputValue}"
    label="#{bindings.PrintToDate.hints.label}"
    required="#{bindings.PrintToDate.hints.mandatory}"
    shortDesc="#{bindings.PrintToDate.hints.tooltip}"
    id="id1"
    disabled="#{bindings.PrintFromDate.inputValue eq null}"
    binding="#{reprintBean.toDate}"
    *partialTriggers="id2">*
    <f:validator binding="#{bindings.PrintToDate.validator}"/>
    <af:convertDateTime pattern="#{bindings.PrintToDate.format}"/>
    </af:inputDate>
    Value change method:
    public void enableToDate(ValueChangeEvent valueChangeEvent) {
    *setToDate(null);*
    This method is not able to reset the to date value to null. Please help to find the issue here.
    Edited by: SrinivasA on Feb 1, 2011 5:12 PM

  • ValueChangeListener in a Region

    Hi,
    I have added a valuechangelistener to a SelectOneChoice componenet in a region. At runtime, when i change the value in the lov, it doesnot call the method of valuechangelistener, where as if the add the same component with same valuechangelistner in the main page(container of the same region), the corresponding method is invoked.
    So, I want to know if there is anything extra/special that is required to listen to valuechangelistner event in case of a region. Please reply asap.

    The scope of the managed bean is 'request'.
    Yes, i have set autosubmit true. The same lines of codes are working fine for the main page but not for the region inside the page.

  • ValueChangeListener in Radio Button not acting after first time

    Hi,
    I am using ADF-BC-JSF in Jdev 10.1.3.3. I have a page on which there are 2 radio buttons which show blank at first. As soon as a user selects a radio button, the valueChangeListener calls up a method in the backing bean that opens a dialog for the user. User enters some text in to the dialog and clicks OK after which the window closes. If the user clicks Cancel on the dialog page, the window is still closed but radio button value is reset to blank through javascript. the problem is that it works only first time. second time it tries to autosubmit but only the constructor of the backing bean is called and not the actual function to open the window. Following is the code snippet that may be helpful.
    Radio Buttons
    <af:selectOneRadio value="#{bindings.SP11WarrantDetailsViewMetallurgistReviewStatus.inputValue}"
    layout="horizontal"
    id="metallurgistRadioBtn"
    autoSubmit="true"
    valueChangeListener="#{UploadDownloadBean.exampleOpenDialog}"
    disabled="#{ !UserInfo.metallurgist || bindings.SP11WarrantDetailsViewMetallurgistReviewStatus !=''}">
    <af:validator binding="#{bindings.SP11WarrantDetailsViewMetallurgistReviewStatus.validator}"/>
    <af:selectItem label="Approved" value="Approved"/>
    <af:selectItem label="Rejected" value="Rejected"/>
    </af:selectOneRadio>
    Function to Open the Window
    public void exampleOpenDialog(ValueChangeEvent valueChangeEvent)
    // Add event code here...
    FacesContext context = FacesContext.getCurrentInstance();
    // Create the dialog UIViewRoot
    ViewHandler viewHandler = context.getApplication().getViewHandler();
    UIViewRoot dialog = viewHandler.createView(context,"/sp11/warrant/MetallurgistNotes.jspx");
    HashMap properties = new HashMap();
    AdfFacesContext afContext = AdfFacesContext.getCurrentInstance();
    afContext.launchDialog(dialog,
    null, // not launched from any component
    null, // no particular parameters
    true, //show in dialog
    properties);
    Javscript for resetting the Radiob button
    function closeWindowOnCancel()
    if(parent.window.opener.document.getElementById("notesValueHolder").value == '' )
    parent.window.opener.document.getElementsByName("metallurgistRadioBtn")[0].checked = false;
    parent.window.opener.document.getElementsByName("metallurgistRadioBtn")[1].checked = false;
    Please suggest what can be the possible cause.
    Regards,
    Neeraj

    Hi,
    I am using ADF-BC-JSF in Jdev 10.1.3.3. I have a page on which there are 2 radio buttons which show blank at first. As soon as a user selects a radio button, the valueChangeListener calls up a method in the backing bean that opens a dialog for the user. User enters some text in to the dialog and clicks OK after which the window closes. If the user clicks Cancel on the dialog page, the window is still closed but radio button value is reset to blank through javascript. the problem is that it works only first time. second time it tries to autosubmit but only the constructor of the backing bean is called and not the actual function to open the window. Following is the code snippet that may be helpful.
    Radio Buttons
    <af:selectOneRadio value="#{bindings.SP11WarrantDetailsViewMetallurgistReviewStatus.inputValue}"
    layout="horizontal"
    id="metallurgistRadioBtn"
    autoSubmit="true"
    valueChangeListener="#{UploadDownloadBean.exampleOpenDialog}"
    disabled="#{ !UserInfo.metallurgist || bindings.SP11WarrantDetailsViewMetallurgistReviewStatus !=''}">
    <af:validator binding="#{bindings.SP11WarrantDetailsViewMetallurgistReviewStatus.validator}"/>
    <af:selectItem label="Approved" value="Approved"/>
    <af:selectItem label="Rejected" value="Rejected"/>
    </af:selectOneRadio>
    Function to Open the Window
    public void exampleOpenDialog(ValueChangeEvent valueChangeEvent)
    // Add event code here...
    FacesContext context = FacesContext.getCurrentInstance();
    // Create the dialog UIViewRoot
    ViewHandler viewHandler = context.getApplication().getViewHandler();
    UIViewRoot dialog = viewHandler.createView(context,"/sp11/warrant/MetallurgistNotes.jspx");
    HashMap properties = new HashMap();
    AdfFacesContext afContext = AdfFacesContext.getCurrentInstance();
    afContext.launchDialog(dialog,
    null, // not launched from any component
    null, // no particular parameters
    true, //show in dialog
    properties);
    Javscript for resetting the Radiob button
    function closeWindowOnCancel()
    if(parent.window.opener.document.getElementById("notesValueHolder").value == '' )
    parent.window.opener.document.getElementsByName("metallurgistRadioBtn")[0].checked = false;
    parent.window.opener.document.getElementsByName("metallurgistRadioBtn")[1].checked = false;
    Please suggest what can be the possible cause.
    Regards,
    Neeraj

  • How to get row index of data table in the while ValueChangeListener fired?

    Hi,
    i have a data table in my page, which contains various components like inputText, selectOneChoice in each row.
    i am invoking a method ValueChangeListener attribute of the selectOneChoice component. I have given the autoSubmit=true for this component.
    <tr:selectOneChoice id="ratingModelType"
    value="#{childRatio.ratingModelType}" binding="#{pageManager.form.bindRatioType}"
    valueChangeListener="#{pageManager.form.onRatingModelTypeChange}" autoSubmit="true"
    contentStyle="width:150px" required="#{!childRatio.disableChildRatioRatingModelType}"
    requiredMessageDetail="#{appBundle['error.ratingModelTypeShouldNotBeEmpty']}">
    <f:selectItems value="#{pageManager.catalog['Rating Model Type']}" />
    <tr:selectOneChoice>In that method i want to fetch the map(with all updated values) relevant to the currently modified row of the table.
    Since i am not using the selectionListener or any radio buttons in the page i am not able to get the row index of the table.
    somebody please tell me how to get the row index of the table, while ValueChangeListener fired?
    Thanks in advance.
    Subbu

    Hi niki,
    Thank you so much. With your suggestion i got the result exactly what i want.
    thanks again.
    --subbu                                                                                                                                                                                                                               

  • Facing the problem ValueChangeListener of the Drop Down List

    Hi,
    I am using the JDeveloper 10.1.3.5.0 and the JHeadStart 10.1.3.3.88. In my requirement, I am having three View Objects(V1,V2,V3). I need to create a page based on one VO(V1) displayed as table. In the screen, there are 6 columns. Three of them(C1,C2,C3) are having the static values( coming from the VO(V1) from which it has been built), and the others are, one column(C4) is displayed as the drop down list(for some of the rows, drop down list values are coming from the VO(V2), and for the others drop down list values are coming from the other VO(V3). The other column(C5) is a input text field, that is enabled or disabled based on the selected values from the drop down list column(C4). The column(C6) is a check box. Now, coming to the actual requirement, the rows are related to the papers. For each paper, there are 5 methods of studies. One of the method of study is SelfLearning (5th method of study), for this the drop down values are coming from the VO(V3), and for the other methods of studies(1 to 4), the drop down values are coming from the VO(V2). Now, for a user, based on the number of papers, the number of rows are displayed.(1 paper- 5 rows, 2 papers-10 rows like wise).   Initially, drop down list is displaying the null values. When I change the value in the drop down list, I need the ValueChangeListener has to be called and it has to call the method in the bean. From the bean, the column(C5) has to be enabled or disabled. This is working fine for the inital 5 rows and 7,8,9,10 rows and 12,13,14,15 rows. But, the ValueChangeListener is not working for the rows 6 and 11. I used the debug concept,and I confirmed that the valueChangeListener is not getting called for the rows 6,11,16 rows.
    C 1
    C 2
    C 3
    C 4
    C 5
    C 6
    P1
    ABC
    Study Method1
    Drop Down list1
    input text box
    check box
    P1
    ABC
    Study Method2
    Drop Down list2
    input text box
    check box
    P1
    ABC
    Study Method3
    Drop Down list3
    input text box
    check box
    P1
    ABC
    Study Method4
    Drop Down list4
    input text box
    check box
    P1
    ABC
    Study Method5
    Drop Down list5
    input text box
    check box
    P2
    DEF
    Study Method1
    Drop Down list1
    input text box
    check box
    P2
    DEF
    Study Method2
    Drop Down list2
    input text box
    check box
    P2
    DEF
    Study Method3
    Drop Down list3
    input text box
    check box
    P2
    DEF
    Study Method4
    Drop Down list4
    input text box
    check box
    P2
    DEF
    Study Method5
    Drop Down list5
    input text box
    check box

    The problem gets solved. Actually, the problem is at the VO Query. The small modification in the query at the attribute p_id( C1 ) has solved the issue.

  • ValueChangeListener is not working in JSF

    Hi Friends,
    Though there were several threads related to the same topic, i could not get the exact information required to get the expected functionality of the valueChangeListener..
    I have configured the necessary things for the valueChangeListener to work. But it (the method in valueChangeListener) does not get invoked at all, which makes me wonder and surprised!!!!
    I am sure that there is no need of incorporating the JavaScript to get any of the JSF built-in functionalities working. aint i?
    ======================================================
    jsp page
    ======================================================
    <h:selectOneMenu id="myMenu" value="#{PersonBean.selectedValue}"   valueChangeListener="#{PersonBean.processValueChange}">
         <f:selectItems id="mySelectItems" value="#{PersonBean.listValues}"/>
    </h:selectOneMenu>=====================================================
    PersonBean.java file
    =====================================================
    public void processValueChange(ValueChangeEvent value) throws AbortProcessingException {
            System.out.println("PersonBean processValueChange()");
            String selectedValue = (String)value.getNewValue();
            System.out.println("PersonBean processValueChange(),     value="+selectedValue);
             if(selectedValue.equals("1")){
                        System.out.println("PersonBean processValueChange(), value chosen is 1");
                        displayOutValues();
            else
                       System.out.println("PersonBean processValueChange(), value chosen is <>1");
    }===================================================
    faces-config.xml file
    ===================================================
    <managed-bean>
         <description>Input Value Holder</description>
         <managed-bean-name>PersonBean</managed-bean-name>
         <managed-bean-class>jsfks.PersonBean</managed-bean-class>
         <managed-bean-scope>session</managed-bean-scope>
         <managed-property>
                <property-name>userName</property-name>
                <property-class>java.lang.String</property-class>
                <value></value>
         </managed-property>
    </managed-bean>Hope the information provided is enough to understand. I do get the list of values populated in the selectOneMenu ( dropdown box). But no action is occuring when there is a change in value being selected. Of course, i do call displayOutValues() inside the processValueChange() which never occurs.
    Can anyone give me a good and clear suggestion to resolve this issue? Does any way the scope of the Managed bean contribute towards this? Even though i have given enough - session scope only.
    Awaiting an earliest reply with thanks in advance!
    Thanks,
    Raghavan alias Saravanan M.

    hi friends,
    the code seems to be working only if i place the submit() in onchange method. thanks for the replies..
    but then still i m wondering without which why it doesnt work as expected?
    i do understand that none of the valueChangeListeners do auto submit of the forms when there is a value change. But the expected actions are supposed to happen even before the form is submitted rite?
    can anyone explain please?
    Thanks,
    Raghavan.

  • How to reset the value in valueChangeListener

    I would like to reset the value in a component to its earlier value in the valueChangeListener.
    Here is an example method in the bean:
    public void valueChangeListener(ValueChangeEvent valueChangeEvent) {
    Date oldDate = (Date)valueChangeEvent.getOldValue();
    Date newDate = (Date)valueChangeEvent.getNewValue();
    if(newDate > sysdate) {
    //valueChangeEvent.getComponent().WHATEVER.setValue(oldDate)
    } else {
    valueChangeEvent.getComponent().processUpdates(FacesContext.getCurrentInstance());
    Please suggest the code that I need to put in comments.
    Note: One way to achieve this is to bind the component to the bean and do a setValue. I do not want to do this(I have master-detail tables with many rows to edit. So, this resetting should be done at row level by fetching the current row on the selected table and set).

    public void firstNameChanged(ValueChangeEvent event)
    System.out.println("FirstName changed");
    System.out.println("old value = " + event.getOldValue());
    System.out.println("new value = " + event.getNewValue());
    String oldValue = (String) event.getOldValue();
    String newValue = (String) event.getNewValue();
    RichInputText firstname = (RichInputText) event.getComponent();
    RichInputText lastname = (RichInputText) JSFUtils.findComponentInRoot("EmployeesLastName");
    firstname.setSubmittedValue(oldValue);
    firstname.setValue(oldValue);
    lastname.setSubmittedValue("lastname");
    lastname.setValue("lastname");
    AdfFacesContext.getCurrentInstance().addPartialTarget(firstname);
    AdfFacesContext.getCurrentInstance().addPartialTarget(lastname);
    }

  • Custom component with valuechangelistener attribute

    I am playing around with JSF and want to make a custom UIcomponent which extends UIinput. I want this component to have the valueChangeListener as an attirbute so that I can:
    <my:customComponent valueChangeListener="#{myBackingBean}">
    Now simple attributes aren't a problem and are explained in every tutorial you find and then some. I haven't found any tutorial that even touches this subject. If anyone can point me in the right direction I would be grateful.
    What I have somewhat figured out is the tld entry:
    <attribute>
    <name>valueChangeListener</name>
    <required>false</required>
    <deferred-method>
    <method-signature>
    void valueChange(javax.faces.event.ValueChangeEvent)
    </method-signature>
    </deferred-method>
    </attribute>
    I am assuming that you have to change the setProperties so that
    if (valueChangeListener != null){
    component.setMethodExpression(...)?
    except that my component deosn't seem to know this but only setmethodbinding, even though I should be using jsf 1.2
    Now obviously I am missing half the story, if not more. Which is the problem of course.

    In the setProperties method of the tag handler, you convert the MethodExpression
    object to an appropriate listener object and add it to the component:
    public void setProperties(UIComponent component) {
         super.setProperties(component);
         if (valueChangeListener != null)
              ((EditableValueHolder) component).addValueChangeListener(
              new MethodExpressionValueChangeListener(valueChangeListener));
    }** Borrowed from 'Core JavaServer Faces' book. 2nd edition. chapter 9

  • Urgent Help on valueChangeListener

    Hi Everybody
    My seconfd post for the same probs. I am trying to invoke a method of a backing bean using valueChangeListener in a selectOneListbox. The problem is this method is not getting invoked. I tried every thing but still lack an answer. I am posting the whole code this time.
    song.jsp
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
    <html>
       <head>
          <title>Song Detail</title>
       </head>
       <body>
          <f:view>   
               <h:form id="songForm">
                       <H4>Select a song to view detail.</H4>
                </Br>
                       <h:selectOneListbox id="songList" value="#{backingBean.selectedSong}" valueChangeListener="#{backingBean.processValueChange}" immediate="true" onchange="this.form.submit()">
                              <f:selectItems value="#{backingBean.songList}"/>
                     </h:selectOneListbox>
                <p>
                 <h:outputText id="result" value="#{backingBean.songDetail}"/>
             </p>   
         </h:form>                  
       </f:view>
      </body>
    </html>SongBean.java
    package song;
    import java.util.ArrayList;
    import javax.faces.model.SelectItem;
    import javax.faces.event.ValueChangeEvent;
    import javax.faces.event.AbortProcessingException; 
    public class SongBean
      ArrayList songList = new ArrayList();
      SelectItem selectedSong;
      String songDetail;
       public SongBean()
         System.out.println("Inside constructor");
        songList.add(new SelectItem("mm","Midnight melodies","m"));
        songList.add(new SelectItem("rc","Rock cradle","r"));
        songList.add(new SelectItem("pc","Purple clouds","p"));
    public SelectItem getSelectedSong () {
         return new SelectItem("mm","Midnight melodies","m");
      public void setSelectedSong (SelectItem selectedSong) {
         this.selectedSong=selectedSong;
      public ArrayList getSongList() {
          return songList;
    public void setSongList(ArrayList songList) {
          this.songList=songList;
      public String getSongDetail() {
          return songDetail;
    public void setSongDetail(String songDetail) {
          this.songDetail=songDetail;
    public void processValueChange(ValueChangeEvent vce) throws AbortProcessingException
              System.out.println("Method invoked");
              String userSong=(String)selectedSong.getValue();
              System.out.println(userSong);        
    }face-config.xml
    <?xml version="1.0"?>
    <!DOCTYPE faces-config PUBLIC
      "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
      "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
    <faces-config> 
      <managed-bean>
        <managed-bean-name>backingBean</managed-bean-name>
        <managed-bean-class>song.SongBean</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
      </managed-bean>
    </faces-config>Plz HELP.

    Back bean property CAN'T be a SelectItem.
    Try this toy code:
    /* song.jsp */
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
    <html>
    <head>
      <title>Song Detail</title>
    </head>
    <body>
      <f:view>
        <h:form id="songForm">
          <H4>Select a song to view detail.</H4>
          </br>
          <h:selectOneListbox id="songList"
                              value="#{backingBean.selectedSong}"
                        valueChangeListener="#{backingBean.processValueChange}"
                        immediate="true"
                        onchange="this.form.submit();">
            <f:selectItems value="#{backingBean.songList}"/>
          </h:selectOneListbox>
          </br></br>
          <h:outputText id="result" value="#{backingBean.songDetail}" />
        </h:form>
      </f:view>
    </body>
    </html>
    /* SongBean.java */
    package song;
    import javax.faces.context.FacesContext;
    import java.util.ArrayList;
    import javax.faces.model.SelectItem;
    import javax.faces.event.ValueChangeEvent;
    import javax.faces.event.AbortProcessingException;
    public class SongBean{
      ArrayList<SelectItem> songList = new ArrayList<SelectItem>();
      String selectedSong;
      String songDetail = "<Here comes the song detail>";
      public SongBean(){
        songList.add(new SelectItem("mm000", "Midnight Melodies", "m"));
        songList.add(new SelectItem("rc000", "Rock Cradle", "r"));
        songList.add(new SelectItem("pc000", "Purple Clouds", "p"));
        songList.add(new SelectItem("pc001", "Red Rains", "p"));
        songList.add(new SelectItem("rc001", "Back Basher", "r"));
        songList.add(new SelectItem("mm001", "Morning Yawns", "m"));
      public String getSelectedSong () {
        return selectedSong;
      public void setSelectedSong (String selectedSong) {
        this.selectedSong = selectedSong;
      public ArrayList<SelectItem> getSongList() {
        return songList;
      public void setSongList(ArrayList<SelectItem> songList) {
        this.songList = songList;
      public String getSongDetail() {
        return songDetail;
      public void setSongDetail(String songDetail) {
        this.songDetail = songDetail;
      public void processValueChange(ValueChangeEvent vce){
        setSongDetail("This is your favorite song.");
        FacesContext.getCurrentInstance().renderResponse();
    [faces-config.xml entry]
    <managed-bean>
      <managed-bean-name>backingBean</managed-bean-name>
      <managed-bean-class>song.SongBean</managed-bean-class>
      <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>

  • SelectOneMenu and ValueChangeListener

    Hi All,
    I am a new user of JSF components. I've got a problem about getting the selected value from the selectedOneMenu component. I have 3 selectOneMenu box and each has valueChangeListener.
    I wanna get first selected id and get the second value according to the first selected id and so on.
    The frist value change listener submit and get the selected value.But when the second value change listener submit the value, the first selectOneMenu also submit the value, so the previous value is lost and return null cause of no selection in the first box.
    I 've separate these component to three separate forms . But when one of the ValueChangeListener is execute, the others also execute.
    So , How can I pass this problem..
    Here is my coding...
    <h:form id="form1">
                        <h:panelGrid columns="3">
                        <h:column><h:outputLabel value="Category L1 : " /> </h:column>
                   <h:column>
                             <h:selectOneMenu id="selectValue"
                                                      onchange="this.form.submit();"
                                                 immediate="true"
                                                 value="#{categoryBean.selectValue}"
                                                 valueChangeListener="#{categoryBean.item1Change}">
                                       <f:selectItems value="#{categoryBean.menuItem1}"/>
                             </h:selectOneMenu>
                        </h:column>     
                        <h:column></h:column>               
                        <h:column><h:outputLabel value="Description : " /></h:column>
                        <h:column><h:outputText value="test" /></h:column>
                        <h:column><h:commandButton action="" value="Add New" /></h:column>
                        </h:panelGrid>
                        <h:inputHidden value="#{categoryBean.tempValue}" />
                   </h:form>
                   <h:form id="form2">
                        <h:panelGrid columns="3">
                        <h:column><h:outputLabel value="Category L2 : " /> </h:column>
                   <h:column>
                             <h:selectOneMenu id="selectValue2"
                                                      onchange="this.form.submit();"
                                                      immediate="true"
                                                      value="#{categoryBean.selectValue2}"
                                                      valueChangeListener="#{categoryBean.item2Change}">
                                       <f:selectItems value="#{categoryBean.menuItem2}"/>
                             </h:selectOneMenu>
                        </h:column>     
                        <h:column></h:column>               
                        <h:column><h:outputLabel value="Description : " /></h:column>
                        <h:column><h:outputText value="test" /></h:column>
                        <h:column><h:commandButton action="" value="Add New" /></h:column>     
                        </h:panelGrid>
                   </h:form>     
                   <h:form id="form3">
                        <h:panelGrid columns="3">
                        <h:column><h:outputLabel value="Category L3 : " /> </h:column>
                   <h:column>
                             <h:selectOneMenu id="selectValue3"
                                                      onchange="this.form.submit();"
                                                 immediate="true"
                                                      value="#{categoryBean.selectValue3}"
                                                      valueChangeListener="#{categoryBean.item3Change}">
                                       <f:selectItems value="#{categoryBean.menuItem3}"/>
                             </h:selectOneMenu>
                        </h:column>     
                        <h:column></h:column>               
                        <h:column><h:outputLabel value="Description : " /></h:column>
                        <h:column><h:outputText value="test" /></h:column>
                        <h:column><h:commandButton action="" value="Add New" /></h:column>
                        </h:panelGrid>     
                   </h:form>          
         public void item1Change(ValueChangeEvent event) {
              Utils.log(getFacesContext(),"Win b kwa...1.........");
              PhaseId phaseId = event.getPhaseId();
              String oldValue = (String) event.getOldValue();
              String newValue = (String) event.getNewValue();
              this.tempValue = newValue;
              if (phaseId.equals(PhaseId.ANY_PHASE))
                   event.setPhaseId(PhaseId.UPDATE_MODEL_VALUES);
                   event.queue();
              else if (phaseId.equals(PhaseId.UPDATE_MODEL_VALUES))
              Utils.log(getFacesContext(),"New Value is......"+newValue );
              if(newValue == null){
                   logger.info("Next time win tar.....");
              else{
                   this.setSelectValue(newValue);
              Utils.log(getFacesContext(), "In L1 : Selected Value is..."+this.getSelectValue());
              this.menuItem2 = this.getCategoryList(this.getSelectValue());
              FacesContext context = FacesContext.getCurrentInstance();
              context.renderResponse();
    please help me.. thanks in advance...

    There's a few things...
    First, and foremost, is that you have two forms on the page. This is a bad idea with JSF. It tends to mess things up (although, some people may have gotten it to work right). You might want to find a way to have only one h:form tag per page. That shouldn't actually be too hard.
    Next, it looks like you set up your selectOneMenu tags properly. You have the valueChangeListener, immediate=true and a form submit onchange. Good!
    However, the valueChangeListener implementation is different than what I usually see. You're queueing up the event to fire in UPDATE_MODELS phase... This is strange. This will probably undo the fact that you put immediate="true" on your component in the first place.
    My suggestion is not to manipulate the phases this way, for your particular problem. Instead, get the new value and set the selected value (without retrieving the phaseId). Then call facesContext.renderResponse() at the end of your valueChangeListener implementation. Something like this:
    public void item1Change(ValueChangeEvent event) {
        String newValue = (String) event.getNewValue();
        if(newValue == null){
            logger.info("Next time win tar.....");
        else{
             this.setSelectValue(newValue);
        Utils.log(getFacesContext(), "In L1 : Selected Value is..."+this.getSelectValue());
        //What's this?
        this.menuItem2 = this.getCategoryList(this.getSelectValue());
        FacesContext context = FacesContext.getCurrentInstance();
        context.renderResponse();
    }Start there. There may be a few more problems.
    CowKing

Maybe you are looking for