我正在开发一个页面来生成动态下拉菜单。如果我使用硬编码值,我可以在表单提交上获取所选值。但是如果我动态生成,那就不起作用了。任何人都可以帮我吗?
豆(工作):
public String getApplication_environment() {
return application_environment;
}
public void setApplication_environment(String application_environment) {
this.application_environment = application_environment;
}
private List<SelectItem> application_environment_list = ENVIRONMENT_LIST;
public static final List<SelectItem> ENVIRONMENT_LIST = new ArrayList<SelectItem>() {
{
add(new SelectItem("A"));
add(new SelectItem("B"));
add(new SelectItem("C"));
add(new SelectItem("D"));
}
};
Bean(不工作):
public static final List<SelectItem> ENVIRONMENT_LIST = new ArrayList<SelectItem>() {
{
for(int i=0;i<3;i++){
add(new SelectItem("--"+i));
}
}
};
XHTML代码:
<f:view>
<div>
<ui:include src="header.xhtml"></ui:include>
<h:body>
<h:form>
<rich:panel styleClass="panel-bgimage"
style="vertical-align:middle;">
<table>
<tr>
<td align="center"><h:outputText value="Tags"
styleClass="headerOutputCell" /> <h:selectOneMenu
value="#{ProjectTags.application_environment}" id="application_environment">
<f:selectItems value="#{ProjectTags.application_environment_list}" var="coll" itemValue="#{coll.label}" itemLabel="#{coll.value}" />
</h:selectOneMenu></td>
</tr>
<tr height="30px">
<td></td>
</tr>
<tr>
<td align="center"><h:selectManyCheckbox
value="#{ProjectTags.environments}" styleClass="headerOutputCell">
<f:selectItems value="#{ProjectTags.environmentsValue}" />
</h:selectManyCheckbox></td>
</tr>
<tr height="30px">
<td></td>
</tr>
<tr>
<td align="center"><h:commandLink id="hmPromote" onclick="dlgConfirmation.show();return false" styleClass="homebtn">
<center class="buttonText">Promote</center>
</h:commandLink>
</td>
</tr>
</table>
<h:panelGrid id="panel" cellpadding="10"
cellspacing="1" rendered = "#{ProjectTags.isNewTag}" >
<table>
<tr><td>
<h:panelGrid columns="2" align="center">
<h:outputText styleClass="headerOutputCell" value="New tag " />
<h:selectBooleanCheckbox value="#{ProjectTags.rememberMe}" >
<f:ajax event="click" execute="@form" />
</h:selectBooleanCheckbox>
</h:panelGrid>
<h:panelGroup>
<h:commandLink id="hmSubmit" onclick="modalDialogCreate.show();return false" styleClass="homebtn">
<center class="buttonText">Submit</center>
</h:commandLink>
</h:panelGroup>
</td></tr>
</table>
</h:panelGrid>
</rich:panel>
<p:confirmDialog id="confirmDialog"
message="Are you sure to promote the tags?"
header="Confirm Promote" severity="alert" widgetVar="promoteDialog">
</p:confirmDialog>
<p:dialog id="modalDialog" header="Please wait" widgetVar="dlgConfirmation" modal="true">
<h:panelGrid columns="2">
<h:graphicImage value="/images/icon-alert.png" />
<h:outputText value="Are you sure to promote the tags?" style="FONT-SIZE: medium;" />
</h:panelGrid>
<h:panelGroup>
<h:commandButton id="confirm" value="OK" onclick="dlgConfirmation.hide();promoteProcess.show()"
action="#{ProjectTags.promoteTags}" immediate="true" style="padding:5px;"/>
<h:commandButton id="Logout" value="Cancel" oncomplete="dlgConfirmation.hide()" style="padding:5px;"/>
</h:panelGroup>
</p:dialog>
<p:dialog id="modalDialogCreate" header="Please wait" widgetVar="modalDialogCreate" modal="true">
<h:panelGrid columns="2">
<h:graphicImage value="/images/icon-alert.png" />
<h:outputText value="Are you sure to create new tag?" style="FONT-SIZE: medium;" />
</h:panelGrid>
<h:panelGroup>
<h:commandButton id="c_confirm" value="OK" onclick="modalDialogCreate.hide();promoteProcess.show()"
action="#{ProjectTags.createNewTag}" immediate="true" style="padding:5px;"/>
<h:commandButton id="c_cancel" value="Cancel" oncomplete="modalDialogCreate.hide()" style="padding:5px;"/>
</h:panelGroup>
</p:dialog>
<p:dialog id="modalDialogProcess" header="Please wait" widgetVar="promoteProcess" modal="true">
<h:panelGrid columns="2">
<h:outputText value="Your Request is being processed"
style="FONT-SIZE: large;" />
<h:graphicImage value="./images/gears_animated.gif" />
<h:outputText
value="*Please do not click refresh till the request is in process"
style="FONT-SIZE: smaller;" />
<h:outputText id="elapsedTime" value="" style="FONT-SIZE: smaller;"></h:outputText>
</h:panelGrid>
</p:dialog>
</h:form>
</h:body>
</div>
</f:view>