在我的应用程序中,我有以下代码:
<h:form>
<h:panelGrid id="initPanel" columns="3">
<h:outputLabel for="type" value="*Type: " />
<h:selectOneMenu label="type" id="type" value="#{createNews.type}"
required="true" requiredMessage="Type is required.">
<f:ajax render="typePanel" />
<f:selectItem noSelectionOption="true" itemLabel="Choose one..." />
<f:selectItem itemValue="Article" itemLabel="Article" />
<f:selectItem itemValue="Video" itemLabel="Video" />
</h:selectOneMenu>
<p:message for="type" />
<h:outputLabel for="title" value="*Title: " />
<p:inputText label="title" id="title"
value="#{createNews.news.title}"
required="true" requiredMessage="Title is required." />
<p:message for="title" />
</h:panelGrid>
<h:panelGroup id="typePanel">
<h:panelGrid rendered="#{createNews.type == 'Article'}" columns="1">
<h:panelGrid columns="2">
<h:outputLabel for="content" value="*Content: " />
<p:message id="contentMsg" for="content" />
</h:panelGrid>
<p:editor id="content" value="#{createNews.news.content}" width="580" />
</h:panelGrid>
<h:panelGrid rendered="#{createNews.type == 'Video'}" columns="3">
<h:outputLabel for="embedCode" value="*Embed code: " />
<p:inputText label="embedCode" id="embedCode"
value="#{createNews.news.embedCode}" />
<p:message for="embedCode" />
</h:panelGrid>
</h:panelGroup>
<p:commandButton value="Confirm" update="initPanel typePanel" actionListener="#{createNews.createNews}" />
</h:form>
这是托管bean:
@Named(value = "createNews")
@RequestScoped
public class CreateNews {
private Integer type;
private News news;
public void createNews() {...}
// Getters and Setters
}
当我选择Article
orVideo
时,相应的部分会正确呈现在typePanel
. 在下面的示例中,我选择Video
并Embed code
渲染了该部分。
但是,当我单击 时Confirm
,之前渲染的部分突然消失了。
不知何故,type
我的托管 bean 的属性没有收到<h:selectOneMenu>
.
如果您能给我一个建议,我将不胜感激。
此致,