我遇到了JSF和Ajax的问题。我使用Ajax keyup事件来过滤selectOneListbox。如果我在开始时全部渲染它,它工作正常。当我使用此组件隐藏面板并在selectOneRadio中选择适当的选项时进行渲染时,keyup事件不起作用。
JSF代码:
<h:form id="form">
Client type: <h:selectOneRadio id="client_type" value="#{testBean.clientType}" styleClass="radio">
<f:selectItem itemValue="N" itemLabel="New client" />
<f:selectItem itemValue="E" itemLabel="Existing client" />
<f:ajax event="change" execute="@this" render="clientPanel" />
</h:selectOneRadio>
<br /><br />
<h:panelGroup id="clientPanel">
<h:panelGroup id="existedClient" rendered="#{testBean.clientType eq 'E'}">
<p style="font-weight: bold;">Existed client</p>
Search: <h:inputText id="in" value="#{testBean.clientSearchPattern}" autocomplete="off">
<f:ajax event="keyup" listener="#{testBean.clientChanged}" render="client_select" />
</h:inputText>
Client: <h:selectOneListbox id="client_select" value="#{testBean.complaint.client.id}" required="true"
style="width: 200px; font-family: 'Ubuntu'; font-size: 14.6667px; font-style: normal;">
<f:selectItems value="#{testBean.clients}" var="client"
itemLabel="#{client.name} #{client.surname}" itemValue="#{client.id}" />
</h:selectOneListbox>
</h:panelGroup>
<br /><br />
<h:panelGroup id="newClient" rendered="#{testBean.clientType eq 'N'}">
<p style="font-weight: bold;">New client</p>
Name: <h:inputText id="name" value="#{testBean.clientSearchPattern}" />
</h:panelGroup>
</h:panelGroup>
</h:form>
Java代码:
@Named
@RequestScoped
public class TestBean {
@Inject
private ClientService clientService;
private String clientType = "N";
private String clientSearchPattern;
private List<Client> clients;
private Complaint complaint = new Complaint();
@PostConstruct
public void init() {
clients = clientService.list();
}
public void clientChanged() {
clients = clientService.search(clientSearchPattern);
}
public String getClientSearchPattern() {
return clientSearchPattern;
}
public void setClientSearchPattern(String clientSearchPattern) {
this.clientSearchPattern = clientSearchPattern;
}
public List<Client> getClients() {
return clients;
}
public Complaint getComplaint() {
return complaint;
}
public void setComplaint(Complaint complaint) {
this.complaint = complaint;
}
public String getClientType() {
return clientType;
}
public void setClientType(String clientType) {
this.clientType = clientType;
}
}
提前致谢!