[jboss-user] [JBoss Seam] - Re: Destroying Context Variable
jamesjmp
do-not-reply at jboss.com
Fri Oct 26 07:20:00 EDT 2007
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!
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4099219#4099219
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4099219
More information about the jboss-user
mailing list