Я хочу сделать быстрый поиск на странице JSF, прежде чем отправить форму (частичное обновление), поэтому у меня есть два значения, одно из которых является вводимым текстом, и я хочу, чтобы результат отображался в выходном тексте, когда пользователь вводит значение ввходной текст.например, я хочу найти имя пользователя с помощью идентификатора пользователя, поэтому во входном тексте пользователь введет идентификатор пользователя (например, 2323), затем будет произведен поиск, и будет отображен выходной текст с именем этогоuser (2323).
Я использую a4j: support для достижения этой цели, но мне ничего не показано, и нет никаких ошибок или исключений.
это моя страница JsF:
<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>
в бобе:
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();
}
в 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;
}
Есть какие-либо предложения для достижения этого по-другому?