<s:iterator value="results" status="status">
<s:if test="#status.odd">
<tr bgcolor="#F8ECE0">
</s:if>
<s:else>
<tr>
</s:else>
Sunday, April 19, 2009
Saturday, February 21, 2009
Struts2 nested checkbox tag inside iterator
Using the s:iterator tag and status attribute it's possible to display and update values of complex types within a collection.
For example, using an iterator tag,
within a form tag, the submit action will update the list of results in the Action class, where my action class has
with getters and setters, and my ProductBean has,
Note: If you find something useful, please leave a comment, thanks!
Using the s:iterator tag and status attribute it's possible to display and update values of complex types within a collection.
For example, using an iterator tag,
<s:iterator value="results" status="status">
<s:hidden value="%{product.sku}" name="results[%{#status.index}].product.sku" />
<input type="checkbox" name="results[<s:property value="%{#status.index}" />].selected" <s:property value="%{selected}" />>
</s:iterator>
within a form tag, the submit action will update the list of results in the Action class, where my action class has
protected List<ProductBean> results;
with getters and setters, and my ProductBean has,
private Product product;
with getters and setters, and
private boolean selected;
/**
* @return the selected
*/
public String isSelected() {
return selected ? "checked" : "";
}
/**
* @param selected the selected to set
*/
public void setSelected(String selected) {
this.selected = selected == null || selected.equals("") ? false : true;
}
Note: If you find something useful, please leave a comment, thanks!
Wednesday, July 23, 2008
Implement connection pooling in Tomcat 5.5 using Hibernate 3, MySQL 5
Culled from various sources:
Add JDBC driver, mysql-connector-java-5.1.5.jar to apache-tomcat-5.5.xx\common\lib
Add resource-ref to WEB-INF/web.xml
Culled from various sources:
Add JDBC driver, mysql-connector-java-5.1.5.jar to apache-tomcat-5.5.xx\common\lib
Add resource-ref to WEB-INF/web.xml
<web-app ...>
...
<resource-ref>
<description>
Resource reference to a factory for java.sql.Connection
instances that may be used for talking to a particular
database that is configured in the server.xml file.
</description>
<res-ref-name>jdbc/MySqlDb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
Add session-factory name attribute and property elements to WEB-INF/classes/hibernate.cfg.xml<hibernate-configuration>
<session-factory name="java:hibernate/SessionFactory">
<!-- JNDI Connection -->
<property name="hibernate.connection.datasource">
java:comp/env/jdbc/MySqlDS
</property>
<property name="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</property>
...
</session-factory>
</hibernate-configuration>
Add Resource to META-INF/context.xml, alternatively add Resource to GlobalResources in tomcat server.xml<?xml version="1.0" encoding="UTF-8"?>
<Context path="/MyApp" reloadable="true">
<Resource name="jdbc/MySqlDS" auth="Container"
type="javax.sql.DataSource"
maxActive="100" maxIdle="10" maxWait="10000"
username="myUsername" password="myPassword"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/bookstore?autoReconnect=true"/>
</Context>
That should work!
Subscribe to:
Posts (Atom)