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???
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>
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
精彩评论