Search code examples
javajspdrop-down-menuliferayliferay-aui

issue to inject java code into an <aui:select> control (with <% %> or <%= %> )


I find odd results while testing form control.

Normal select control:

<select class="form-control " name="input_nb_players_min" id="input_nb_players_min">
<%out.write(   "<option value=\"test3\" label =\"test3\" />"         ); %> //works fine
<%= "<option value=\"test6\" label =\"test6\" />" %>//works fine
<%System.out.println(   "<option value=\"test3\" label =\"test3\" />"   );%>    //works fine   
</select>

when doing the same into an < aui:select>:

< aui:select name="preferences--mailingSendMode--" type="select" label="type d'envoi du mailing"  value="<%= mailingSendMode_cfg %>" >
    <%out.write(   "<aui:option value=\"test3\" label =\"test3\" />"         ); %>
    <%="<aui:option value=\"test4\" label =\"test4\" />" %> //not working!
    <aui:option value="test2" label ="test2" />    //works fine   
    <aui:option value="test" label ="test" />   //works fine    //not working!
    <%= "<aui:option value=\"test6\" label =\"test6\" />" %> //not working!
    <%String str =  "<aui:option value=\"test7\" label =\"test7\" />"; %>
    <%=str %> //not working!
    <%System.out.print("test/>"); %> //working
    <aui:option value="test8" label ="test8" selected="<%=true %>" />   //works fine   
    <aui:option value="test9" label ="test9" selected="<%=1==1 %>" />   //works fine   

 </aui:select>

Can anyone share light onn this pls?

thx in advance.


Solution

  • You can follow the code below as an example of dynamic options with a selected value:

    <aui:select name="title">
        <%for(int i = 0; i < listOfOptions.size(); i++){ 
            Object option = listOfOptions.get(i);
            boolean selected = false;
            if(user.getTitle().equals(option.getTitle())){
                selected = true;
            } %>
            <aui:option label=<%=option.getTitle() %> value="<%=option.getValue() %>" selected=<%=selected %> />
        <%} %>
    </aui:select>