|
From: Johan T. <jt...@us...> - 2007-01-24 21:31:53
|
Update of /cvsroot/boakeity/boakeity/src/se/biobanksregistersyd/boakeity/action In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv28770/src/se/biobanksregistersyd/boakeity/action Modified Files: BiobankUi.java BiobankUiAction.java Log Message: More fiddling with loading and storing. Mark all factory populated member variables with @Out(required=false) as not all fields will be populated at once, but really one at a time as the JSF-component tree is traversed and each @Factory method is called. Index: BiobankUiAction.java =================================================================== RCS file: /cvsroot/boakeity/boakeity/src/se/biobanksregistersyd/boakeity/action/BiobankUiAction.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- BiobankUiAction.java 17 Jan 2007 22:56:49 -0000 1.5 +++ BiobankUiAction.java 24 Jan 2007 21:31:50 -0000 1.6 @@ -34,11 +34,14 @@ import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; +import org.jboss.seam.ScopeType; +import org.jboss.seam.annotations.Begin; import org.jboss.seam.annotations.Factory; import org.jboss.seam.annotations.In; import org.jboss.seam.annotations.Logger; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Out; +import org.jboss.seam.annotations.Scope; import org.jboss.seam.core.FacesMessages; import org.jboss.seam.core.ResourceBundle; import org.jboss.seam.log.Log; @@ -47,18 +50,18 @@ /** * Action paired with 'biobankui.xhtml'. - * */ @Stateless -@Name("biobankui") +@Name("biobankUiAction") +@Scope(ScopeType.CONVERSATION) public class BiobankUiAction implements BiobankUi { /** The biobank under edit. */ - @In + @Out @In(create = true) private Biobank biobank; /** A list of possible choices for principalType, for use in JSF. */ - @Out + @Out(required = false) private List < SelectItem > principalTypeList; /** A list of possible choices for biobankType, for use in JSF. */ @@ -78,11 +81,43 @@ private Log log; /** + * Load a <code>Biobank</code>. Due to the page declaration in + * <code>pages.xml</code> this method is always called at every + * request. + * + * @param biobankId a <code>String</code> with the primary key + * of the <code>Biobank</code> to load, or + * <code>null</code> if no <code>Biobank</code> + * should be loaded. + * @throws EntityNotFoundException if unable to load the + * <code>Biobank</code>. + */ + @Begin(join = true) + public void loadBiobank(final String biobankId) + throws EntityNotFoundException { + if (biobankId == null || biobankId.trim().equals("")) { + System.out.println("create?"); + if (biobank == null) { + System.out.println("new Biobank()"); + biobank = new Biobank(); + } + } else { + // Lookup the biobank from the DB. + System.out.println("find"); + biobank = manager.find(Biobank.class, biobankId); + if (biobank == null) { + throw new EntityNotFoundException("Biobank", biobankId); + } + } + } + + /** * Store the edited data to persistent storage. * * @return the JSP page to redirect to. */ public String store() { + System.out.println("biobank: store()"); Biobank biobankP = manager.find(Biobank.class, biobank.getBiobankId()); if (biobankP == null) { manager.persist(biobank); @@ -134,11 +169,11 @@ @Factory("biobankCountryTypeList") public void findCountryTypeList() { biobankCountryTypeList = new ArrayList < SelectItem > (); - String list = ResourceBundle.instance().getString("BiobankCountryTypeList"); + String list = ResourceBundle.instance().getString( + "BiobankCountryTypeList"); for (String type : list.split("\\|")) { String[] tmp = type.split(";"); biobankCountryTypeList.add(new SelectItem(tmp[0], tmp[1])); } } - } Index: BiobankUi.java =================================================================== RCS file: /cvsroot/boakeity/boakeity/src/se/biobanksregistersyd/boakeity/action/BiobankUi.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- BiobankUi.java 17 Jan 2007 22:56:49 -0000 1.5 +++ BiobankUi.java 24 Jan 2007 21:31:50 -0000 1.6 @@ -34,6 +34,18 @@ */ @Local public interface BiobankUi { + + /** + * Load a <code>Biobank</code>. + * + * @param biobankId a <code>String</code> with the primary key + * of the <code>Biobank</code>. + * @throws EntityNotFoundException if unable to load the + * <code>Biobank</code>. + */ + void loadBiobank(final String biobankId) + throws EntityNotFoundException; + /** * Store the edited data to persistent storage. * @@ -58,4 +70,5 @@ * string from message bundles. */ void findCountryTypeList(); + } |