FROM THE BLOG

ADF Tutorial: How to show / hide a required attribute.

When the requirement needs the developer to implement a hide / show attribute conditionally, the task can be accomplished straightforward with an “auto-submit / partial trigger” strategy. However, when the case isthat the field you want to show / hide is required, things will definitely change.

Using as an example HR database in the new version of JDeveloper 12.c; we want to add an employee. If the new employee belongs to the Sales department, we need to specify a ‘Commission Percentage’ and it needs to be mandatory.

show_and_hide_required_attribute_formWe have implemented at this stage the straight forward strategy; “auto-submit / partial trigger”.

show_and_hide_required_attribute_form_selected_ITshow_and_hide_required_attribute_form_selected_SalesAt this point, if you try to save the form, you will get a validation error as expected because the commission field is mandatory. However, If you got confused, and want to choose a different department;

show_and_hide_required_attribute_form_changing_mind_error

This is not an expected behavior and the way to resolve it is implementing the approach programmatically. This is the structure of our page;

show_and_hide_required_attribute_page_structureThe reason why the Commission Field is inside a Panel Group is for PPR purposes. We just set AutoSubmit property to true and ValuePassThru to true as well. This will be explained later.

show_and_hide_required_attribute_departmentId_propertiesThis is how the code of our backing bean looks like;

show_and_hide_required_attribute_departmentId_beanThe reason we used ‘ValuePassThru’ is because we want to have the actual DepId in the valueChangeEvent. Otherwise we will receive the index of the LOV.

Once you have implemented this solution, you are going to be able to go back and forward; hiding and showing your required value in ADF. You just need to add the bindings of commisionField and the panelGroup to the bean.

Note: We used in this example ViewScope for the backing bean. You should reconsider this if you are planning to deploy you application in a clustered environment. We will post something about this in another post.

One comment

  1. Amir Meysami

    on

    Reply

    Thank You.

Leave a comment

Your email address will not be published.

Social Media

Stay up-to-date with our latest ADF and related technical posts via your favourite social network services.