-
15. Re: Destroying Context Variable
terryb Oct 26, 2007 5:37 AM (in response to terryb)James, can you please post your code for the first bit. I may learn something from that too.
If you are going New Record from the View page. The easiest fix may be to pass empty Id param in your New Record button or link. (f:param name="youPojoId" value=""/> -
16. Re: Destroying Context Variable
pmuir Oct 26, 2007 5:55 AM (in response to terryb)Also take a look at the org.jboss.seam.afterTransactionSuccess.Foo event (only in Seam 2) http://docs.jboss.org/seam/2.0.0.CR3/reference/en/html/framework.html#d0e6472
-
17. Re: Destroying Context Variable
jamesjmp Oct 26, 2007 6:00 AM (in response to terryb)thank you Pete, Is that compatible with seam 1.2.1? That´s the version I´m using.
-
18. Re: Destroying Context Variable
pmuir Oct 26, 2007 6:03 AM (in response to terryb)Please read my post
Also take a look at the org.jboss.seam.afterTransactionSuccess.Foo event (only in Seam 2)
-
19. Re: Destroying Context Variable
jamesjmp Oct 26, 2007 6:34 AM (in response to terryb)Sorry I wrote it right away, and then I realised yo hav just said that!!! I´ll prepare a post with more details and code.
-
20. Re: Destroying Context Variable
jamesjmp Oct 26, 2007 7:19 AM (in response to terryb)hello again,
Terry, Pete and whoever.., this is the problem I´m facing:
I´ve created an app by means of seam-gen without EJB3 (seam version is 1.2.1)
Let´s call the table RstReport, the following steps work fine:
- creating new data (RstReportEdit.xhtml and RstReportEdit.page)
- details of a new RstReport displayed in the RstReport.xhtml
- list of records in RstReportList.xhtml.
This are my issues:
- after creating a new RstReport, let´s call it RstReport3, if just after that I want to create a new one, the
RstReportEdit.xhtml shows the fields the RstReport3 that I´ve just created. I must log out and log in again and then the RstReportEdit.xhtml displays no previous data.
- If I go to the list, and select one row, for instance RstReport3 row to display its data (view.gif that goes to RstReport.xhtml). After having a look to that previously created RstReport, I go to create a new one, again the RstReportEdit.xhtml displays the RstReport3 data. Whenever I change one field in that edit window, RstReport 3 data is updated right away in the database.
What happens is logic, because all this pages work with the same RstReportHome object, and the RstReport of the instance hasn´t been cleaned. What should be the best way to avoid logging out each time to clean the session? (seam 1.2.1) This is what I´ve tried up to now:
- I´ve overriden persist method in the RstReportHome this way: (rstReportHome is the name of my component)@Override public String persist() { log.info("Home - persist"); String returnStatus = super.persist(); Contexts.removeFromAllContexts("rstReportHome"); return returnStatus; } @Override public String remove() { log.info("Home - remove"); String returnStatus = super.remove(); Contexts.removeFromAllContexts("rstReportHome"); return returnStatus; } @Override public String update() { log.info("Home - update"); String returnStatus = super.update(); Contexts.removeFromAllContexts("rstReportHome"); return returnStatus; }
With that after creating a new RstReport, if I go again to the edit view, all works fine. But the problem keeps on happening if I go through RstReportList.xhtml --> RstReport.xhtml -->RstReportEdit.xhtml (it shows same data, RstReport3, displayed in RstReport.xhtml)
I go to RstReportEdit.xhtml by means of a rich:menuItem<rich:menuItem value="#{messages['New']}" action="/RstReportEdit.xhtml"/>
To prevent that data from being displayed I´ve added in the invocation this:<rich:menuItem value="#{messages['New']} param NewReport" action="/RstReportEdit.xhtml?action=NewReport"> </rich:menuItem>
Then in the wire I check that param, and in that case I do this:public void wire() { try { if (action.equals("NewReport")) { clean(); } .. } public void clean() { log.info("limpiando instancia..."); Contexts.removeFromAllContexts("rstReportHome"); this.setInstance(createInstance()); } @Override protected RstReport createInstance() { log.info("createInstance..............."); RstReport rstReport = new RstReport(); Date dat = new Date(); rstReport.setReportDate(dat); Firm firma = new Firm(); rstReport.setFirm(firma); firmHome.setInstance(firma); CfgBenchmark benchmark = new CfgBenchmark(); rstReport.setCfgBenchmark(benchmark); cfgBenchmarkHome.setInstance(benchmark); CfgCurrency currency = new CfgCurrency(); cfgCurrencyHome.setInstance(currency); rstReport.setCfgCurrency(currency); Fund cartera = new Fund(); fundHome.setInstance(cartera); rstReport.setFund(cartera); //default values rstReport.setConfidenceLevel(0.99); short timeHorizonDefault = 5; rstReport.setTimeHorizon(timeHorizonDefault); rstReport.setShortDescription(" "); byte codeIni = 0; RstStatus rstStatus = new RstStatus(); rstStatus.setCode(codeIni); rstStatus.setDescription("NOT READY"); rstReport.setRstStatus(rstStatus); log.info("RstReportHome createdInstance!!"); return rstReport; }
And to prevent data from being updated whenever changed I´ve added bypassUpdates="true" in all fields this way:<a:support bypassUpdates="true" event="onblur" reRender="confidenceLevelDecoration"/>
Pete, is this the proper way to achieve this with seam 1.2.1? (Terry I haven´t check your invocation option up to now)
I could provide you with more code if you would like to.
thanks in advance! -
21. Re: Destroying Context Variable
pmuir Oct 26, 2007 7:53 AM (in response to terryb)I'm pretty sure this works out of the box on Seam 1.2 - I'll check though.
-
22. Re: Destroying Context Variable
jamesjmp Oct 26, 2007 10:14 AM (in response to terryb)hi, I´ve found a problem with what I´ve described before.
My RstReport has some attributes with are other objects. With them the edit doesn´t work.
This is the object:@Entity @Table(name = "RST_REPORT", catalog = "prisk") public class RstReport implements java.io.Serializable { private int code; //simple attribute private String shortDescription; //object attribute private CfgCurrency cfgCurrency; //more atributes... //getters, setter and constructors...
This si some of the RstReportEdit.xhtml code:<!-- simple attribute, works ok --> <s:decorate id="shortDescriptionDecoration" template="layout/edit.xhtml"> <ui:define name="label">#{messages['RstReport.shortDescription']}</ui:define> <h:inputText id="shortDescription" size="100" required="true" maxlength="125" value="#{rstReportHome.instance.shortDescription}"> <a:support event="onblur" reRender="shortDescriptionDecoration" bypassUpdates="true" /> </h:inputText> </s:decorate> <!-- object attribute, doesn´t work ok --> <s:decorate id="currencyIsoDecoration" template="layout/edit.xhtml"> <ui:define name="label">#{messages['CfgCurrency']}</ui:define> <h:inputText id="currencyIso" size="20" maxlength="50" required="true" disabled="true" value="#{rstReportHome.instance.cfgCurrency.currencyIso}"> <a:support bypassUpdates="true" event="onblur" reRender="currencyIsoDecoration"/> </h:inputText> <s:button value="#{messages['Select']} #{messages['CfgCurrency']}" view="/CfgCurrencyList.xhtml"> <f:param name="from" value="RstReportEdit"/> </s:button> </s:decorate>
And this is RstReportEdit.page.xml full code:<!DOCTYPE page PUBLIC "-//JBoss/Seam Pages Configuration DTD 1.2//EN" "http://jboss.com/products/seam/pages-1.2.dtd"> <page no-conversation-view-id="/RstReportList.xhtml" login-required="true"> <begin-conversation join="true" flush-mode="manual"/> <param name="action" value="#{rstReportHome.action}"/> <action execute="#{rstReportHome.wire}"/> <param name="rstReportFrom"/> <param name="rstReportCode" value="#{rstReportHome.rstReportCode}"/> <param name="cfgBenchmarkFrom"/> <param name="cfgBenchmarkBenchmarkCode" value="#{cfgBenchmarkHome.cfgBenchmarkBenchmarkCode}"/> <param name="cfgBenchmarkTypeFrom"/> <param name="cfgBenchmarkTypeBenchmarkTypeCode" value="#{cfgBenchmarkTypeHome.cfgBenchmarkTypeBenchmarkTypeCode}"/> <param name="firmFrom"/> <param name="firmFirmCode" value="#{firmHome.firmFirmCode}"/> <param name="cfgCurrencyFrom"/> <param name="cfgCurrencyCurrencyCode" value="#{cfgCurrencyHome.cfgCurrencyCurrencyCode}"/> <param name="rstMethodologyFrom"/> <param name="rstMethodologyCode" value="#{rstMethodologyHome.rstMethodologyCode}"/> <param name="fundFrom"/> <param name="fundFundCode" value="#{fundHome.fundFundCode}"/> <param name="rstReportTypeFrom"/> <param name="rstReportTypeCode" value="#{rstReportTypeHome.rstReportTypeCode}"/> <param name="rstStatusFrom"/> <param name="rstStatusCode" value="#{rstStatusHome.rstStatusCode}"/> <navigation from-action="#{rstReportHome.persist}"> <end-conversation/> <redirect view-id="/RstReportL.xhtml"/> </navigation> <navigation from-action="#{rstReportHome.update}"> <end-conversation/> <redirect view-id="/RstReport.xhtml"/> </navigation> </page>
For the object-attribute values I use the seam-gened list of them. For instance for the CfgCurrency POJO, CfgCurrencyList.xhtml. When I go there and select one, when returning again to RstReportEdit.xhtml all the fields are populated with that of the last RstReport.xhtml displayed in RstReport.xhtml
I guess the reason is that in the params the code has been automatically added rstReportCode=1131
http://localhost:8080/RISK_ONLINE/RstReportEdit.seam?cfgCurrencyCurrencyCode=4&action=&rstReportCode=1131&cid=13&clr=true
rstReportCode is the id, in the RstReporthome it is:public void setRstReportCode(Integer id) { setId(id); } public Integer getRstReportCode() { return (Integer) getId(); }
What would be the best way to avoid this?
thanks in advance! -
23. Re: Destroying Context Variable
jamesjmp Oct 29, 2007 4:49 AM (in response to terryb)hi,
Terry I´m trying to pass empty Id param, to check if it solves the problem I explained in the last post.
My pojo id param is rstReportCode.
I´m trying with this 3 ways and no one works ;-((<rich:menuItem value="#{messages['New']} F param" action="/RstReportEdit.xhtml"> <f:param name="rstReportCode" value=""/> </rich:menuItem> <rich:menuItem value="#{messages['New']} param rstReportCode=" action="/RstReportEdit.xhtml?rstReportCode="> </rich:menuItem> <rich:menuItem value="#{messages['New']} param rstReportCode=0" action="/RstReportEdit.xhtml?rstReportCode=0"> </rich:menuItem>
It seems that richmenuItem doesn´t work properly with f param.
any idea? thanks in advance! -
24. Re: Destroying Context Variable
rbcdexia Oct 29, 2007 7:29 AM (in response to terryb)I have the same problem. Please. Do you have any solution for it?????
-
25. Re: Destroying Context Variable
terryb Oct 29, 2007 7:37 AM (in response to terryb)I personally never tried rich:menuItem. but passing empty record ID as james is attempting worked for me from s:link. I think Pete has already suggested in this thread that seam 2 has some built in function to clear the instance.