我有一个xhtml页面,其中有一个表单可以为在线日历创建一个事件,在表单的末尾有可能邀请一些注册到该站点的用户。
目前有三个字段可以插入电子邮件(邀请用户1,邀请用户2,邀请用户3在代码底部),但我希望在开头有零字段但是只需一个名为 “添加用户”的按钮 ,点击该按钮即可添加新字段。然后可以在不同的时间点击此按钮,因此对生成的字段没有限制。
这是代码
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Create Event</title>
</h:head>
<h:body>
<h:form prependId="false">
<p:panel header="Create Event Form">
<h:panelGrid columns="3" id="regGrid">
<h:outputLabel for="name">Name:</h:outputLabel>
<p:inputText id="name" value="#{createBean.event.eventname}"/><br/>
<h:outputLabel for="city">City</h:outputLabel>
<p:inputText id="city" value="#{createBean.event.city}"/><br/>
<h:outputLabel for="inviteone">Invite User 1:</h:outputLabel>
<p:inputText id="inviteone" value="#{createBean.invited1}"/><br/>
<h:outputLabel for="inviteone">Invite User 2:</h:outputLabel>
<p:inputText id="invitetwo" value="#{createBean.invited2}"/><br/>
<h:outputLabel for="inviteone">Invite User 3:</h:outputLabel>
<p:inputText id="invitethree" value="#{createBean.invited3}"/><br/>
</h:panelGrid>
<p:commandButton value="Create Event" update="regGrid"
action="#{createBean.saveEvent()}" />
</p:panel>
</h:form>
</h:body>
总之,我想删除最后3对h:outputLabel - p:inputText和 只需添加一个按钮,点击后生成一对 的h:outputLabel - p:inputText,再次点击另一对h:outputLabel - p:inputText。 (然后我已经能够以适当的方式将值传递给Bean;))
答案 0 :(得分:1)
尝试 ui:repeat 标记,让jsf重新渲染容器:
<p:commandButton value="Add friend"
action="#{createBean.addInvited}"
update="container" />
<p:outputPanel id="container">
<ui:repeat value="#{createBean.invitedList}" var="invited" varStatus="myVarStatus">
<h:outputLabel>Invite User #{myVarStatus.index}:</h:outputLabel>
<p:inputText value="#{invited}"/>
<br/>
</ui:repeat>
</p:outputPanel>