0

There is a table like this:

<h:panelGroup rendered="#{ImportFromCSVFile.step2Visible}">
    <div style="width: 100%; overflow: auto; max-height: 400px;">
        <tr:table id="step2ColumnMappings" var="columnMappingEntry" rows="0" rowBandingInterval="1" value="#{ImportFromCSVFile.columnMappings}">
            <tr:column>
                <tr:outputLabel value="#{columnMappingEntry.columnIndex}"/>
            </tr:column>
            <tr:column>
                <tr:outputLabel value="#{columnMappingEntry.columnValue}"/>
            </tr:column>
            <tr:column>
                <h:selectOneMenu value="#{columnMappingEntry.columnType}" validator="#{ImportFromCSVFile.validateColumnType}" onchange="submit()" valueChangeListener="#{ImportFromCSVFile.columnMappingChanged}">
                    <f:selectItems value="#{ImportFromCSVFile.columnsToBeMapped}" />
                </h:selectOneMenu>
            </tr:column>
        </tr:table>
    </div>
</h:panelGroup>

which renders (properly) as a table with three columns: text in the first two and dropdowns in the last one. dropdowns are also properly initialized based on values in the model.

What I need to do is to be able to run some logic everytime a value in any of the dropdowns changes. I was thinking of using valueChangeListener on selectOneMenu, as you can see in the code, but it doesn't get called. The only thing that comes to mind right now is working with POST parameters when the form is submitted, which would not be optimal.

Do you know how I can get valueChangeListener to work in this context? JSF 1.2. I may be missing an obvious or known solution, but unfortunately I have very very little prior experience with JSF and do not work with it on a regular basis.

Thank you very much in advance!

xmlns:h="http://java.sun.com/jsf/html" xmlns:tr="http://myfaces.apache.org/trinidad"

kooker
  • 363
  • 1
  • 5
  • 16

2 Answers2

0

The easiest thing to do would be to use <tr:selectOneChoice instead of <h:selectOneChoice. Use it's valueChangeListener in the same way. However, you can't just submit the form via Javascript like that because it is not aware of the JSF life-cycle (not post'ing the right stuff and your code shouldn't interact with that level of JSF internals anyway). If you set <tr:selectOneChoice autoSubmit="true"... this will cause a post to occur when the drop-down menu value changes that calls your value change listener.

S Balough
  • 183
  • 4
0

Invoking a javascript function like the way you mentioned in the code snippet will not submit your form.To invoke

valuechange

listener you need to submit a request to the backing bean which will check your application level logic. You can try removing the

onClick

attribute and also please put a message as you have placed a

validator

. At times it so happen, that when validation is not succeeded and you have not attached a corresponding message or notification for the same, the desired action won't be performed. So even though your logic might be write but he JSF lifecycle interrupts at

validation phase

and your remaining action is not invoked.

AngelsandDemons
  • 2,823
  • 13
  • 47
  • 70