出于“顺序”目的而部分提交表格是不可接受的。征求意见
我有一个 JSF 页面,用户可以在其中将他们的汽车输入我的数据库。该表单具有三个输入字段:
- 制造商
- 型号
- 注册
我正在使用 PrimeFaces 3.0.M2,并且 Manufacturer
和 Model
字段都是自动完成输入字段:
<p:autoComplete id="manufacturer"
minQueryLength="3"
completeMethod="#{carController.completeManufacturer}"
forceSelection="true"
value="#{carController.manufacturer}" />
模型字段看起来是相同,但值明显略有不同。
托管 bean 如下所示(略有缩写):
private String manufacturer;
private String model;
private String registration;
public List<String> completeManufacturer(String query) {
List<String> ms = new ArrayList<String>();
for (Manufacturer m : manufacturerFacade.findAllByName(query)) {
ms.add(m.getLongName());
}
return ms;
}
public List<String> completeModel(String query) {
List<String> ms = new ArrayList<String>();
for (Model m :
modelFacade.findAllByManufacturer(manufacturerFacade.findByName(manufacturer))) {
ms.add(m.getShortName());
}
return ms;
}
问题在于完成 model
字段。我需要此字段仅显示基于所选制造商的自动完成结果,但托管 bean 中的 manufacturer
字符串在提交整个表单之前不会填充,因此我无法查找以下模型与所选制造商相关联。
我该如何仅提交manufacturer
字段,而不提交整个表单,以便我可以查看所选制造商的型号?
谢谢!
I have a JSF page where users can enter their car into my database. The form has three input fields:
- Manufacturer
- Model
- Registration
I am using PrimeFaces 3.0.M2 and both the Manufacturer
and Model
field are autocomplete input fields:
<p:autoComplete id="manufacturer"
minQueryLength="3"
completeMethod="#{carController.completeManufacturer}"
forceSelection="true"
value="#{carController.manufacturer}" />
The field for the model looks the same, with slightly different values obviously.
The managed bean looks as follows (slightly abbreviated):
private String manufacturer;
private String model;
private String registration;
public List<String> completeManufacturer(String query) {
List<String> ms = new ArrayList<String>();
for (Manufacturer m : manufacturerFacade.findAllByName(query)) {
ms.add(m.getLongName());
}
return ms;
}
public List<String> completeModel(String query) {
List<String> ms = new ArrayList<String>();
for (Model m :
modelFacade.findAllByManufacturer(manufacturerFacade.findByName(manufacturer))) {
ms.add(m.getShortName());
}
return ms;
}
The problem lies in completing the model
field. I need this field to only display autocompletion results based on the selected manufacturer, but the manufacturer
String in the managed bean does not get populated until the entire form is submitted, so I cannot look the models up that are associated with the selected manufacturer.
How would I go about submitting only the manufacturer
field, without submitting the entire form, so I can look the models of the selected manufacturer up?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需添加一个 selectListener,如下所示:
然后在控制器中:
Just add a selectListener, like so:
and then in the controller:
您可以向manafucurer 输入字段添加一个额外的ajax 处理程序,然后处理
onchange
事件。在服务器端处理程序中,只需记住支持 bean 中的新值即可。如果您随后将支持 bean 放入视图范围中,则源自模型输入字段的 ajax 请求将获得相同的实例,并且您可以直接访问您之前记住的制造商字段。
You could add an extra ajax handler to the manafucturer input field and then handle the
onchange
event. In the server-side handler, simply remember the new value in your backing bean.If you then put your backing bean in the view scope, the ajax requests originating from the model input field will get the same instance and you have direct access to the manufacturer field that you previously remembered.