Reputation: 832
i have 2 autofill fileds empname and empno if i give empno remaining fields should be autofilled from database,same to empname.but the problem is When i insert new empno remaining entered fields has been set to null,same to empname how to solve it.
<h:outputText value="Employee_no"/>
<h:inputText id="empp" value="#{Bean.dto.empno}" >
<p:ajax event="keyup" update="empn,des,dep,loc" listener="#{Bean.Workerno}"/>
</h:inputText>
<h:outputText value="Employee_Name"/>
<h:inputText id="empn" value="#{Bean.dto.empname}" >
<p:ajax event="keyup" update="empp,des,loc,dep" listener="#{Bean.WorkerName}"/>
</h:inputText>
<h:outputText value="Department"/>
<h:inputText id="dep" value="#{Bean.dto.de}" />
<h:outputText value="Designation"/>
<h:inputText id="des" value="#{Bean.dto.de}" />
<h:outputText value="Employee_no"/>
<h:inputText id="empp" value="#{Bean.dto.empno}" >
<p:ajax event="keyup" update="empn,des,dep,loc" listener="#{Bean.Workerno}"/>
</h:inputText>
<h:outputText value="Employee_Name"/>
<h:inputText id="empn" value="#{Bean.dto.empname}" >
<p:ajax event="keyup" update="empp,des,loc,dep" listener="#{Bean.WorkerName}"/>
</h:inputText>
<h:outputText value="D"/>
<h:inputText id="dep" value="#{Bean.dto.d}" />
<h:outputText value="Designation"/>
<h:inputText id="des" value="#{Bean.dto.de}" />
BEAN
Upvotes: 0
Views: 6160
Reputation: 4853
Your code looks fine...
One thing is change the ajax
event from KeyUp
to blur
.
KeyUp - Forces to call the listener method for every typing letter.
Blur - Forces to call the listener method when you left the text box after typing the content.
Here you need 'blur' event because you need to call the DB after entered the all empno
.
Make sure that the values are retrieved from DB, after changed the event
As for as my consern your DB value is not getting at workerNo()
when ajax listener forces.
JSF Code
<h:ouputText value="empno"/>
<p:inputText id="empno" value="#{bean.empno}">
<p:ajax event="blur" listener="#{bean.ajaxEvent}" update="empname"/>
</p:inputText>
<h:ouputText value="empname"/>
<p:inputText id="empname" value="#{bean.empname}">
Bean Code
//Setters and getters of empname,empno
public void ajaxEvent()
{
if(getEmpNo()==//DB empno)
{
setEmpName("DB empname"); //Here only your updating the name field
}
}
Upvotes: 4