You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Vangel V. Ajanovski" <aj...@gmail.com> on 2021/09/03 17:40:28 UTC
Re: [RELEASE] Apache Tapestry 5.7.3 released
On 30.8.21 22:56, Thiago H. de Paula Figueiredo wrote:
> If you want to tell Tapestry how to build and initialize your @SessionState
> objects, you can implement ApplicationStateCreator and contribute an
> ApplicationStateContribution instance with it for a given class to the
> distributed configuration of the ApplicationStateManager services. Your
> ApplicationStateCreator implementation will be called by
> ApplicationStateManagerImpl to get the object instead of using
> ObjectLocator.autobuild(). This is probably the best way of implementing
> the logic you want here.
Hi Thiago (or anyone else that can help).
I tried to follow the suggestion with ApplicationStateContribution.
Either I am doing it the wrong way, or something is wrong with the
Hibernate session at the moment of ASO creation, as I have the same
problem again - session.createQuery returns null.
Here is the Application State Contribution code, it is a really simple
test code:
@Contribute(ApplicationStateManager.class)
public void contributeApplicationStateManager(
MappedConfiguration<Class, ApplicationStateContribution>
configuration, final Session session, final Logger logger) {
ApplicationStateCreator<UserInfo> userInfoCreator = new
ApplicationStateCreator<UserInfo>() {
public UserInfo create() {
Person p = (Person) session
.createQuery("from Person p where
p.userName='student1'")
.uniqueResult();
...
It fails right at this point.
This is the page, it is really a basic page:
public class Index {
@Property @SessionState private UserInfo userInfo;
}
And the .TML:
<html title="message:index-page"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_4.xsd"
xmlns:p="tapestry:parameter">
<p>${userInfo.userName}</p>
</html>
And this is UserInfo, not much here:
package info.ajanovski.muldequa.model;
public class UserInfo {
public static enum UserRole {
NONE, STUDENT, INSTRUCTOR, ADMINISTRATOR
};
private String userName;
private Long personId;
private List<UserRole> userRoles;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public Long getPersonId() {
return personId;
}
public void setPersonId(Long personId) {
this.personId = personId;
}
public List<UserRole> getUserRoles() {
return userRoles;
}
public void setUserRoles(List<UserRole> userRoles) {
this.userRoles = userRoles;
}
public boolean isNone() {
return userRoles.contains(UserRole.NONE);
}
public boolean isStudent() {
return userRoles.contains(UserRole.STUDENT);
}
public boolean isInstructor() {
return userRoles.contains(UserRole.INSTRUCTOR);
}
public boolean isAdministrator() {
return userRoles.contains(UserRole.ADMINISTRATOR);
}
}
The error log:
2021-09-03 19:27:32,396 [http-nio-8081-exec-3 ] INFO
org.apache.tapestry5.modules.InternalModule.PageLoader Loaded page
'Index' (mk) in 152.200 ms
2021-09-03 19:27:32,464 [http-nio-8081-exec-3 ] INFO
che.tapestry5.modules.TapestryModule.ApplicationStateManager
userInfoCreator.create entered
2021-09-03 19:27:32,475 [http-nio-8081-exec-3 ] ERROR
tapestry.render.info.ajanovski.muldequa.pages.Index Render queue error
in Expansion[PropBinding[expansion Index(userInfo.userName)]]: Cannot
invoke "org.hibernate.query.Query.uniqueResult()" because the return
value of "org.hibernate.Session.createQuery(String)" is null
org.apache.tapestry5.commons.internal.util.TapestryException: Cannot
invoke "org.hibernate.query.Query.uniqueResult()" because the return
value of "org.hibernate.Session.createQuery(String)" is null
at
org.apache.tapestry5.internal.bindings.PropBinding.get(PropBinding.java:67)
~[tapestry-core-5.7.3.jar:?]
...
...
Caused by: java.lang.NullPointerException: Cannot invoke
"org.hibernate.query.Query.uniqueResult()" because the return value of
"org.hibernate.Session.createQuery(String)" is null
at
info.ajanovski.muldequa.services.AppModule$3.create(AppModule.java:150)
~[classes/:?]
...
Exactly the location noted above.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org