大家好,感谢您的帮助。 我需要将bean中的当前值返回给jsf。
JSF(示例)
<!-- InputText USERNAME -->
<h:outputText style="font-size:12px;font-weight:bold;" value="Username"></h:outputText>
<h:inputText a:placeholder="Enter user.." id="username" value="#{regBean.username}" required="true"></h:inputText>
<h:outputText value="<br/>" escape="false" />
<!-- COMMANDBUTTON SEND -->
<p:commandButton update=":dialogConf" style="font-size:10px;width:68px;height:32px;margin-left:70px;" type="submit" value="Sign Up" icon="ui-icon-arrowreturnthick-1-e" styleClass="botonesR"
onerror="PF('errorDlg').show();" oncomplete="PF('confirmation').show();PF('registration').hide();"
action="#{regBean.doActionReg}" ajax="true">
</p:commandButton>
Bean(示例)
public void insertNewUser(){
Connection conn = null;
PreparedStatement pStatement = null;
String user = this.getUsername();
String SQL = "INSERT INTO USER"
+ "(USERNAME)VALUES"
+ "(?)";
try {
conn = getdbConnection();
pStatement = conn.prepareStatement(SQL);
pStatement.setString(1, user);
//Execute insertSQL
pStatement.executeUpdate();
System.out.println("User:" + user);
System.out.println("Record is inserted into USUARIOS table");
}catch (SQLException e){
System.out.println(e.getMessage());
}finally{
try{
if (pStatement!=null){
pStatement.close();
}
if (conn!=null){
conn.close();
}
}catch(SQLException e){
System.out.println(e.getMessage());
}
}
}
直到这里一切正常,正确保存好记录。 现在我想在插入查询
之后在确认对话框中看到当前用户相同的JSF
<p:dialog header="Confirmation" showEffect="explode" id="dialogConf" widgetVar="confirmation" hideEffect="explode" height="125px" width="378px" modal="true" resizable="false">
<h:outputText value="User ( #{regBean.username}) is now in our db"></h:outputText>
</p:dialog>
这里#{regBean.username}没有显示用户名的当前值。
答案 0 :(得分:0)
解决了只是正确添加更新
<!-- COMMANDBUTTON SEND -->
<p:commandButton update="userReg" style="font-size:10px;width:68px;height:32px;margin-left:70px;" type="submit" value="Sign Up" icon="ui-icon-arrowreturnthick-1-e" styleClass="botonesR"
onerror="PF('errorDlg').show();" oncomplete="PF('confirmation').show();PF('registration').hide();"
action="#{regBean.doActionReg}">
</p:commandButton>
我显示结果
<p:dialog header="Confirmation" showEffect="explode" id="dialogConf" widgetVar="confirmation" hideEffect="explode" height="125px" width="378px" modal="true" resizable="false">
<h:outputText id="userReg" value="User ( #{regBean.username}) is now in our db"></h:outputText>