JSF, Hibernate, Spring --> Struktur

  • Themenstarter Themenstarter Guest
  • Beginndatum Beginndatum
Status
Nicht offen für weitere Antworten.
G

Guest

Gast
Hallo,

benutze JSF, Hibernate und Spring

habe folgende JSF Seite (Auszug):

Code:
<h:form>
	<table>
	<tr>
	<td>Rolename:</td>
	<td><h:inputText value="#{roleController.role.rolename}" required="true"/></td>
	</tr>
	<tr>
	<td>Username:</td>
	<td><h:inputText value="#{roleController.user.username}" required="true"/></td>
	</tr>
	<tr>
	<td></td>
	<td><h:commandButton action="#{roleController.save}" value="Speichern"/></td>
	</tr>
	</table>
</h:form>


Und dann mein RoleController dazu:

Code:
public class RoleController {

	private BeanFactory beanFactory;
	private Role role;
	private User user;
	
	public RoleController() {
		beanFactory = new ClassPathXmlApplicationContext(new String[] {"applicationContext.xml"});
	}

	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String save() {
		RoleServiceImpl roleService = (RoleServiceImpl) beanFactory.getBean("roleService");
		role.getUsers().add(user);
		user.setRole(role);
		roleService.save(role);
		return "success";
	}
}

Nun Funktioniert auch alles soweit, ich bin mir aber nichts ganz sicher ob alles korrekt strutkuriert ist, auch in Bezug auf Transaktionen.

Meine weiteren Files: Role, User (zwei ganz normale Beans), BasicDAOImpl, RoleDAO, RoleService und RoleServiceImpl

Vielen Dank im voraus!
 
Code:
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="
	[url]http://www.springframework.org/schema/beans[/url] 
	[url]http://www.springframework.org/schema/beans/spring-beans-2.5.xsd[/url]
	[url]http://www.springframework.org/schema/tx[/url] 
	[url]http://www.springframework.org/schema/tx/spring-tx-2.5.xsd[/url]
	[url]http://www.springframework.org/schema/aop[/url] 
	http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">

	<bean id="datasource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass" value="com.mysql.jdbc.Driver" />
		<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/xxx" />
		<property name="user" value="xxx" />
		<property name="password" value="xxx" />
		<property name="minPoolSize" value="2" />
		<property name="maxPoolSize" value="4" />
	</bean>
	
	<bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
		<property name="dataSource" ref="datasource"/>
		<property name="configLocation"><value>classpath:hibernate.cfg.xml</value></property>
	</bean>	
	
	<bean id="roleService"
		class="de.laliluna.example.service.RoleServiceImpl">
		<property name="roleDao" ref="roleDao" />
	</bean>

	<bean id="roleDao"
		class="de.laliluna.example.domain.RoleDao">
		<constructor-arg ref="hibernateSessionFactory" />
	</bean>
	
	<tx:annotation-driven transaction-manager="txManager"/>
	<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" >
		<property name="sessionFactory" ref="hibernateSessionFactory"/>
	</bean>
</beans>
 
Status
Nicht offen für weitere Antworten.

Zurück
Oben