[jboss-user] [JBoss Seam] - Re: ajax and EntityHome (Conversation) bug?!
dashti
do-not-reply at jboss.com
Tue Nov 27 12:26:56 EST 2007
excuse me, the las file in the previous post was FormInstance.java.
FormInstanceHome.java:
| package com.behdasht.eb;
|
| import java.util.ArrayList;
| import java.util.List;
|
| import javax.faces.event.ActionEvent;
| import javax.faces.model.SelectItem;
|
| import org.jboss.seam.annotations.Begin;
| import org.jboss.seam.annotations.In;
| import org.jboss.seam.annotations.Logger;
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.core.ResourceBundle;
| import org.jboss.seam.framework.EntityHome;
| import org.jboss.seam.log.Log;
|
| @Name("formInstanceHome")
| public class FormInstanceHome extends EntityHome<FormInstance> {
|
| @In(create = true)
| VisitHome visitHome;
| @In(create = true)
| FormStructureHome formStructureHome;
|
| public void setFormInstanceFormInstanceId(Long id) {
| setId(id);
| }
|
| public Long getFormInstanceFormInstanceId() {
| return (Long) getId();
| }
|
| @Override
| protected FormInstance createInstance() {
| FormInstance formInstance = new FormInstance();
| return formInstance;
| }
|
| public void wire() {
|
| Visit visit = visitHome.getDefinedInstance();
| if (visit != null) {
| getInstance().setVisit(visit);
| }
| FormStructure formStructure = formStructureHome.getDefinedInstance();
| if (formStructure != null) {
| getInstance().setFormStructure(formStructure);
| }
| }
|
| public boolean isWired() {
| return true;
| }
|
| public FormInstance getDefinedInstance() {
| return isIdDefined() ? getInstance() : null;
| }
|
| public List<FieldValue> getFieldValues() {
| return getInstance() == null ? null : getInstance().getFieldValues();
| }
|
|
|
|
|
| @Logger
| Log log;
| private int fieldNum;
| private List<SelectItem> formStructures;
| private List<SelectItem> threeState;
| FormStructure selectedFormStructure;
| @Override
| public String persist(){
| super.persist();
| List<FieldValue> fieldValues;
| if (selectedFormStructure != null ) {
| getDefinedInstance().setFormStructure(selectedFormStructure);
| fieldValues = new ArrayList<FieldValue>();
| FieldValue fv;
| for(Field f : getDefinedInstance().getFormStructure().getFields()){
| fv = new FieldValue();
| fv.setField(f);
| fv.setFormInstance(getDefinedInstance());
| fieldValues.add(fv);
| getEntityManager().persist(fv.getFormInstance());
| }
| getDefinedInstance().setFieldValues(fieldValues);
| super.update();
| }
|
| return "persisted";
| }
|
| //@Begin(join=true)
| public void selectFormInstanceFromTable(ActionEvent event){
| FormInstance fi = (FormInstance)getEntityManager().createQuery("select fi from FormInstance fi where fi.formInstanceId=:fid").setParameter("fid", new Long((String)getId())).getSingleResult();
| setInstance(fi);
| setId(fi.getFormInstanceId());
| }
|
| @Override
| public String update() {
| if(getInstance() == null)
| log.info("baba aslan nulleeeeeeeeeeeeeeeeeeee !!");
| log.info("oomad inja tooye update!!\n" + "fi.getID()=" + getInstance().getFormInstanceId());
| //getEntityManager().refresh(getInstance());
| super.update();
| List<FieldValue> fieldValues;
| if (selectedFormStructure != null && selectedFormStructure != getInstance().getFormStructure()) {
| for(FieldValue fv : getDefinedInstance().getFieldValues()){
| fv.setFormInstance(null);
| fv.setField(null);
| getEntityManager().remove(fv);
| }
| getInstance().setFieldValues(null);
| getInstance().setFormStructure(selectedFormStructure);
|
| fieldValues = new ArrayList<FieldValue>();
| FieldValue fv;
| for(Field f : getInstance().getFormStructure().getFields()){
| fv = new FieldValue();
| fv.setField(f);
| fv.setFormInstance(getDefinedInstance());
| fieldValues.add(fv);
| getEntityManager().persist(fv.getFormInstance());
| }
| getInstance().setFieldValues(fieldValues);
| super.update();
| }
|
| return "updated";
| }
|
| public int getFieldNum() {
| fieldNum++;
| return fieldNum;
| }
|
| public List<SelectItem> getFormStructures(){
| formStructures = new ArrayList<SelectItem>();
| SelectItem si;
| List<FormStructure> list = (List<FormStructure>)getEntityManager().createQuery("from FormStructure").getResultList();
| for(FormStructure fs : list){
| si = new SelectItem();
| si.setLabel(fs.getFormName());
| si.setValue(fs);
| formStructures.add(si);
| }
| return formStructures;
| }
|
| public List<SelectItem> getThreeSatet() {
| if (threeState == null){
|
| threeState = new ArrayList<SelectItem>();
|
|
| threeState.add(new SelectItem(0, ResourceBundle.instance().getString("Unknown")));
| threeState.add(new SelectItem(1, ResourceBundle.instance().getString("Yes")));
| threeState.add(new SelectItem(-1, ResourceBundle.instance().getString("No")));
|
| }
|
| return threeState;
| }
|
| public void newInstance() {
| FormInstance instance = createInstance();
| super.setInstance(instance);
| }
|
| public FormStructure getSelectedFormStructure() {
| selectedFormStructure = getInstance().getFormStructure();
| return selectedFormStructure;
| }
|
| public void setSelectedFormStructure(FormStructure selectedFormStructure) {
| this.selectedFormStructure = selectedFormStructure;
| }
|
| }
|
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4108167#4108167
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4108167
More information about the jboss-user
mailing list