Thursday, September 5, 2013

ADF Select Once Choice

building ADF Select One Choice using model driven list is quite easy once you try it. but sometimes you get business requirements that makes you lose some sleep over it.

I recently came across thread discussion on the oracle forum -sorry I don't have the link to it- where the author of the thread was requested to disable some of the items in the Select items.

Some will suggest that instead of showing the items in the list and have them disabled, you can easily remove them from the list, which can be easily done by using a view criteria.
But there are times where the developer is forced to do as the requirements ask. so we still have to show the items and somehow disable them.

here is my solution:
the first steps of the solution is the same as if you are trying to create a normal model driven list.
eventually, you will have something similar to the following in the source of the page:
             <af:selectOneChoice value="#{bindings.DepartmentId.inputValue}"
                                label="#{bindings.DepartmentId.label}"
                                required="#{bindings.DepartmentId.hints.mandatory}"
                                shortDesc="#{bindings.DepartmentId.hints.tooltip}"
                                id="soc2">
              <f:selectItems value="#{bindings.DepartmentId.items}" id="si1"/>
            </af:selectOneChoice>
edit the source to look something like this:
            <af:selectOneChoice value="#{bindings.DepartmentId.inputValue}"
                                label="#{bindings.DepartmentId.label}"
                                required="#{bindings.DepartmentId.hints.mandatory}"
                                shortDesc="#{bindings.DepartmentId.hints.tooltip}"
                                id="soc1" valuePassThru="true"
                                autoSubmit="true"
                                valueChangeListener="#{TestB.testListener}">
                         <!--f:selectItems value="#{bindings.DepartmentId.items}" id="si1"/-->
                       <af:forEach items="#{bindings.DepartmentId.items}" var="item">
                             <af:selectItem label="#{item.label}" id="selectItem1"    value="#{item.value}" disabled="#{item.value%2 eq 0}"/>
                       </af:forEach>
            </af:selectOneChoice>
with this code you will generate the select items yourself using the model driven list.
now all that remains is editing the disabled attribute of the selectItem tag to disable the select item as per your requirements.

No comments:

Post a Comment