I want to make quick search in the JSF page before I submit the form (partial update) , so I have two values, one is input text and I want the result show in the output text when the user enter the value in the input text. for example I want to search about the name of the user using the user id, so in the input text the user will enter the user id (e.g 2323) then the search will happens and this will render the output text with the name of this user(2323).
I use a4j:support in order to achieve this but nothing shown with me and there is no any error or exception.
this is my JsF page:
<tr>
<td>
<table>
<tr>
<td width="80px"><h:outputLabel
value="user id"></h:outputLabel></td>
<td width="5px"> </td>
<td><h:inputText id="secondIdNum" maxlength="6" style="width:240px"
value="#{ideaDetailsBean.addIdeaDto.secondId}">
<a4j:support event="onchanged" actionListener="#
{ideaDetailsBean.secondIdChange}"
reRender="secondNameId" />
</h:inputText></td>
<td width="15px"> </td>
<td width="80px"><h:outputLabel value="user name "></h:outputLabel></td>
<td width="5px"> </td>
<td><h:outputText id="secondNameId"
style="width:240px"
value="#{ideaDetailsBean.addIdeaDto.secondName}"></h:outputText>
</td>
</tr>
</table>
</td>
</tr>
in the backbean:
public void secondIdChange(ActionEvent actionEvent) {
if(addIdeaDto.getSecondId() != null){
addIdeaDto.setSecondName(getParticipantName(addIdeaDto.getSecondId()));
}
}
static String getParticipantName(String employeeId) {
IIMDelegate iimDelegate = new IIMDelegate();
UserInfoDto userInfoDto = new UserInfoDto();
iimDelegate.getParticipant(employeeId);
return userInfoDto.getUserName();
}
in the DAO:
public UserInfoDto getParticipant(String employeeId) {
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet searchResultSet = null;
try {
connection = getConnection();
preparedStatement = connection.prepareStatement(
"SELECT U_NAME FROM APPL_USER WHERE U_LOGIN = ?");
// Assign first value to first parameter
preparedStatement.setString(1, employeeId);
searchResultSet = preparedStatement.executeQuery();
return getParticipant(searchResultSet);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
try {
searchResultSet.close();
preparedStatement.close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
private UserInfoDto getParticipant(ResultSet searchResultSet) throws SQLException {
List<UserInfoDto> result = new ArrayList<UserInfoDto>();
UserInfoDto userInfoDto = null;
while (searchResultSet.next()) {
userInfoDto = new UserInfoDto();
userInfoDto.setUserName(searchResultSet.getString(1));
result.add(userInfoDto);
}
return result == null ? null : result.size() > 0 ? result.get(0) :null;
}
Any suggestion to achieve this in different way?