自动完成程序不提交表单值

发布于 2024-12-02 14:23:21 字数 571 浏览 0 评论 0原文

我正在使用 struts 2 和 jquery 插件。

我有一个 jsp,其中定义了两个元素:一个选择和一个自动完成器。 我需要过滤从先前选择的提供程序中选择的产品:

 <s:form id='myForm'>
 <s:select list="providers" value="provider.id" listKey="id" name="provider.id"/>
 <sj:autocompleter 
 id="productId" 
 name="productDescription" 
 value="%{productDescription}" 
 listenTopics="providerChanged"
 href="%{url_products}"
 formIds="myForm" 
 />

问题是自动完成程序在输入时不会在 sj:select 中提交最新选定的值。因此,当调用 url_products 时,provider.id 的旧值将发送到操作。

请注意,我在自动完成程序中添加了 formId,但没有解决问题。

有什么想法吗???

I'm working with struts 2 and jquery plugin.

I have a jsp where I have defined two elements, a select and an autocompleter.
I need to filter the products selected from the provider previously selected:

 <s:form id='myForm'>
 <s:select list="providers" value="provider.id" listKey="id" name="provider.id"/>
 <sj:autocompleter 
 id="productId" 
 name="productDescription" 
 value="%{productDescription}" 
 listenTopics="providerChanged"
 href="%{url_products}"
 formIds="myForm" 
 />

The problem is that the autocompleter does not submit the latest selected values in the sj:select while typing in it. So when url_products is called, an old value for the provider.id is sent to the action.

Plese note that I added formIds in the autocompleter but does not resolve the problem.

Any ideas???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

恋你朝朝暮暮 2024-12-09 14:23:21

我没有在 JS 中添加任何代码,因此我包含了一些其他相关代码,可以更好地描述我所实现的内容:

操作中的代码:

public List<Provider> getProviders() {
    return this.providerService.getAllProviders();
}

public String[] getAllProducts() {
            //provider.id has an old value when this methood is called
    List<String> productsDescriptions = new ArrayList<String>();
    if (term != null && term.length() > 0)
    {
        List<Product> products = new ArrayList<Product>();
        products = this.productService.getAllProducts();
            for (Product product : products) {
                String descriptionProduct =     product.getDescription();
                if    (StringUtils.contains(descriptionProduct.toLowerCase(), term.toLowerCase()))
                {
                        productsDescriptions.add(descriptionProduct);
                }
            }
    }
    return productsDescriptions.toArray(new String[productsDescriptions.size()]);
}

public String getProductDescription(String productDescription) {
    return this.productDescription;
}

public void setProductDescription(String productDescription) {
    this.productDescription = productDescription;
}

public String showProducts() {
    return "showProducts";
}

jsp 处的 URL:

<s:url id="url_products" action="purchaseNavegation" method="showProducts"/>

struts.xml:

<action name="purchaseNavigation" class="purchaseNavigationAction">
        <result name="showProducts" type="json">
            <param name="root">allProducts</param>
        </result>
    </action>

I did not add any code at JS, so I include some other code related that can describe better what I've implemented:

Code in the action:

public List<Provider> getProviders() {
    return this.providerService.getAllProviders();
}

public String[] getAllProducts() {
            //provider.id has an old value when this methood is called
    List<String> productsDescriptions = new ArrayList<String>();
    if (term != null && term.length() > 0)
    {
        List<Product> products = new ArrayList<Product>();
        products = this.productService.getAllProducts();
            for (Product product : products) {
                String descriptionProduct =     product.getDescription();
                if    (StringUtils.contains(descriptionProduct.toLowerCase(), term.toLowerCase()))
                {
                        productsDescriptions.add(descriptionProduct);
                }
            }
    }
    return productsDescriptions.toArray(new String[productsDescriptions.size()]);
}

public String getProductDescription(String productDescription) {
    return this.productDescription;
}

public void setProductDescription(String productDescription) {
    this.productDescription = productDescription;
}

public String showProducts() {
    return "showProducts";
}

URL at jsp:

<s:url id="url_products" action="purchaseNavegation" method="showProducts"/>

struts.xml:

<action name="purchaseNavigation" class="purchaseNavigationAction">
        <result name="showProducts" type="json">
            <param name="root">allProducts</param>
        </result>
    </action>
你曾走过我的故事 2024-12-09 14:23:21

我最近玩过 sj:autocompleter 并遇到了非常相似的问题。我不确定这是不是我在后端搞砸了 - 我想自动完成器来匹配最后输入的项目:

这个和那个以及其他东西..

我仍然想匹配“某些东西”但不覆盖'这个和那个以及'如果选择了'某事' - 无论如何,为了说明这一点,不是我的拼接和切割导致了错误,而是添加了一个简单的修复

forceValidOption="false"

: sj:自动完成器。默认情况下,如果省略该值,则该值为 true。

尝试一下,看看它是否适合你

I've played around with sj:autocompleter lately and had a very similar problem. I wasn't sure if it was my messing around on the back end doing that - I wanted to autocompleter to match on the last item being typed:

This and that and someth..

I still wanted to match on 'something' but without overwriting 'This and that and ' if 'something' was selected - anyway, to get to the point, it wasn't my splicing and dicing that caused the error it was a simple fix of adding:

forceValidOption="false"

to the sj:autocompleter. By default, this value is true if you omit it.

Try it and see if it works for you

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