[JBoss Seam] - Re: Entities with one/many_to_many relationships and SEAM
by adam.stortz
Trouby,
Yes, I am using JBoss with JSF 1.2_01 RI and facelets
I am using JBoss 4.0.4 with the EJB 3.0 RC8 update
I am not using the multiple SelectItems to populate a ManyToMany or OneToMany relationship, I am injecting the selected items into a stateful session bean, but translating it to manage an entity relationship would be fairly easy. Here are the important pieces of code, maybe another example would help you. The most interesting parts will be in bold.
editBlogEntry.xhtml
| <ui:composition template="/template/template.xhtml"
| xmlns="http://www.w3.org/1999/xhtml"
| xmlns:ui="http://java.sun.com/jsf/facelets"
| xmlns:f="http://java.sun.com/jsf/core"
| xmlns:h="http://java.sun.com/jsf/html"
| xmlns:selectitems="http://jboss.com/products/seam/selectitems/taglib">
|
| <ui:define name="body">
| <h:messages globalOnly="true" layout="list" />
|
| <h:form>
| <h:inputHidden value="${blogEntry.id}" />
| <h:panelGrid columns="3">
|
| <h:outputText value="${msgs.title}:" />
| <h:inputText id="title" value="${blogEntry.title}" required="true"/>
| <h:message for="title" styleClass="error"/>
|
| <h:outputText value="${msgs.body}:" />
| <h:inputTextarea id="body" value="${blogEntry.body}" rows="50" cols="30"/>
| <h:message for="body" styleClass="error"/>
|
| <h:outputText value="${msgs.userGroups}:"/>
| <h:outputText value="${msgs.userGroupsEmpty}" rendered="${empty userGroupsSelectItems}" />
| <h:selectManyListbox id="userGroups" size="5" value="${blogEntryService.selectedUserGroups}" rendered="${not empty userGroupsSelectItems}">
| <f:selectItems value="${userGroupsSelectItems}"/>
| <selectitems:convertEntity entityClass="org.unleashed.ejb.entity.UserGroup" />
| </h:selectManyListbox>
| <h:message for="userGroups" styleClass="error" rendered="${not empty userGroupsSelectItems}"/>
|
| </h:panelGrid>
|
| <h:commandButton action="${blogEntryService.save}" value="${msgs.save}" />
| </h:form>
|
| </ui:define>
| </ui:composition>
|
BlogEntryServiceBean.java - This is where the multiple select items get injected from the page
| @Stateful
| @Name("blogEntryService")
| public class BlogEntryServiceBean implements BlogEntryService{
|
|
| @Logger private Log log;
|
| @PersistenceContext
| private EntityManager em;
|
| @In (create=true)
| @Out
| @Valid
| private BlogEntry blogEntry;
|
|
| @SelectItems(label="name")
| private List<UserGroup> userGroupsSelectItems;
|
| private List<UserGroup> selectedUserGroups;
|
| @Factory("userGroupsSelectItems")
| public List<UserGroup> findAllUserGroupsSelectItems()
| {
| userGroupsSelectItems = em.createQuery("from UserGroup userGroup").getResultList();
| return userGroupsSelectItems;
| }
|
| @IfInvalid(outcome=Outcome.REDISPLAY)
| public String save()
| {
| log.debug("Selected User Groups: '" + selectedUserGroups + "'");
| blogEntry.setPostDate(new Date());
| log.debug("Saving Blog Entry: " + blogEntry);
| em.merge(blogEntry);
| log.debug("Blog Entry: " + blogEntry + " saved.");
| return "viewBlogEntries";
| }
|
| public List<UserGroup> getSelectedUserGroups()
| {
| return selectedUserGroups;
| }
| public void setSelectedUserGroups(List<UserGroup> selectedUserGroups)
| {
| this.selectedUserGroups = selectedUserGroups;
| }
| ...
|
| }
|
|
In the save method, the selected items are logged, right now I am performing no actions based on the selection, but the proper output shows up in the log
components.xml - Deployed in WEB-INF
FYI unleashed is the name of my application
| <components>
|
| <component class="org.jboss.seam.selectitems.SelectItemsPersistenceConfig">
| <property name="persistenceUnitJndiName">java:/selectItemsEntityManagerFactory</property>
| </component>
|
| <component name="em" class="org.jboss.seam.core.ManagedPersistenceContext">
| <property name="persistenceUnitJndiName">java:/unleashedEntityManagerFactory</property>
| </component>
|
| <component class="org.jboss.seam.selectitems.SelectItemsPersistenceConfig">
| <property name="persistenceUnitJndiName">java:/unleashedEntityManagerFactory</property>
| </component>
| </components>
|
I also had to override the equals method in my UserGroup entity:
| @Override
| public boolean equals(Object obj) {
| if (obj instanceof UserGroup) {
| UserGroup userGroup = (UserGroup) obj;
| return this.id == userGroup.getId();
| } else {
| return false;
| }
| }
|
I think that covers all of the code that has any impact on that. If you have any questions about the code, please let me know.
Regards,
Adam
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3967212#3967212
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3967212
19 years, 8 months
[Tomcat, HTTPD, Servlets & JSP] - How to run ajax4jsf on jboss app server 4.0.4
by mind_mantra
Could any one tell how to run ajax4jsf on jboss app server or give any working example where ajax4jsf is running on jboss.
I tried to run ajax4jsf on jboss app server 4.0.4 but its not running.
I downloaded the war from following loacation-
https://ajax4jsf.dev.java.net/files/documents/4966/35187/a4j-button-and-l...
and deployed it to jboss. It gave exception and could not deploy and run.
But the same application is running perfectly in a separate Tomcat
I removed jsf-api.jar and jsf-impl.jar from lib then it deployed.(MyFaces jsf jars are already there in jbossweb-*.sar lib folder) It gave following Exception at deployment -
15:46:33,750 INFO [ServletCacheAdministrator] Created new instance of ServletCacheAdministrator
| 15:46:33,750 INFO [ServletCacheAdministrator] Created new application-scoped cache at key: __oscache_cache
| 15:46:33,812 ERROR [[/ademo]] Exception starting filter ajax4jsf
| java.lang.IllegalStateException: No Factories configured for this Application - typically this is because a context listener is not setup in your web.xml.
| A typical config looks like this;
| <listener>
| <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
| </listener>
I copied and pasted above listener tag in my web.xml and removed the default listener tag in that file.
The application starts and runs.
when I click on server submit button i see the output.
But when i click "Ajax Submit" button nothing happens.
Whats wrong ? ( one i guess is the ajas4jsf filter didnt start as shown in console).
How to make it run ?
Any help would be greatly apreciated.
Thanks.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3967204#3967204
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3967204
19 years, 8 months