POJO Autocomplete losing it's value

UI Components for JSF
doctorlux
Posts: 9
Joined: 22 Apr 2010, 15:34

13 May 2010, 18:46

Hi,
i have a strange problem with p:autocomplete using POJO. Every time i display selected value, and move focus from this to other component, the value of this component is gone. In other words, p:autocomplete onBlur clears its value, if there was any before. Only the first time i select a value from suggested list, value remains, but every time i go back on this field and leave, the value is lost.

On non POJO p:autocomplete everything works as expected.

It has nothing to do with converter (I think?) because if I don't go back, value is persisted as expected.

Here is an example:

Code: Select all

<h:panelGrid columns="2" >
   <h:outputLabel value="Device:"/>
   <h:selectBooleanCheckbox  value="#{ContactController.object.mobile}" >
      <p:ajax event="change" update="device"  />
   </h:selectBooleanCheckbox>

   <h:outputLabel value="Type/IMEI:" />
   <p:autoComplete  var="device" forceSelection="true" id="device1"
        completeMethod="#{DeviceCommons.completeIMEI}" maxResults="5" 
        itemValue="#{device}" itemLabel="#{device.imei} - #{device.name}" 
        value="#{ContactController.object.device}" />

</h:panelGrid>
Thank you

doctorlux
Posts: 9
Joined: 22 Apr 2010, 15:34

14 May 2010, 12:25

Just to add some essential infos missing:

JSF 2.0
PrimeFaces 2.0.2-SNAPSHOT (but same behavior in older versions)
Glassfish v3

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

17 May 2010, 23:24

Can't replicate it, maybe I got it wrong, can you describe what we should do to replicate this step by step? Can you reproduce it at showcase as well? Also does it happen with non-pojo?

doctorlux
Posts: 9
Joined: 22 Apr 2010, 15:34

18 May 2010, 13:32

Hi Cagatay,
tnx for replay!

So this problem only occurs on Pojo values.

So here is the scenario:
1. I'm creating a new object
2. selecting value from autocomplete
3. save (persist) new object but continue editing
4. focus on autocomplete field
5. leave this field and the value is gone

but before submitting values, if i focus autocomplete field and leave, value remains.

The same problem occurs if I fetch persisted object, then it loses it's value without prior submitting.
And here is part of xhtml page:

Code: Select all

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">
 <h:head>
  <title>Ugovori</title>
   <link rel="stylesheet" type="text/css" href="skin.css" />
 </h:head>
 <h:body>
  <h:form id="frmContact" prependId="false">
   <p:messages id="msg" />
   <h:commandButton value="Save " actionListener="#{ContactController.saveAndContinue}"/>
   <h:commandButton value="Save and close" action="/index.xhtml" actionListener="#{ContactController.save}"/>
   <h:commandButton value="Cancel and close" action="/index.xhtml" immediate="true" 
                                 actionListener="#{ContactController.cancel}"  />
    <p:panel header="Contract" >
     <h:panelGrid columns="2">
      <h:panelGrid columns="2">
       <h:outputLabel value="Phone number:"/>
       <p:autoComplete maxResults="5" completeMethod="#{MSISDNCommons.completeMSISDN}"
                                 value="#{ContactController.object.number}" />

       <h:outputLabel value="SIM Card:"/>
       <p:autoComplete var="sim" forceSelection="true" completeMethod="#{SIMCommons.completeSIM}" maxResults="5" 
                                 itemValue="#{sim}" itemLabel="#{sim.serialNr}" value="#{ContactController.object.sim}" />

The first autoComplete works as expected, but second one gives me trouble.

here is alse SIMCommons.completeSIM method (nothing special):

Code: Select all

public List<SIM> completeSIM(String code) {
        List<SIM> result = new ArrayList<SIM>();
        if (code != null && code.length() > 3) {
            for (SIM r : simCommons.getFreeByLastDigits(code)) {
                String snr = r.getSerialNr();
                String subsnr = snr.substring(snr.length() - 7, snr.length());
                if (subsnr.startsWith(code)) {
                    result.add(r);
                }
            }
        }
        return result;
    }

doctorlux
Posts: 9
Joined: 22 Apr 2010, 15:34

18 May 2010, 16:29

And one more thing regarding value loss, if cleared field is submitted, last value still remains.

Here is Firebug output for this component:

Code: Select all

<div class="yui-ac" id="j_idt61">
 <input autocomplete="off" class="yui-ac-input" id="j_idt61_input" name="j_idt61_input" value="89385024510000580950" type="text">
 <input id="j_idt61_hinput" name="j_idt61_hinput" value="683bcd1f-128c-4574-8524-fcc0c995a2f7" type="hidden">
 <div class="yui-ac-container" id="j_idt61_container"><div style="display: none;" class="yui-ac-content">
   <div style="display: none;" class="yui-ac-hd"></div>
   <div class="yui-ac-bd">
      <ul>
        <li style="display: none;"></li>
        <li style="display: none;"></li>
        <li style="display: none;"></li>
        <li style="display: none;"></li>
        <li style="display: none;"></li>
        <li style="display: none;"></li>
        <li style="display: none;"></li>
        <li style="display: none;"></li>
        <li style="display: none;"></li>
        <li style="display: none;"></li>
      </ul>
    </div>
    <div style="display: none;" class="yui-ac-ft"></div>
  </div>
 </div>
</div>
<script type="text/javascript">widget_j_idt61 = new PrimeFaces.widget.AutoComplete('j_idt61', {url:'/Resolvo/contract.xhtml',formId:'frmContact',fields:["label", "value"],pojo:true});
widget_j_idt61.maxResultsDisplayed = 5;
widget_j_idt61.forceSelection=true;
</script>
Interesting situation is that when field lose it's value, firebug still shows it's value, as you can see in result above.

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

19 May 2010, 18:47


doctorlux
Posts: 9
Joined: 22 Apr 2010, 15:34

19 May 2010, 20:08

No, I can't.
I'll try to make a small app and deploy it on my server so you can try it and see what's happening.

doctorlux
Posts: 9
Joined: 22 Apr 2010, 15:34

20 May 2010, 13:39

Ok, here is small app: https://primetest.e-ured.com/

Steps to reproduce:
1. Click "New entry"
2. Select one device
3. Click Tab key
4. Click Shift+Tab keys to focus again on autocomplete field.
5. Click Tab key to focus out. Value is still there.
6. Click Save
7. Click "Edit entry"
8. Click on autocomplete field
9. Click Tab key to focus out. Pufff, value is gone.
10. Click Save. Note: Value still remains on backing bean.

doctorlux
Posts: 9
Joined: 22 Apr 2010, 15:34

25 May 2010, 01:36

Hi Cagatay,
did you manage to reproduce this bug using provided demo app?

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

29 May 2010, 11:31

Yes, I did, this one is very hard to track down, can you confirm it happens when it's not inside a dialog as well? Also can you please test with a regular inputText and share the results?

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 57 guests