I use,
- JSF
- Spring
- OCPSoft Rewrite
- Glassfish 4 / Jetty 9
I've noticed that my beans invoke @PostConstruct
's init()
method twice. Here's sample bean that got initialized twice, if you'll need web.xml
or anything else, just post it - I ran out of ideas.
@ManagedBean(name = "userBean")
public class UserBean implements Serializable {
private static final long serialVersionUID = -1347081883455053542L;
@ManagedProperty(value = "#{param.username}")
private String username;
private Users user;
private Authentication authentication;
private StreamedContent avatar;
@PostConstruct
public void init() {
System.out.println("userbean init and username: " + username);
user = Users.findByUsername(username);
authentication = SecurityContextHolder.getContext()
.getAuthentication();
if (user == null) {
Navigator.redirect("/601");
return;
}
if (user.isKeepPrivate() == true && !username.equals(authentication.getName())) {
Navigator.redirect("/600");
return;
}
avatar = new DefaultStreamedContent(UserUtils.getAvatar(user), "image/png");
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public StreamedContent getAvatar() {
return avatar;
}
public void setAvatar(StreamedContent avatar) {
this.avatar = avatar;
}
}
@ManagedBean
,@ManagedProperty
would simply be ignored. You would need to have equivalent Spring annotations instead. – Tiny@PostConstruct
. – Sotirios DelimanolisapplicationContext.xml
or alike), what did you get with these annotations,@Controller
,Scope("request")
? (A view scope as and when required, needs to be customized, of course as it is not available in Spring directly). – Tiny<f:viewParam>
(also) nested inside<f:metadata>
like in this case,<f:metadata> <f:viewParam name="username" id="username" converter="#{converterIfNeeded}" value="#{userBean.username}" valueChangeListener="#{valueChangedListenerIfNeeded}"/> </f:metadata>
. Don't forget to remove the@ManagedProperty
annotation beforeprivate String username;
in your bean. – Tiny