出于“顺序”目的而部分提交表格是不可接受的。征求意见

发布于 2024-12-01 22:21:40 字数 1380 浏览 0 评论 0原文

我有一个 JSF 页面,用户可以在其中将他们的汽车输入我的数据库。该表单具有三个输入字段:

  • 制造商
  • 型号
  • 注册

我正在使用 PrimeFaces 3.0.M2,并且 ManufacturerModel 字段都是自动完成输入字段:

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你丑哭了我 2024-12-08 22:21:40

只需添加一个 selectListener,如下所示:

<p:autoComplete id="manufacturer"
                minQueryLength="3"
                completeMethod="#{carController.completeManufacturer}"
                forceSelection="true"
                selectListener="#{carController.manufacturerSelected}"
                value="#{carController.manufacturer}" />

然后在控制器中:

public void manufacturerSelected(SelectEvent vce) {
    String nameOfSelected = vce.getObject().toString();
    // whatever logic comes to your mind
}

Just add a selectListener, like so:

<p:autoComplete id="manufacturer"
                minQueryLength="3"
                completeMethod="#{carController.completeManufacturer}"
                forceSelection="true"
                selectListener="#{carController.manufacturerSelected}"
                value="#{carController.manufacturer}" />

and then in the controller:

public void manufacturerSelected(SelectEvent vce) {
    String nameOfSelected = vce.getObject().toString();
    // whatever logic comes to your mind
}
似狗非友 2024-12-08 22:21:40

您可以向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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文