0

As I am trying to decipher a portion of html code, I came across this one and I couldn't understand what it does. Can anyone explain to me ? Thanks !

<option ${submitExpressionForm.project eq val.projectId?'selected="selected"':''} value="<c:out value="${val.projectId}"/>"> <c:out value="${val.project}"/> </option>

  • The HTML doesn't do much, it's the JSP part that interests you I would say. The $ expression either prints or doesn't print the binary `selected` attribute based on whether or not the option is selected in the view model. The `Project name` – Tomáš Hübelbauer Jun 14 '16 at 21:30

1 Answers1

0

That isn't exclusively HTML code. It's HTML code and what looks like PHP. In any event, in the first line, the option is the default option if submitExpressionForm.project and val.projectId are identical. This will render in the browser as:

<option selected value="<c:out value="something"/>">
<c:out value="something"/>
</option>

or

<option value="<c:out value="something"/>">
<c:out value="something"/>
</option>

Depending on whether those two variables are equivalent. Long-story short, this populates an item in a pull-down menu (like this: enter image description here) and sets it to the default selection in certain conditions. Of course, it will not actually say "something" - it will be whatever the contents of the val.projectId variable are.

In this code, php is using curly braces to do substitution and the terenary operator to do a if/then statement.

Community
  • 1
  • 1
James Shewey
  • 260
  • 2
  • 19