Strange. This should work, we have a few use cases and examples for that. Can you attach your application source code ?
package de.ptc.web.controller;
import java.io.Serializable;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.transaction.UserTransaction;
import org.picketlink.idm.IdentityManager;
import org.picketlink.idm.model.basic.BasicModel;
import org.picketlink.idm.model.basic.User;
import org.slf4j.Logger;
import de.ptc.web.security.annotations.Admin;
@RequestScoped
@Named("userController")
public class UserController implements Serializable {
private static final long serialVersionUID = -5971624362491978724L;
@Inject
private Logger log;
@Inject
private IdentityManager identityManager;
@Inject
private UserTransaction userTransaction;
private User user;
private String firstName;
private String lastName;
private String email;
private String password;
private String login;
@SuppressWarnings("unchecked")
public List<User> getUsers() {
List<User> users = (List<User>) identityManager.getQueryBuilder()
.createIdentityQuery(User.class).getResultList();
Collections.sort(users, new Comparator<User>() {
@Override
public int compare(User o1, User o2) {
int cmpLastName = o1.getLastName().compareTo(o2.getLastName());
return cmpLastName == 0 ? o1.getFirstName().compareTo(
o2.getFirstName()) : cmpLastName;
}
});
return users;
}
@Admin
public void save() {
try {
userTransaction.begin();
if (user != null) {
user.setFirstName(firstName);
user.setLastName(lastName);
user.setEmail(email);
user.setLoginName(login);
identityManager.update(user);
}
identityManager.remove(BasicModel
.getUser(identityManager, "aegdeg"));
userTransaction.commit();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
/**
* @return the user
*/
public User getUser() {
return user;
}
/**
* @param user
* the user to set
*/
public void setUser(User user) {
this.user = user;
if (user != null) {
setFirstName(user.getFirstName());
setLastName(user.getLastName());
setEmail(user.getEmail());
setLogin(user.getLoginName());
}
}
/**
* @return the firstName
*/
public String getFirstName() {
return firstName;
}
/**
* @param firstName
* the firstName to set
*/
public void setFirstName(String firstName) {
this.firstName = firstName;
}
/**
* @return the lastName
*/
public String getLastName() {
return lastName;
}
/**
* @param lastName
* the lastName to set
*/
public void setLastName(String lastName) {
this.lastName = lastName;
}
/**
* @return the email
*/
public String getEmail() {
return email;
}
/**
* @param email
* the email to set
*/
public void setEmail(String email) {
this.email = email;
}
/**
* @return the password
*/
public String getPassword() {
return password;
}
/**
* @param password
* the password to set
*/
public void setPassword(String password) {
this.password = password;
}
/**
* @return the login
*/
public String getLogin() {
return login;
}
/**
* @param login
* the login to set
*/
public void setLogin(String login) {
this.login = login;
}
}
JSF
<div class="modal fade" id="editUser" tabindex="-1" role="dialog"
aria-labelledby="editUserLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<h:form id="editUserForm" styleClass="form-horizontal" role="form">
<div class="modal-header" style="border-bottom: none;">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×</button>
<h4 class="modal-title" id="editUserLabel">Nutzer bearbeiten</h4>
</div>
<div class="modal-body" style="margin-top: -10px;">
<h:messages id="editUserMessages" globalOnly="true"
infoClass="alert-info" errorClass="alert-danger"
styleClass="alert" layout="table" />
<div class="form-group">
<h:outputLabel styleClass="col-sm-3 control-label">Nutzer:</h:outputLabel>
<div class="col-sm-6">
<h:selectOneMenu id="user" styleClass="selectpicker show-tick"
value="#{userController.user}">
<f:selectItem noSelectionOption="true"
itemLabel="Nutzer auswählen" itemDisabled="true" />
<f:selectItems value="#{userController.users}" var="user"
itemLabel="#{user.lastName}, #{user.firstName}"
itemValue="#{user}" />
<f:ajax execute="@this" render="@form"
onevent="function(data) {if (data.status == 'success') {$('.selectpicker').selectpicker();}}" />
</h:selectOneMenu>
</div>
</div>
<div class="form-group">
<h:outputLabel for="firstName"
styleClass="col-sm-3 control-label">Vorname:</h:outputLabel>
<div class="col-sm-6">
<h:inputText id="firstName" styleClass="form-control"
p:placeholder="Vorname" value="#{userController.firstName}" />
</div>
</div>
<div class="form-group">
<h:outputLabel for="lastName"
styleClass="col-sm-3 control-label">Nachname:</h:outputLabel>
<div class="col-sm-6">
<h:inputText id="lastName" styleClass="form-control"
p:placeholder="Nachname" value="#{userController.lastName}" />
</div>
</div>
<div class="form-group">
<h:outputLabel for="email" styleClass="col-sm-3 control-label">E-Mail:</h:outputLabel>
<div class="col-sm-6">
<h:inputText id="email" styleClass="form-control"
p:placeholder="E-Mail" value="#{userController.email}" />
</div>
</div>
<div class="form-group">
<h:outputLabel for="loginName"
styleClass="col-sm-3 control-label">Login:</h:outputLabel>
<div class="col-sm-6">
<h:inputText id="loginName" styleClass="form-control"
p:placeholder="Login" value="#{userController.login}" />
</div>
</div>
<div class="form-group">
<h:outputLabel for="password"
styleClass="col-sm-3 control-label">Password:</h:outputLabel>
<div class="col-sm-6">
<h:inputSecret id="password" styleClass="form-control"
value="#{userController.password}" />
</div>
</div>
</div>
<div class="modal-footer">
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<h:commandButton id="save" value="Speichern"
styleClass="btn btn-primary" action="#{userController.save}">
<f:ajax execute="@form" render="@form"
onevent="function(data) {if (data.status == 'success') {$('.selectpicker').selectpicker();}}" />
</h:commandButton>
</div>
</div>
</div>
</h:form>
</div>
</div>
</div>
Btw, you can simplify your configuration if you just observer the SecurityConfigurationEvent to get the builder from there to provide your config.
I know, but that way, I get warning about a missing default partition manager.
BTW: Now i expirience some strange error, after saving:
Caused by: javax.el.ELException: org.picketlink.idm.IdentityManagementException: PLIDM000501: Could not query IdentityType using query [org.picketlink.idm.query.internal.DefaultIdentityQuery@3002a544].
at javax.el.BeanELResolver.getValue(BeanELResolver.java:368)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at com.sun.el.parser.AstValue.getValue(AstValue.java:140)
at com.sun.el.parser.AstValue.getValue(AstValue.java:204)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:226)
at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
... 74 more
Caused by: org.picketlink.idm.IdentityManagementException: PLIDM000501: Could not query IdentityType using query [org.picketlink.idm.query.internal.DefaultIdentityQuery@3002a544].
at org.picketlink.idm.query.internal.DefaultIdentityQuery.getResultList(DefaultIdentityQuery.java:200)
at de.ptc.web.controller.UserController.getUsers(UserController.java:49)
at de.ptc.web.controller.UserController$Proxy$_$$_WeldSubclass.getUsers(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.jboss.weld.interceptor.proxy.SimpleInterceptionChain.interceptorChainCompleted(SimpleInterceptionChain.java:47)
at org.jboss.weld.interceptor.chain.AbstractInterceptionChain.invokeNextInterceptor(AbstractInterceptionChain.java:80)
at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.executeInterception(InterceptorMethodHandler.java:48)
at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.invoke(InterceptorMethodHandler.java:41)
at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:53)
at de.ptc.web.controller.UserController$Proxy$_$$_WeldSubclass.getUsers(Unknown Source)
at de.ptc.web.controller.UserController$Proxy$_$$_WeldClientProxy.getUsers(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:363)
... 81 more
Caused by: java.lang.NullPointerException
at org.picketlink.idm.jpa.internal.JPAIdentityStore.getAttributes(JPAIdentityStore.java:1262)
at org.picketlink.idm.jpa.internal.JPAIdentityStore.loadAttributes(JPAIdentityStore.java:386)
at org.picketlink.idm.query.internal.DefaultIdentityQuery.getResultList(DefaultIdentityQuery.java:193)
... 99 more
The strange thing is, that
userController.getUsers();
works the first time called and seems to fail, when i do partial rendering the form after saving....
If you need more source code, I could give you a temporary git user account to my private repository.
|