a4j:在提交表单之前支持部分更新

时间:2018-11-20 07:57:59

标签: jsf ajax4jsf

我想在提交表单(部分更新)之前在JSF页面中进行快速搜索,所以我有两个值,一个是输入文本,当用户在中输入值时,我希望结果显示在输出文本中输入文字。例如,我想使用用户ID搜索用户名,因此用户将在输入文本中输入用户ID(例如2323),然后将进行搜索,这将使用此名称渲染输出文本用户(2323)。

我使用a4j:support来实现此目的,但没有显示任何内容,也没有任何错误或异常。

这是我的JsF页面:

<tr>
<td>
<table>
<tr>
<td width="80px"><h:outputLabel
value="user id"></h:outputLabel></td>
<td width="5px">&nbsp;</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">&nbsp;</td>
<td width="80px"><h:outputLabel value="user name "></h:outputLabel></td>
<td width="5px">&nbsp;</td>
<td><h:outputText id="secondNameId"                                                                      
style="width:240px"
 value="#{ideaDetailsBean.addIdeaDto.secondName}"></h:outputText>
</td>
 </tr>
</table>
</td>
 </tr>

在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();
}

在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;
    }

有人建议以其他方式实现这一目标吗?

0 个答案:

没有答案