我在 JSF2.0 中有一个简单的应用程序。我在会话范围内创建了一个 ManagedBean。在这个托管 bean 中,我存储了一个属性。但是当我尝试从 jsp 访问该属性时,它没有被检索到。我正在存储 roleType 的值。这是ManagedBean中的方法
public class LoginBean {
private String userID;
private List<String> roleNames;
private String roleType;
public String getUserID() {
return userID;
}
public void setUserID(String userID) {
this.userID = userID;
}
public List<String> getRoleNames() {
return roleNames;
}
public void setRoleNames(List<String> roleNames) {
this.roleNames = roleNames;
}
public String getRoleType() {
return roleType;
}
public void setRoleType(String roleType) {
this.roleType = roleType;
}
public String createAuth() throws SQLException
{
Authorisation authCall=com.validation.client.authorization.concern.AuthorisationCall.createAuthorisation(userID);
if(authCall.getUserRoles()==null || authCall.getUserRoles().size()<=0){
return "login";
}
List<String> roleNameList=new ArrayList<String>();
Iterator itr =authCall.getUserRoles().iterator();
String roleType=null;
while (itr.hasNext()){
UserRole userRole=(UserRole)itr.next();
roleNameList.add(userRole.getRoleName());
roleType=userRole.getRoleDescription();
}
setRoleNames(roleNameList);
setRoleType(roleType);
}
}
The jsp page where I am retrieving the property is :
<c:if test="${loginBean.roleType=='APPROVER'}">
<h:outputText value="loginBean.roleType"/>
<c:if>
在 faces-config.xml 我这样做是为了注册 bean
<managed-bean>
<description>temporary authentication</description>
<managed-bean-name>loginBean</managed-bean-name>
<managed-bean-class>com.validation.client.authorization.concern.LoginBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
这是我在 JSF 中的第一次尝试,我真的坚持这一点。