[JBoss Seam] - Need help updating multi-table dataTable - injecting list?
by asookazian
I have successfully created a dataTable based on two different DB tables with a 1:1 relationship. I need to know for CRUD purposes, how will it be possible to update the DB in a JSF/Seam/EJB3 framework this app is currently in.
Specifically, as in the pic below, you see that the user can change multiple columns in multiple rows for one of the entities (in this case only the CreditCard data can be updated, the Customer data is read-only).
I've seen in the hotel booking example that you inject the instance of the entity bean that had its setter methods called when the form was submitted in the JSF. In this case, it's not just one row that's being set and updated, it's potentially multiple rows in one transaction/use-case.
Does Seam support this? If so, how can I persist multiple rows/entity instances in a single transaction? It seems that I must inject the entire List of modified rows/entities into the SFSB first.
See partial code below:
CustomerAction.java (SFSB):
| @DataModel
| private List<Customers> customers;
|
| @DataModelSelection
| private Customers customer;
|
| @Factory("customers")
| public void find()
| {
|
| customers = em.createQuery("select c, cc "+
| "from Customers c inner join c.creditCard as cc "+
| "where c.userId = :userId")
| .setParameter("userId", user.getUserId())
| .getResultList();
|
| }
myJSF.xhtml:
| <h:form>
|
| <h:dataTable value="#{customers}" var="customer"
| bgcolor="#F1F1F1" border="10" width="100%" cellpadding="0" cellspacing="0"
| dir="LTR" frame="hsides">
| <h:column>
| <f:facet name="header">First Name</f:facet>
|
| <h:outputText value="#{customer[0].firstName}"/>
| </h:column>
|
| <h:column>
| <f:facet name="header">Last Name</f:facet>
|
| <h:outputText value="#{customer[0].lastName}"/>
| </h:column>
|
| <h:column>
| <f:facet name="header">Street Name</f:facet>
| <h:outputText value="#{customer[0].streetName}"/>
| </h:column>
|
| <h:column>
| <f:facet name="header">CC #</f:facet>
|
| <h:inputText value="#{customer[1].creditcardnumber}"/>
| </h:column>
|
| <h:column>
| <f:facet name="header">Company Name</f:facet>
|
| <h:inputText value="#{customer[1].companyname}"/>
| </h:column>
|
|
| </h:dataTable>
|
| <h:commandButton value="submit" action="#{customerAction.submit}"/>
| </h:form>
[img]http://i145.photobucket.com/albums/r234/rabiesjoy/java/multi-table-da...]
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4092127#4092127
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4092127
18Â years, 6Â months
[JBoss Seam] - Losing Home#instance reference
by rnallakukkala
Hi there,
I'm fairly new the seam world and currently using code base of seam 2 nightly build. was trying to do our business validation and landed into a scenario where my home#instance variable reference is lost upon invocation of an another seam component's method.
here's my code
Home bean
| @Name(MembershipHome.COMPONENT_NAME)
| public class MembershipHome extends EntityHome<Membership> {
|
| @In(value=MembershipValidation.COMPONENT_NAME,create=true)
| private MembershipValidation membershipValidation;
| .....
| .....
| @Override
| public String persist(){
| Membership instance = getInstance();
| membershipValidation.validate();// loosing the reference of the instance variable after this call.
| setInstance(instance);//explicit setting of the instance works as expected, but nasty right?
| if(!membershipValidation.isEmpty()) {
| membershipValidation.flushErrors();
| return "error";//TODO is there any standard form that Seam recommand
| }
| return super.persist();
| }
| .....
| .....
| }
|
Here's my validation class
| @Name(MembershipValidation.COMPONENT_NAME)
| public class MembershipValidation extends BaseValidator{
|
| public final static String COMPONENT_NAME ="membershipValidation";
|
| @In(MembershipHome.COMPONENT_NAME)
| private MembershipHome membershipHome;
|
| public void validate(){
| << some crazy validations>>
| }
| .....
| .....
| }
|
Now the problem I'm running to is
Prior to the "membershipValidation.validate();" method invocation, the home object has the reference to the entity instance, but after the method invocation the "instance" reference is lost.
Please note that explicit setting of the instance reference after this method call (membershipValidation.validate()) works as expected; but explicit setting of the setInstance isnt looking beautiful though :-(.
Can you suggest me what's taking me wrong?
Thanks
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4092125#4092125
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4092125
18Â years, 6Â months
[JBoss Seam] - SFSB Method(Event Handler) still called after form validatio
by jfrankman
I have a SFSB that has a save method linked to a save button on my page. I have @NotNull validation annotations on the entity bean. When I submit the form I see the error messages appear from the the decorator tags, but the "save" event handler is still called and the page is reloaded with its original values. My understanding is that if validation fails on a form, the event handler does not get called and the invalid values in the form remain, so either I am doing something wrong, or I misundertand the form validation in SEAM. I believe it works this way because seam-gen'ed applicaitions do not appear to invoke the EntityHome.persist() if the form validation fails. When form validation fails does/should the SFSB method (Event handler) still get called?
Here is the code in question:
Entity Object:
@Entity
| @Table(name = "FBCLIENTTRANS")
| @Name("clientTransmittal")
| public class ClientTransmittalVO {
|
| private int id;
| private Date transdate;
| private String countycode;
| private Integer agentno;
| private String clientfirstname;
| private String clientlastname;
| private String receiptnumber;
| private Integer clientid;
| private ClientVO client;
|
| private Set<ClientTransmittalLineItemVO> clientTransmittalLineItemVOs = new HashSet<ClientTransmittalLineItemVO>(
| 0);
|
| public ClientTransmittalVO() {
| }
|
| @Id
| @Column(name = "ID", unique = true, nullable = false)
| @NotNull @GeneratedValue
| public int getId() {
| return this.id;
| }
|
| public void setId(int id) {
| this.id = id;
| }
|
| @Temporal(TemporalType.DATE)
| @Basic @Column(name = "TRANSDATE")
| @NotNull
| public Date getTransdate() {
| return this.transdate;
| }
|
| @Column(name = "COUNTYCODE", nullable = false, length = 5)
| @NotNull
| @Length(max = 5)
| public String getCountycode() {
| return this.countycode;
| }
|
| @Column(name = "AGENTNO")
| public Integer getAgentno() {
| return this.agentno;
| }
|
| @Column(name = "CLIENTFIRSTNAME", length = 50)
| @Length(max = 50)
| public String getClientfirstname() {
| return this.clientfirstname;
| }
|
|
| @Column(name = "CLIENTLASTNAME", length = 50)
| @Length(max = 50)
| public String getClientlastname() {
| return this.clientlastname;
| }
|
| @Column(name = "RECEIPTNUMBER", length = 10)
| @Length(max = 10)
| public String getReceiptnumber() {
| return this.receiptnumber;
| }
|
| @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "clientTransmittal")
| public Set<ClientTransmittalLineItemVO> getClientTransmittalLineItems() {
| return this.clientTransmittalLineItemVOs;
| }
|
| @ManyToOne(cascade = CascadeType.ALL)
| @JoinColumn(name = "CLIENTID", nullable = false)
| @NotNull
| public ClientVO getClient() {
| return client;
| }
|
|
| @Transient
| public void addLineItem(ClientTransmittalLineItemVO lineItem)
| {
| clientTransmittalLineItemVOs.add(lineItem);
| lineItem.setClientTransmittal(this);
| }
|
| @Transient
| public List<ClientTransmittalLineItemVO> getLineItemsList()
| {
| List<ClientTransmittalLineItemVO> list = new ArrayList<ClientTransmittalLineItemVO>(getClientTransmittalLineItems());
| return list;
|
| }
| }
SFSB:
@Stateful
| @Name("clientTransmittalLineItemAction")
| @Scope(ScopeType.SESSION)
| public class ClientTransmittalLineItemActionImpl implements
| ClientTransmittalLineItemAction {
|
| @In(required=false) @Out(required=false) ClientVO client;
| @In(create=true) private ClientService clientService;
| @In(required=false) @Out(required=false) ClientTransmittalVO clientTransmittal;
|
| @Out(value="emptyLineItems")
| boolean emptyLineItems=true;
|
| @DataModelSelection
| @Out(required=false, value="lineItem")
| private ClientTransmittalLineItemVO clientTransmittalLineItemx;
|
| @DataModel
| List<ClientTransmittalLineItemVO> lineItems;
|
| @Factory("lineItems")
| public void findLineItems()
| {
|
| long clientId=client.getId();
| ClientVO client=clientService.findClientByIdFetchGraph(clientId);
| for (ClientTransmittalVO transmittal : client.getTransmittalsList()) {
| if (transmittal.getId()==clientTransmittal.getId()){
| clientTransmittal=transmittal;
| }
| }
|
| lineItems=clientTransmittal.getLineItemsList();
| emptyLineItems=lineItems.isEmpty();
| }
|
| public String saveClientTransmittal()
| {
|
| ClientVO clientSave=clientService.findClientByIdFetchGraph(client.getId());
|
| clientSave.addTransmittal(clientTransmittal);
| if (clientTransmittal.getId()>0)
| {
| clientService.saveClient(clientSave);
| client=clientSave;
| return "transUpdated";
| }
| else
| {
| clientService.saveNewClient(clientSave);
| client=clientSave;
| clientTransmittalLineItemx=new ClientTransmittalLineItemVO();
| clientTransmittalLineItemx.setClientTransmittal(clientTransmittal);
| //technically a client can have more than one agent. So this could
| //be a list box, but 99% only have one agent, so default to the agent number
| //on the first policy.
| Integer agentNumber;
| if (client.getPoliciesList().get(0)!=null)
| {
| agentNumber=(client.getPoliciesList().get(0).getAgent().getAgentNumber().intValue());
| clientTransmittalLineItemx.setAgentnumber(agentNumber);
| }
|
| clientTransmittalLineItemx.setAgentpersonid(client.getId().intValue());
| return "transCreated";
| }
|
| //transmittals=client.getTransmittalsList();
| }
|
| @Remove @Destroy
| public void destroy() {}
|
| }
jsf page:
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
| "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
| <ui:composition xmlns="http://www.w3.org/1999/xhtml"
| xmlns:s="http://jboss.com/products/seam/taglib"
| 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:a="https://ajax4jsf.dev.java.net/ajax"
| xmlns:rich="http://richfaces.ajax4jsf.org/rich"
| template="layout/frametemplate.xhtml">
|
| <ui:define name="body">
|
| <h:messages globalOnly="true" styleClass="message" id="globalMessages" />
|
| <h:form id="countytrans" styleClass="edit">
| <s:validateAll>
| <rich:panel>
| <f:facet name="header">Edit Countytrans</f:facet>
|
| <s:decorate id="idDecoration" template="layout/edit.xhtml">
| <ui:define name="label">id</ui:define>
| <h:inputText id="id" required="true"
| value="#{clientTransmittal.id}">
| <a:support event="onblur" reRender="idDecoration" />
| </h:inputText>
| </s:decorate>
|
| <s:decorate id="transdateDecoration" template="layout/edit.xhtml">
| <ui:define name="label">transdat</ui:define>
| <h:inputText id="transdate" size="16"
| value="#{clientTransmittal.transdate}">
| <s:convertDateTime pattern="MM/dd/yyyy" />
|
| <a:support event="onchange" reRender="transdateDecoration"
| ajaxSingle="true" />
| </h:inputText>
| <s:selectDate for="transdate" format="MM/dd/yyyy">
| <img src="images/dtpick.gif" />
| <a:support event="onclick" reRender="transdateDecoration"
| ajaxSingle="true" />
| </s:selectDate>
|
| </s:decorate>
|
| <s:decorate id="countycodeDecoration" template="layout/edit.xhtml">
| <ui:define name="label">countycode</ui:define>
| <h:inputText id="countycode" required="true" size="5"
| maxlength="5" value="#{clientTransmittal.countycode}">
| <a:support event="onblur" reRender="countycodeDecoration" />
| </h:inputText>
| </s:decorate>
|
| <s:decorate id="agentnoDecoration" template="layout/edit.xhtml">
| <ui:define name="label">agentno</ui:define>
| <h:inputText id="agentno" value="#{clientTransmittal.agentno}">
| <a:support event="onblur" reRender="agentnoDecoration" />
| </h:inputText>
| </s:decorate>
|
| <s:decorate id="clientfirstnameDecoration"
| template="layout/edit.xhtml">
| <ui:define name="label">clientfirstname</ui:define>
| <h:inputText id="clientfirstname" size="50" maxlength="50"
| value="#{clientTransmittal.clientfirstname}">
| <a:support event="onblur" reRender="clientfirstnameDecoration" />
| </h:inputText>
| </s:decorate>
|
| <s:decorate id="clientlastnameDecoration"
| template="layout/edit.xhtml">
| <ui:define name="label">clientlastname</ui:define>
| <h:inputText id="clientlastname" size="50" maxlength="50"
| value="#{clientTransmittal.clientlastname}">
| <a:support event="onblur" reRender="clientlastnameDecoration" />
| </h:inputText>
| </s:decorate>
|
| <s:decorate id="receiptnumberDecoration"
| template="layout/edit.xhtml">
| <ui:define name="label">receiptnumber</ui:define>
| <h:inputText id="receiptnumber" size="10" maxlength="10"
| value="#{clientTransmittal.receiptnumber}">
| <a:support event="onblur" reRender="receiptnumberDecoration" />
| </h:inputText>
| </s:decorate>
|
|
| <div style="clear:both">
| <span class="required">*</span> required fields
| </div>
|
| </rich:panel>
|
| <div class="actionButtons1">
| <s:button
| action="#{clientTransmittalLineItemAction.saveClientTransmittal}"
| id="saveTransButton" value="Save Transmittal">
| </s:button>
| </div>
| </s:validateAll>
| </h:form>
| </ui:define>
|
| </ui:composition>
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4092116#4092116
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4092116
18Â years, 6Â months