This content has been marked as final.
Show 2 replies
-
2. Re: Populate more than one input with suggestionBox onselect
siobhan.ernest Nov 24, 2007 5:14 PM (in response to siobhan.ernest)Hi again -
Thanks for the tip Ilya, but I am still stuck. Form looks like this now:<h:form id="suggestionbox_form"> <h:panelGrid columns="2" rowClasses="prop" columnClasses="name,value"> <a4j:keepAlive beanName="quickFindService.student" ajaxOnly="true"/> <a4j:region renderRegionOnly="false"> <h:outputLabel for="studentName">Student Name</h:outputLabel> <h:inputText value="#{quickFindService.student.studentName}" id="studentName"/> <h:outputLabel for="studentId">Student Id</h:outputLabel> <h:inputText value="#{quickFindService.student.studentId}" id="studentId"/> <rich:suggestionbox id="studentSuggestionBox" for="studentName" suggestionAction="#{quickFindService.quickFindStudentByName}" var="suggest" first="0" minChars="3" fetchValue="#{suggest.studentName}" width="200" height="100" ajaxSingle="true"> <h:column> <h:outputText value="#{suggest.studentName}"/> </h:column> <h:column> <h:outputText value="#{suggest.studentId}"/> </h:column> <a4j:support event="onselect" action="#{quickFindService.onSelect}" reRender="studentId" ajaxSingle="true"> <f:setPropertyActionListener value="#{suggest.studentId}" target="#{quickFindService.student.studentId}"/> </a4j:support> </rich:suggestionbox> </a4j:region> </h:panelGrid> <a4j:log popup="false" level="WARN" width="800" height="100"></a4j:log> <a4j:outputPanel ajaxRendered="true"> <h:messages/> </a4j:outputPanel> </h:form>
and the backing bean:@Stateful @Name("quickFindService") @Scope(ScopeType.CONVERSATION) public class QuickFindAction implements QuickFind, Serializable { @Logger Log log; @In EntityManager entityManager; private Object event; private Student student ; public List<Student> quickFindStudentByName(Object event) { List<Student> results = new ArrayList<Student>(); if (event != null) { String pref = event.toString(); results = entityManager.createQuery("select student from Student student where lower(student.studentName) like concat(lower(:pref),'%')") .setParameter("pref", pref) .getResultList(); } return results; } public void selectStudent() { } public void onSelect() { log.info("Student: " + student.getStudentName() + "; id: " + student.getStudentId() ); } public Object getEvent() { return event; } public void setEvent(Object event) { this.event = event; } public Student getStudent() { if(student == null) { student = new Student() ; } return student; } public void setStudent(Student student) { this.student = student; } @Remove @Destroy public void destroy() { } }
Still no joy. The value in #suggest.studentId is always null in the setPropertyActionListener, and so the studentId field never gets set correctly. I can set it to any string literal I want, or a #messages property, but not the #suggest value I need. The #suggest.studentId in the suggestion dataTable show correctly, so I know my query is pulling back the student properly.
There is something I am not doing right here, and I've been staring at it so long, I'm afraid I am missing something terribly obvious.
Help appreciated.