OakvilleWork
OakvilleWork

Reputation: 2377

making default value the previously selected value (JSTL)

I have a drop down menu that is full of biller names as such:

<select id="mailer_filter">
<optgroup label="VIEW BY SUBSCRIPTION">
            <c:forEach var="Mailer" items="${mailerlist.billerNameList}">
            <option value="searchFor=${Mailer.billerName}&searchBy=3&addressTypeF=${requestScope.addressTypeF}&folder=${mailitems.mailboxAttributes.folder}"><c:out value="${Mailer.billerName}"/></option>              
            </c:forEach>
          </optgroup>
        </select>
        <script type="text/javascript">
          $('#mailer_filter').change(function(){
            epost.fn.windowLocation('mailList.a?' + $(this).val());
          });
        </script>

what I would like to attempt to do is which ever item the user selected from the drop down. to have that item show up as the default selected value in the drop down when the page reloads with the data again. i'm assuming there are many ways to do this, what is involved here is storing the selected item in the request scope or something I guess.

the variable = ${Mailer.billerName} is the name i wish to make default on reload when the user has selected that from the drop down. thanks for your time, knowledge and effort.

Upvotes: 0

Views: 2114

Answers (2)

Andrew
Andrew

Reputation: 2813

I am not sure I've got your question right, but you can save the ${Mailer.billerName} as a request attribute and then do something like this :

<c:forEach var="Mailer" items="${mailerlist.billerNameList}">
            <option 

<c:if check='${request.billerName eq Mailer.billerName}' >selected</c:if>

value="searchFor=${Mailer.billerName}&searchBy=3&addressTypeF=${requestScope.addressTypeF}&folder=${mailitems.mailboxAttributes.folder}"><c:out value="${Mailer.billerName}"/></option>              
            </c:forEach>

Upvotes: 1

JB Nizet
JB Nizet

Reputation: 691943

Indeed store the value you want to pre-select, and add the following code:

<option value="..." 
    <c:if test="${Mailer.billerName == valueToPreSelect}>
        selected="selected"
    </c:if>><c:out value="${Mailer.billerName}"/></option>

Upvotes: 2

Related Questions