You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by clanmilano <cl...@gmail.com> on 2011/09/09 02:27:49 UTC

struts2 jquery autocompleter is not working

Hello there! I have a web project in which I'm using struts2 + jquery plugin.
I really like the autocompleter component since as you may know, it starts
filtering its content while we type on it.
The thing is that it does not submit the latest selected values in the
others elements at the jsp like s:select, while typing in it. So when
url_products is called, an old value for the provider.id is sent to the
action.

JSP:

<s:form id='myForm'>

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

<s:select list="providers" value="purchase.provider.id" listKey="id"
name="purchase.provider.id"/>

<sj:autocompleter 
id="productId" 
name="productDescription" 
value="%{productDescription}" 
listenTopics="providerChanged"
href="%{url_products}"
formIds="myForm" 
/>


Code in the struts action:

public void setPurchase(Purchase purchase) {
this.purchase = purchase;
}

public Purchase getPurchase() {
return this.purchase;
}

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

public String[] getAllProducts() {
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";
}


struts.xml:

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



Why are the latest selected values of the s:select are not sent to the
action when the url is called? Any ideas? 

--
View this message in context: http://struts.1045723.n5.nabble.com/struts2-jquery-autocompleter-is-not-working-tp4784544p4784544.html
Sent from the Struts - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: struts2 jquery autocompleter is not working

Posted by Higo Matos <hi...@gmail.com>.
clanmilano, this problem is reported in:

http://code.google.com/p/struts2-jquery/issues/detail?id=647


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: struts2 jquery autocompleter is not working

Posted by Dave Newton <da...@gmail.com>.
Sounds like a bug off it's supposed to be serializing on submit, or an
ambiguous spec--I'd check the tag code to see what seems to be intended and
take it from there.

Dave
 On Sep 9, 2011 6:16 PM, "clanmilano" <cl...@gmail.com> wrote:
> getAllProducts() is called any time the user type in the autocompleter.
Form
> values are sent to the action but they do not have the latest values, they
> just send the value that they have in loading of the page.
>
> What I expect is to get the form values latest selected.
>
> As it is specified in http://code.google.com/p/struts2-jquery/ there is an
> attribute formIds that says:
> Comma delimited list of form ids for which to serialize all fields during
> submission when this element is clicked (if multiple forms have
overlapping
> element names, it is indeterminate which will be used)
>
> So it's like autocompleter supports what I'm expecting.
>
> I really don't know if this is an issue in the component or if it is an
> issue in my code.
>
> Any suggestion?
>
> --
> View this message in context:
http://struts.1045723.n5.nabble.com/struts2-jquery-autocompleter-is-not-working-tp4784544p4788070.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>

Re: struts2 jquery autocompleter is not working

Posted by clanmilano <cl...@gmail.com>.
getAllProducts() is called any time the user type in the autocompleter. Form
values are sent to the action but they do not have the latest values, they
just send the value that they have in loading of the page.

What I expect is to get the form values latest selected.

As it is specified in http://code.google.com/p/struts2-jquery/ there is an
attribute formIds that says:
Comma delimited list of form ids for which to serialize all fields during
submission when this element is clicked (if multiple forms have overlapping
element names, it is indeterminate which will be used)

So it's like autocompleter supports what I'm expecting.

I really don't know if this is an issue in the component or if it is an
issue in my code.

Any suggestion?

--
View this message in context: http://struts.1045723.n5.nabble.com/struts2-jquery-autocompleter-is-not-working-tp4784544p4788070.html
Sent from the Struts - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: struts2 jquery autocompleter is not working

Posted by Dave Newton <da...@gmail.com>.
I didn't even know it sent *any* other form information, is it actually in
the HTTP request? If it is, then perhaps it builds up its request on page
load, and not dynamically.

Dave

On Thu, Sep 8, 2011 at 8:27 PM, clanmilano <cl...@gmail.com> wrote:

> Hello there! I have a web project in which I'm using struts2 + jquery
> plugin.
> I really like the autocompleter component since as you may know, it starts
> filtering its content while we type on it.
> The thing is that it does not submit the latest selected values in the
> others elements at the jsp like s:select, while typing in it. So when
> url_products is called, an old value for the provider.id is sent to the
> action.
>
> JSP:
>
> <s:form id='myForm'>
>
> <s:url id="url_products" action="purchaseNavegation"
> method="showProducts"/>
>
> <s:select list="providers" value="purchase.provider.id" listKey="id"
> name="purchase.provider.id"/>
>
> <sj:autocompleter
> id="productId"
> name="productDescription"
> value="%{productDescription}"
> listenTopics="providerChanged"
> href="%{url_products}"
> formIds="myForm"
> />
>
>
> Code in the struts action:
>
> public void setPurchase(Purchase purchase) {
> this.purchase = purchase;
> }
>
> public Purchase getPurchase() {
> return this.purchase;
> }
>
> public List<Provider> getProviders() {
> return this.providerService.getAllProviders();
> }
>
> public String[] getAllProducts() {
> 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";
> }
>
>
> struts.xml:
>
> <action name="purchaseNavigation" class="purchaseNavigationAction">
> <result name="showProducts" type="json">
> allProducts
> </result>
> </action>
>
>
>
> Why are the latest selected values of the s:select are not sent to the
> action when the url is called? Any ideas?
>
> --
> View this message in context:
> http://struts.1045723.n5.nabble.com/struts2-jquery-autocompleter-is-not-working-tp4784544p4784544.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>