如何解决在刷新页面之前,JSF不会显示用户名
我的java ee8项目是在开放式自由上部署的,我正在尝试使用开放式自由的基本注册表来配置安全性。我有两个用户设置了Bob和Dave。
当Bob或Dave使用chrome的基本身份验证登录到应用程序时,我的应用程序会很好地加载联系人列表。但是它不会显示已登录用户的名称。
如果我只是刷新页面,那么两者都可以。
<h:body>
<h:form>
<header>
<h4 style="float:right">Hello,#{usersession.loggedUser.userName.name}</h4>
</header>
<div>
<p:selectOneMenu class="cannedFilter" value="#{dataView.selectedContactId}">
<f:selectItems value="#{dataView.loggedUsersContactList}" var="userContact" itemLabel="#{userContact.name}" itemValue="#{userContact.id}"/>
</p:selectOneMenu>
</div>
</h:form>
</h:body>
@Named(value = "usersession")
@SessionScoped
public class UserSession implements Serializable {
private User loggedUser;
@Inject
private UserHelper userhelper;
@Inject
private SecurityContext securityContext;
public User getLoggedUser() {
Principal callerPrincipal = securityContext.getCallerPrincipal();
if(callerPrincipal == null) {
System.out.println("User is not logged in yet");
return null;
}
System.out.println("User is logged in: "+callerPrincipal.getName());
loggedUser = userhelper.getUser(callerPrincipal.getName());
return loggedUser;
}
public void setLoggedUser(User loggedUser) {
this.loggedUser = loggedUser;
}
}
@RequestScoped
@Named(value = "dataView")
public class DataView implements Serializable {
@Inject
private UserSession userSession;
public List<Contact> getLoggedUsersContactList() {
if(userSession.getLoggedUser.getName().equals("Bob")){
return bobsContactList();
} else if(userSession.getLoggedUser.getName().equals("Dave")){
return davesContactList();
} else {return null;}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。