我遍历一个项目列表,如果元素的状态等于学生或教师,则需要显示特定的下拉列表.以下代码显示所有字段,但不显示任何元素的下拉列表!
<s:iterator value="listOfPeople" status="element">
.....
<s:if test='%{elements[#element.index].Status.equalsIgnoreCase("Student") ||
elements[#element.index].Status.equalsIgnoreCase("Teacher")}'>
<s:select name="elements[%{#element.index}].Status"
id="elements[%{#element.index}].Status"
label="Status"
list="#{'Student':'Student','Teacher':'Teacher'}"
headerKey = "-1"
headerValue=" "
value="%{Status}"
/>
</s:if>
Run Code Online (Sandbox Code Playgroud)
在控制器中:
PeopleModel peopleModel = new PeopleModel();
listOfPeople = peopleModel.findPeople();
System.out.println("size is:" + listOfPeople.size()); //returns 8
return "listPeople";
Run Code Online (Sandbox Code Playgroud)
我的型号:
List<People> people = new ArrayList();
final Session session = HibernateUtil.getSession();
try {
final Transaction tx = session.beginTransaction();
try {
Criteria criteria = session.createCriteria(People.class, "People")
people.addAll((List<People>) criteria.list());
if (!tx.wasCommitted()) {
tx.commit();
}
if (session.isOpen()) {
session.close();
}
System.out.println("size is ::: " …Run Code Online (Sandbox Code Playgroud) 以前我使用以下代码来配置sessionFactory,但是在将我的hibernate版本从4.2.1.Final升级到4.3.4.Final后,我无法使用以下代码检索sessionFactory,因为不推荐使用ServiceRegistryBuilder().
我使用此链接创建它,但提供的函数没有返回任何东西,因此它遇到预编译错误.
private static SessionFactory configureSessionFactory() {
try {
Configuration configuration = new Configuration();
configuration.configure();
serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
return sessionFactory;
} catch (HibernateException e) {
System.out.append("** Exception in SessionFactory **");
e.printStackTrace();
}
return sessionFactory;
}
static {
try {
sessionFactory = configureSessionFactory();
} catch (Exception e) {
System.err.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
private HibernateUtil() {
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
public static Session getSession() throws HibernateException { …Run Code Online (Sandbox Code Playgroud) 我在GlassFish上运行我的应用程序,我使用Spring Security和Hibernate.当我运行应用程序时,GlassFish控制台上将显示以下警告和错误.我该如何避免它们?
WARNING: The web application [] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
SEVERE: The web application [] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@1087985b]) and a value of type [org.hibernate.internal.SessionImpl] (value [SessionImpl(PersistenceContext[entityKeys=[],collectionKeys=[]];ActionQueue[insertions=[] updates=[] deletions=[] collectionCreations=[] collectionRemovals=[] collectionUpdates=[] unresolvedInsertDependencies=UnresolvedEntityInsertActions[]])]) but failed to remove it when the web application was stopped. Threads are going to be …Run Code Online (Sandbox Code Playgroud) 我有一个包含以下字段的搜索表单
price, status, owner
Run Code Online (Sandbox Code Playgroud)
当用户填写所有字段时,请求将被发送到后端以显示具有指定价格,状态和所有者的产品的类别列表.用户可以单击每个类别以查看其产品列表.
为了实现它,我有以下方法来检索类别,并将搜索字段(价格,状态,所有者)放入会话中以在搜索的下一页中可用(当选择类别时).
参数的值可能太长了,我更喜欢将它们作为GET来轻松地为结果添加书签.
public String retrieveCategories(){
//... here I retrieve categories which their products are matched
//with the search fields
Map session = ActionContext.getContext().getSession();
session.put("Items", this.items);
return "SUCCESS";
}
Run Code Online (Sandbox Code Playgroud)
显示所有类别后,用户可以单击每个类别以查看其产品.类别的名称将发送到后端,因此我将从会话中检索值以搜索具有所选类别的相同规格的产品.
public String retrieveProductsOfSelectedCategory(){
Map session = ActionContext.getContext().getSession();
this.items = (Items) session.get("Items");
//... here I retrieve products of the selected category based on values retrieved
// from session
}
Run Code Online (Sandbox Code Playgroud)
我想知道如果不是你的建议,实施它是否是一个好习惯?