# How to use overloaded methods in JSPs

**URL:** <https://talk.openmrs.org/t/how-to-use-overloaded-methods-in-jsps/3364>\
**Category:** Development\
**Tags:** radiologydcm4chee, spring\
**Created:** [October 20, 2015, 12:21pm UTC](https://talk.openmrs.org/t/how-to-use-overloaded-methods-in-jsps/3364 "2015-10-20T12:21:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bgevam](https://talk.openmrs.org/letter_avatar/bgevam/32/5_5575768a8748004e209b776fc1b2916d.png) [@bgevam](https://talk.openmrs.org/u/bgevam)\
**Post date:** [October 20, 2015, 12:22pm UTC](https://talk.openmrs.org/t/how-to-use-overloaded-methods-in-jsps/3364/1 "2015-10-20T12:22:00Z")

</div>

Platform Version: 1.10.2 Module: radiologydcm4chee

Hey there! I am currently developing on the dcm4chee module. I want to create an encounter for an observation. For this encounter I need a provider. When I try to bind the provider like this:

```
            <tr>
                <td>Obs Encounter Provider</td>
                <td><spring:bind path="obs.encounter.provider">
                        <openmrs:fieldGen type="org.openmrs.Provider"
                            formFieldName="${status.expression}"
                            val="${obs.encounter.provider}" />
                    </spring:bind></td>
            </tr>

```

The method `setProvider(Person provider)` gets called in [Encounter](https://github.com/openmrs/openmrs-core/blob/master/api/src/main/java/org/openmrs/Encounter.java "Encounter"). This leads me to my final question:

How can I call other, **overloaded** , implementations of the setProvider method? Especially `setProvider(EncounterRole role, Provider provider)`.

---

<div class="post-metadata">

**Author:** ![darius](https://talk.openmrs.org/user_avatar/talk.openmrs.org/darius/32/8082_2.png) [@darius](https://talk.openmrs.org/u/darius)\
**Post date:** [October 20, 2015, 1:34pm UTC](https://talk.openmrs.org/t/how-to-use-overloaded-methods-in-jsps/3364/2 "2015-10-20T13:34:36Z")

</div>

I believe that what you’re asking is not possible.

I haven’t gone back and re-read the Spring docs, but I’m pretty sure you can only spring:bind to a plain bean property.

And generally, JSTL cannot call arbitrary methods.

---

<div class="post-metadata">

**Author:** ![lluismf](https://talk.openmrs.org/user_avatar/talk.openmrs.org/lluismf/32/770_2.png) [@lluismf](https://talk.openmrs.org/u/lluismf)\
**Post date:** [October 20, 2015, 3:00pm UTC](https://talk.openmrs.org/t/how-to-use-overloaded-methods-in-jsps/3364/3 "2015-10-20T15:00:04Z")

</div>

In Struts (and I guess Spring does the same) it doesn’t need to be a real property. As long as there’s a setter and getter it works.

---

<div class="post-metadata">

**Author:** ![darius](https://talk.openmrs.org/user_avatar/talk.openmrs.org/darius/32/8082_2.png) [@darius](https://talk.openmrs.org/u/darius)\
**Post date:** [October 20, 2015, 3:37pm UTC](https://talk.openmrs.org/t/how-to-use-overloaded-methods-in-jsps/3364/4 "2015-10-20T15:37:33Z")

</div>

@lluismf is correct, I phrased it incorrectly. You can only spring:bind to something with a standard bean-convention getter and setter.

But regardless you can’t call setProvider(EncounterRole, Provider) via spring:bind.

---

<div class="post-metadata">

**Author:** ![lluismf](https://talk.openmrs.org/user_avatar/talk.openmrs.org/lluismf/32/770_2.png) [@lluismf](https://talk.openmrs.org/u/lluismf)\
**Post date:** [October 20, 2015, 6:28pm UTC](https://talk.openmrs.org/t/how-to-use-overloaded-methods-in-jsps/3364/5 "2015-10-20T18:28:37Z")

</div>

If the encounter role is fixed, you could add in Encounter a getEncounterRolesMap returning a `Map<String, EncounterRole>` (and its corresponding setter) and then do something like:

```
 <spring:bind path="obs.encounter.encounterRolesMap[roleUUID].provider">

```

But I don’t think it’s a good idea to add new methods to the domain objects for a specific JSP need. In fact, I don’t like the idea of using domain objects in the view but that’s another question.

---

<div class="post-metadata">

**Author:** ![bgevam](https://talk.openmrs.org/letter_avatar/bgevam/32/5_5575768a8748004e209b776fc1b2916d.png) [@bgevam](https://talk.openmrs.org/u/bgevam)\
**Post date:** [November 7, 2015, 9:15am UTC](https://talk.openmrs.org/t/how-to-use-overloaded-methods-in-jsps/3364/6 "2015-11-07T09:15:56Z")

</div>

Thank you @darius and @lluismf 😄

I’m going to find another way then, I guess.
