将 java 代码注入 <aui:select> 控件的问题(使用 <% %> 或 <%= %> )

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

我在测试表单控件时发现奇怪的结果。

普通select对照:

<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>

对 < 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>

任何人都可以分享一下吗?

提前致谢。

您可以按照以下代码作为具有选定值的动态选项的示例:

<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>