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
05. Oct 2008, 19:45 CET | Link

Scenario:

a) User fills form say Pname, Color, etc. fields(these belongs to reagent entity fields) from a form say study.xhtml and clicks Save, values are persisted properly.

b) After above event, user clicks a link(Add More Reagents) and passes some id to a function in reagentHome. On clicking link it loads a particular reagent.xhtml page, with same fields as Pname, Color, etc.

Issue is, it holds the values as submitted at point (a), for Pname, Color, etc. in reagent.xhtml and I cannot create a new Reagent (it will be updated always) because that reagent instance is still there.

I think I need to check for creating new instance or clear instance somehow or override any function of entity home, etc... please suggest... What is the best way so that form fields are cleared and we should be able to persist new entry.

Please suggest

study.xhtml


<h:commandLink target="_new" id="name" action="#{reagentHome.getQuantId}" immediate="true">
	<h:outputText value="Add More Reagents"/>
	<f:param name="qid" value="#{quantExperimentHome.instance.hjid}"/>
</h:commandLink>

reagent.xhtml

<s:decorate id="pnameDecoration" template="layout/edit.xhtml">
<ui:define name="label">PName</ui:define>
<h:inputText id="name" required="true" immediate="true"
	     value="#{reagentHome.instance.pname}">
 </h:inputText>
</s:decorate>  
<s:decorate id="colorDecoration" template="layout/edit.xhtml">
<ui:define name="label">Color</ui:define>
<h:inputText id="name" required="true"
	     value="#{reagentHome.instance.color}"/>
</s:decorate>

reagentHome.java

@Name("reagentHome")
public class ReagentHome extends EntityHome<Reagent>
{
@RequestParameter 
Long reagentId;

@In(required=false)
private Long hjid;

@Factory("reagent")
public Reagent initReagent() { return getInstance(); }

@Override
public Object getId() 
{ 
	if (reagentId==null)
	{
		return super.getId();
	}
	else
	{
		return reagentId;
	}
}

@Override @Begin(join=true)
public void create() {
	super.create();
} 

//JUST for Testing
public String getQuantId(){
	HttpServletRequest req = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
	String qid = req.getParameter("name");
	return "reagent";
}

5 Replies:
05. Oct 2008, 21:53 CET | Link
Any suggestion on this...
05. Oct 2008, 23:20 CET | Link

The problem is probably that you are carrying bean instances across pages because they are using the same conversation. If the reagentHome bean already exists from a previous page then Seam will use that instance for the new page.

You have two choices, the first is to just use a separate conversation, and the second is to manually clear out the reagentHome instance, or at least, clear out the instance and Id values from that instance.

Cheers,

Andy

 

It's a job that's never started that takes the longest to finish. - J.R.R. Tolkien

---------- www.andygibson.net ----------

06. Oct 2008, 00:00 CET | Link
Thanks for replying Andy.

Choice 2 will be fine as of now, where in reagentHome (code provided above) I can clear out the reagentHome instance, or at least, clear out the instance and Id values from that instance.

Other thing, whenever seam uses persist (probably like in reagentHome...), where does the control go after transaction is committed.
e.g. suppose reagent have a field pname, once reagent is persisted and pname is in database, how can I get this stored value pname in database in reagentHome it self and pass it to some other external purpose.
06. Oct 2008, 00:14 CET | Link
More details Andy, for passing value to external method....

Here is the code I tried calling "passReagentId()" method in separate bean, but issue is
value of reagent id, is not committed or transaction is not committed at the time of calling "passReagentId"

@Name("reagentHome")
public class ReagentHome extends EntityHome<Reagent>
{
    @RequestParameter
    Long reagentId;
         @In(required=false)
    private Long hjid;
         @Factory("reagent")
    public Reagent initReagent() { return getInstance(); }
         @Override
    public Object getId()
    {
        if (reagentId==null)
        {
            return super.getId();
        }
        else
        {
            return reagentId;
        }
    }
         @Override @Begin(join=true)
    public void create() {
        super.create();
    }
         @Override
    public String persist(){
          getReagent();
        String persistResult = super.persist();
        //getEntityManager().setFlushMode(FlushModeType.COMMIT);
        entityManager.refresh(getInstance());
        //passReagentId();//<--- CALLING IT
        return persistResult;
    }

    public List<Reagent> getReagent() {
     ......
     return reagentList;
    }
     //PASS REAGENT ID to external method in other bean, once reagent is committed
   public void passReagentId(){
 Utils u = new Utils();
 try {
  // But this should be called after persist() method
  u.passReagent(instance.getHjid());
 } catch (SQLException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 }
    
06. Oct 2008, 02:01 CET | Link
Any suggestions... this is very important for us...