Help

Controls

PermLinkWikiLink

Built with Seam

You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.

Forum: Seam Users Forum ListTopic List
16. Aug 2008, 22:52 CET | Link

Hello All.
I'm pretty new to seam. and I wrote a small code but i'm facing a problem with a DataModel List
the case as follows
my pages.xml look like this:


<page view-id="/editCertificates.xhtml" action="#{certificateBean.initCertificates}" >
 <navigation>
        <rule if-outcome="certificatesUpdated">
           <redirect view-id="/listPatches.xhtml" />
        </rule>
 </navigation>
</page>
         <page view-id="/listPatches.xhtml">
<param name="patch.id" value="#{patchHome.id}" converterId="javax.faces.Long" />
        <navigation>
                <rule if-outcome="merged">
                        <redirect view-id="/listPatches.xhtml" />
                </rule>
                <rule if-outcome="certificatesCreated">
                        <redirect view-id="/editCertificates.xhtml" />
                </rule>
        </navigation>
</page>

the scenario starts as follows
1- I list the patches in a listPatches.xhtml and within the page there is a link to initialize the certificates relatd to this patch depending on a value within the patch bean,this is all done in PatchHome class using a method called createCertificates as followos
@Name("patchHome")
@Scope(ScopeType.CONVERSATION)
public class PatchHome extends EntityHome<Patch> {

        @DataModel("patches")
        private List patches;
                 @DataModelSelection("patches")
        @Out(scope = ScopeType.CONVERSATION, required = false)
        private Patch patchModel;


@Begin
public String createCertificates() {
        int size = patchModel.getCertificates().size();
        if(size == 0) {
                List<Certificate> certs = patchModel.getCertificates();
                Date date = new Date(System.currentTimeMillis());
                for (int i = 0; i < patchModel.getFirstYearCCRCount().intValue(); i++) {
                        Certificate c = new Certificate(patchModel, null, date, "testuser", null, null, new Integer((patchModel.getFirstYear().intValue() - 2000)));
                                certs.add(c);
                        }
getEntityManager().merge(patchModel);
return "certificatesCreated";
}
}

2- The code above works fine and persist the list of certificates related to the page
3- when the editCertificates.xhtml is rendered depending on the Second Seam Component the got the patchModel object Injected from the above class, but the problem is when i call the command button after setting some values to the certificates that are already created and only need some fields to be updated the list is returned null
@Name("certificateBean")
public class CertificateHome {
                 @In
        private Patch patchModel;
                 @In
        private EntityManager entityManager;
                 @DataModel
        private List fetchedCertificates;
                 @Factory("fetchedCertificates")
        public void initCertificates() {
                fetchedCertificates = patchModel.getCertificates();
        }

        @End
        public String updateCertificates() {
         // the real problem goes here. because the fetchedCertificates list is null when
         // this method is called.
        }
}

the s:button looks like this
<s:button id="persis" value="Update" action="#{certificateBean.updateCertificates}"/>

Please Anyone can tell me what am I missing here. what makes the list empty.

Thanks in advance



1 Reply:
17. Aug 2008, 19:22 CET | Link

Finally I was able to solve this problem

I simply replaced the s:button with the h:commandButton

but honestly i don't know what the read difference is.

Hope this is useful for you also