Which I assumed is perfectly doable.
But when I try to run the application, it is throwing compilation errors.
Error(20,26): Syntax error, insert ") Statement" to complete IfStatement
Error(20,78): Syntax error on token "==", invalid (
Error(20,78): The left-hand side of an assignment must be a variable
Error(20,86): Syntax error, insert "AssignmentOperator Expression" to complete Assignment
Error(20,86): Syntax error, insert ";" to complete Statement
Error(22,26): Syntax error on token "else", delete this token
Just as an addition to this, rather than writing out such code, I prefer to use a tag which handles it for me like the ones provided by struts/stripes.
ie give it a list of options, and tell it the option that is selected, then let the component render the HTML for it.
Indeed, I've written many such tags. One for example, is given a Map instance that uses the Map keys as the option value attributes, and the Map values as the option text. Another takes an enum class and constructs a set of option elements from the enum definition.