<h:form>
<table>
<tr>
<td><label>First Name:</label></td>
<td><h:outputText value="#{profile.firstName}"
rendered="#{not profile.canEdit}" /></td>
<td><h:inputText value="#{profile.firstName}"
rendered="#{profile.canEdit}" required="true" /></td>
<td><h:commandButton value="Edit"
action="#{profile.editDetail}" /></td>
<td><h:commandButton value="Cancel" type="button"
action="#{profile.cancelBtn}" /></td>
</tr>
<tr>
<td><label>Last Name:</label></td>
<td><h:outputText value="#{profile.lastName}"
rendered="#{not profile.canEdit}" /></td>
<td><h:inputText value="#{profile.lastName}"
rendered="#{profile.canEdit}" required="true" /></td>
<td><h:commandButton value="Edit"
action="#{profile.editDetail}" /></td>
<td><h:commandButton value="Cancel" type="button"
action="#{profile.cancelBtn}" /></td>
</tr>
<tr>
<td><label>Email:</label></td>
<td><h:outputText value="#{profile.email}"
rendered="#{not profile.canEdit}" /></td>
<td><h:inputText value="#{profile.email}" id="email"
rendered="#{profile.canEdit}" required="true" /></td>
<td><h:commandButton value="Edit"
action="#{profile.editDetail}" /></td>
<td><h:commandButton value="Cancel" type="button"
action="#{profile.cancelBtn}" /></td>
<td><h:message for="email" value="#{profile.errorMessage}"
rendered="#{profile.errorMessage ne null}" /></td>
</tr>
<tr>
<td><label>Password:</label></td>
<td><h:outputText value="#{profile.password}"
rendered="#{not profile.canEdit}" /></td>
<td><h:commandButton value="Edit"
action="#{profile.editDetail}" /></td>
<td><h:commandButton value="Cancel" type="button"
action="#{profile.cancelBtn}" /></td>
</tr>
<h:panelGroup rendered="#{profile.canEdit}">
<tr>
<td><label>Old Password: </label></td>
<td><h:inputText value="#{profile.password}" required="true" /></td>
<td><h:outputText rendered="#{profile.errorMessage != null}"
value="#{profile.errorMessage}"></h:outputText></td>
</tr>
<tr>
<td><label>New Password: </label></td>
<td><h:inputSecret value="#{profile.newPassword}"
required="true" /></td>
</tr>
<tr>
<td><label>Confirm Password: </label></td>
<td><h:inputSecret value="#{profile.confirmPassword}"
required="true" /></td>
<td><h:outputText
rendered="#{profile.confirmPassword != profile.newPassword}"
value="Passwords donot match!!"></h:outputText></td>
</tr>
<tr>
<td><h:commandButton action="#{profile.savePassword}"
value="Save Password"
disabled="#{profile.confirmPassword != profile.newPassword}" /></td>
<td><h:commandButton action="#{profile.cancelBtn}" value="Cancel" type="button"/></td>
</tr>
</h:panelGroup>
<tr>
<td><label>Gender</label></td>
<td>#{profile.gender}</td>
</tr>
<tr>
<td><label>City</label></td>
<td>#{profile.city}</td>
</tr>
<tr>
<td><label>State</label></td>
<td>#{profile.state}</td>
</tr>
<tr>
<td><label>Country</label></td>
<td>#{profile.country}</td>
</tr>
<tr>
<td><label>Zip-Code</label></td>
<td>#{profile.zipCode}</td>
</tr>
<tr>
<td><label>Phone Number</label></td>
<td>#{profile.phoneNumber}</td>
</tr>
<tr>
<td><h:commandButton action="#{profile.saveDetails}"
disabled="#{profile.canEdit eq 'false'}" value="Save" /></td>
<td><h:commandButton action="#{profile.cancelBtn}" type="button"
value="Cancel" /></td>
</tr>
</table>
</h:form>
我的支持bean的代码片段
public String InitializeValues(){
customer = (CustomerVO) sessionManager.getSession("CustomerBean");
System.out.println("inside profilepagecontroller"+"\n"+ customer);
setFirstName(customer.getFirstName());
this.setLastName(customer.getLastName());
this.setEmail(customer.getEmail());
this.setPassword(customer.getPassword());
this.setCity(customer.getCity());
this.setState(customer.getState());
this.setCountry(customer.getCountry());
this.setPhoneNumber(customer.getPhoneNumber());
this.setGender(customer.getGender());
this.setZipCode(customer.getZipCode());
this.setCustomerId(customer.getCustomerId());
return "ProfilePage";
}
public String editDetail(){
setCanEdit(true);
setCanSave(true);
return null;
}
public String cancelBtn(){
setCanEdit(false);
return "ProfilePage";
}
我需要的问题和解决方案
答案 0 :(得分:0)
当我点击cancelbutton时,canEdit设置为false,但是inputText 不会在屏幕上显示“未取消”。它不呈现outputText
你的commandButton有type =“button”,不应该是这种情况。
点击编辑后如何才能在编辑模式下获得特定字段?( 为每个字段创建单独的布尔值obv不可行)
嗯当然可行。我看到你使用的唯一场景是,如果某些组件没有通过验证。然后我想你可以尝试渲染X
。问题是所有组件在开始时都是vaalid然后将不会呈现无效。要解决该问题,请检查请求是否为回发:
#{component.valid}
setter方法设置支持bean的字段值。我跑完之后 代码,同样不会显示在屏幕上。 '这个'得到了所有 我需要显示的值,但不会显示在屏幕上。
我不明白这个问题是你的大写方法初始化你正在谈论的?你应该发布整个bean,因为它从未被称为。