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.
| Online: | 23 Members of 4546 |
| Forum: Seam Users |
25. Jul 2008, 13:23 CET | Link |
When I create a new seam entity with jboss tools, a list and an edit page will be created, together with the necessary java code.
In the plain example, if I go to the list page, click on entry 1, click back
or on the list-link at the top of the page, click on entry 2, the edit page of entry 1 is shown.
If I am correct this is because the conversation of the first edit did not end.
What I did to solve this problem is - change in the home object:
public class MdaIcnMonthsHome extends EntityHome<MdaIcnMonths>
{
Long mdaIcnMonthsId;
@RequestParameter
public void setMdaIcnMonthsId(Long mdaIcnMonthsId) {
if (mdaIcnMonthsId != null)
if (this.getConversation().isLongRunning())
if (this.instance != null)
if (this.instance.getKey() != null)
if (this.instance.getKey().compareTo(mdaIcnMonthsId) != 0 )
this.getConversation().end();
this.mdaIcnMonthsId = mdaIcnMonthsId;
}
Is this the correct way to do this?
Update, the previous example did not work completely correct, it sometimes (first time) came up with the old answer.
I changed the thing to do to user find to reset the instance. @RequestParameter public void setMdaIcnMonthsId(Long mdaIcnMonthsId) { if (mdaIcnMonthsId != null) if (this.getConversation().isLongRunning()) if (this.instance != null) if (this.instance.getKey() != null) if (this.instance.getKey().compareTo(mdaIcnMonthsId) != 0 ) this.instance = getEntityManager().find(MdaIcnMonths.class, mdaIcnMonthsId); this.mdaIcnMonthsId = mdaIcnMonthsId; }Is this a correct thing to do?
Where do you start and stop your conversations in this example ? What is the JSF code for the links you click? Do you propagate the conversation context?
The code is created with Seam-Create new entity.
List to select the object:
<h:form id="mdaIcnMonthsForm"> <rich:panel> <f:facet name="header">mdaIcnMonths for month #{mdaIcnMonthsHome.instance.stmPerPeriodsR.month}</f:facet> <s:decorate id="nameDecoration" template="layout/edit.xhtml" for="name"> <ui:define name="label">DollarExchangeRate</ui:define> <h:inputText id="name" required="true" value="#{mdaIcnMonthsHome.instance.dollarExchangeRate}" rendered="#{s:hasRole('MDA_DOLLAR_USER')}"/> <h:outputText value="#{mdaIcnMonthsHome.instance.dollarExchangeRate}" rendered="#{!s:hasRole('MDA_DOLLAR_USER')}"/> </s:decorate> <div style="clear:both"/> </rich:panel> <div class="actionButtons"> <h:commandButton id="update" value="Save" action="#{mdaIcnMonthsHome.update}" rendered="#{mdaIcnMonthsHome.managed and s:hasRole('MDA_DOLLAR_USER')}"/> <s:button propagation="end" id="done" value="Done" view="/mdaIcnMonthsList.xhtml"/> </div> </h:form>The home object is also standard
@Name("mdaIcnMonthsHome") public class MdaIcnMonthsHome extends EntityHome<MdaIcnMonths> { @RequestParameter Long mdaIcnMonthsId; @Override public Object getId() { if (mdaIcnMonthsId==null) { return super.getId(); } else { return mdaIcnMonthsId; } } @Override @Begin public void create() { super.create(); } @Override @Restrict("#{s:hasRole('MDA_DOLLAR_USER'}") public String persist() { // TODO Auto-generated method stub return super.persist(); } }Sorry, missed the list page:
<h:dataTable id="mdaIcnMonthsList" var="mdaIcnMonths" value="#{mdaIcnMonthsList.resultList}" rendered="#{not empty mdaIcnMonthsList.resultList}"> <h:column> <f:facet name="header">Month</f:facet> <s:link id="name" value="#{mdaIcnMonths.stmPerPeriodsR.month} " view="/mdaIcnMonths.xhtml" > <f:param name="mdaIcnMonthsId" value="#{mdaIcnMonths.key}"/> </s:link> </h:column>