-
1. Re: Bean executed twice - while calling and exiting the web
nbelaevski Feb 23, 2009 4:37 AM (in response to aish)Hi,
How do you exit to the next page, by h:commandLink or by h:outputLink? -
2. Re: Bean executed twice - while calling and exiting the web
aish Feb 23, 2009 10:03 AM (in response to aish)hi,
I am using rich:menuItems to navigate between various pages. Let me post my code below for your reference. (I have given only a small section of my code due to space constraints).
Please let me know if you need additional information
Thanks
Aish
This is my index page (main page in my web):
=============
<h:form id="myForm">
This is the header section of the web page
<a4j:include viewId="/left-menu.jsp" />
<a4j:include viewId="/topmenu.jsp" />
<a4j:outputPanel id="centerGrid" >
<a4j:include viewId="#{link.address}">
</a4j:include>
Footer section
</h:form>
This is topmenu.jsp
=============
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<rich:toolBar width="100px">
<rich:dropDownMenu value="Sample1">
<rich:menuItem value="MenuItem1" action="#{link.domenuItem1}" id="dropdownmenu_mItem1" />
<rich:menuItem value="MenuItem2" action="#{link.domenuItem2}" id="dropdownmenu_mItem2" />
</rich:dropDownMenu>
</rich:toolBar>
====
This is link.java
===========
public void domenuItem1()
{
urllink="/pageMenu1.jsp";
}
public void domenuItem2()
{
urllink="/pageMenu2.jsp";
}
public String getlink()
{
return urllink;
} -
3. Re: Bean executed twice - while calling and exiting the web
nbelaevski Feb 23, 2009 12:00 PM (in response to aish)So, this happens because components nested inside data table are trying to process submitted information.
Workaround: develop phase listener that will track JSF lifecycle phases and skip data table processing if we're on 2-5 phases. Data table processing can be skipped by setting rendered="false", e.g.:<rich:dataTable rendered="#{onEncodePhase}" />
Where onEncodePhase is a request-scoped boolean parameter that will be added by phase listener on the 6th phase start. -
4. Re: Bean executed twice - while calling and exiting the web
aish Feb 23, 2009 12:11 PM (in response to aish)Hi,
Thanks for responding.
Would you be able to post some code on how to track JSF life cycle phase using phase listeners. I am new to this.
I am not sure If I clearly explained this in my earlier posts. When I select menuItem1, it sets the urlLink and reRenders the page. In that page, we have the back end bean that gets the data from the table. After this dataTable is displayed on the screen, I select menuItem2 using the menuoption and it sets the urlLink to the new .jsp page and reRenders the page. While coming out of menuItem1 and entering into menuItem2, the system executes the back end beans in menuItem1 program and menuItem2 program.
Can you please help me understand this on how to control with JSF life cycles?
Thanks
Aish -
5. Re: Bean executed twice - while calling and exiting the web
nbelaevski Feb 23, 2009 2:11 PM (in response to aish)Now it's much clear. Let's postpone phase listener development and try something simpler. Please try setting ajaxSingle="true" for menu items.
-
6. Re: Bean executed twice - while calling and exiting the web
aish Feb 24, 2009 7:41 AM (in response to aish)Hi,
Thanks for responding.
I tried that and still got the same results -that is the bean was executed during the entry and exit of the program. I also tried submittype="ajax" but still the same results.
Please let me know what else Ican try.
Thanks
Aish -
7. Re: Bean executed twice - while calling and exiting the web
nbelaevski Feb 24, 2009 11:21 AM (in response to aish)Aish,
You can try the workaround described here: https://jira.jboss.org/jira/browse/RF-3341. Set AJAX submission mode and check. -
8. Re: Bean executed twice - while calling and exiting the web
aish Mar 9, 2009 1:50 PM (in response to aish)Hi,
I tried the following two options and they didn't work. That is the bean is called during entry and exit of the program. Please let me know if what I tried is wrong
Thanks
Aish
Option 1
========
<a4j:keepAlive beanName="tabDetail" />
<rich:dataTable id="tabDetal_dTable"
value="#{tabDetail.displayTbl}" var="dbqueue" border="1"
width="670px" cellspacing="1" cellpadding="1" >
Option 2
========
<a4j:region renderRegionOnly="true">
<rich:dataTable id="tabDetal_dTable"
value="#{tabDetail.displayTbl}" var="dbqueue" border="1"
width="670px" cellspacing="1" cellpadding="1" >
</a4j:region> -
9. Re: Bean executed twice - while calling and exiting the web
nbelaevski Mar 9, 2009 2:36 PM (in response to aish)Hi Aish,
You should wrap "AJAXed" menu items into a4j:region. Unfortunately it's not clear whether menu items are inside the data table or not. -
10. Re: Bean executed twice - while calling and exiting the web
aish Mar 16, 2009 9:50 PM (in response to aish)Hi,
Please help me with this. I have tried a4j:region and it didn't help me. May be I missed something.
The problem I have is - I select a menu to display a web page which connects to backend database and displays the data using a rich:dataTable. Then I select a different menu to go a new web page. Here, the first program is called again which connects to the database and extracts the data and then, go to display the second web page.Basically,
the bean method of the first program is executed during the entry and exit of web page 1. Again, when I move from second web page to third web page, the bean method of second program is executed both during entry and exit of the program. This way bean method execution happens during the entry and exit of all program which impacts performance.
Could you please help me to resolve this situation. I am explaining below the way menu item is handled for your reference.
Please refer to the index.jsp page. I have the dropdown menu.jsp at the top of the page and just below the header. The dropdown.jsp is given for your reference. When a menu Item is selected, it sets the "link" variable in the navigate.java to the corresponding .jsp and that .jsp file is displayed in the outputPanel ('centergrid") defined on the index.jsp.
The beans are defined in 'session' scope.
Please let me know if you need additional information to help me.
Thanks
Aish
index.jsp
=======
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
default-menu
<f:view>
<h:form id="myForm">
This is is the header section with just html tags
<a4j:include viewId="/dropdownmenu.jsp" />
<h:panelGrid columns="3" style="width:775px">
<a4j:outputPanel id="centerGrid" >
<a4j:include viewId="#{navigate.address}">
</a4j:include>
</a4j:outputPanel>
</h:panelGrid>
This is the footer section
</h:form>
</f:view>
dropdownmenu.jsp
===============
<rich:toolBar width="775px">
<rich:dropDownMenu value="Section A">
<rich:menuItem value="System A" action="#{navigate.doSystemA}" id="dropdownmenu_mItem1" />
<rich:menuItem value="System B" action="#{navigate.doSystemB}" id="dropdownmenu_mItem2" />
</rich:dropDownMenu>
Navigate.java
===========
class navigate
{
private String link;
public void doSystemA()
{
link = "SystemA.jsp"
}
public void doSystemB()
{
link = "SystemB.jsp"
}
public String getAddress()
{
return urllink;
}
} -
11. Re: Bean executed twice - while calling and exiting the web
nbelaevski Mar 17, 2009 7:22 AM (in response to aish)Can you please post full page code containing a4j:region components?
-
12. Re: Bean executed twice - while calling and exiting the web
ilya_shaikovsky Mar 17, 2009 7:54 AM (in response to aish)Normal JSF behavior. You using dropDownMenu in mode server. So not ajax but standard post occurs. your menu and table in the same submitted form. So table called datamodel during decodes. And regions will not helps you as them works only during ajax requests.
You should define menu item as immediate. But be carefull if you need to submit some changes from the dataTable (for example if you will need the table to be editable) -
13. Re: Bean executed twice - while calling and exiting the web
aish Mar 17, 2009 11:14 AM (in response to aish)Hi,
Thanks for reviewing my post and passing on your suggestions.
1. As you have suggested, I tried using immediate="true" in my menuitem (my tables are not editable) and it didn't help. As usual, The bean was called twice - during the entry and exit of the program.
2. Then, I set the submitmode="ajax" and immediate="true". I noticed the same behaviour. The bean was called twice.
Please let me know what else I could change to make this work?
Also, I do have a menu implemented at the left side of the index page. This was implemented using panelMenuItem and panelmenugroup. (I have dropdown menu at the top of the page and this panel menu at the left hand side of the page.) I am enclosing the code of this panelmenu below for your reference. This panelmenu also behaves in the same way - bean getting called twice.
Please advise.
Thanks
Aish
panelMenu.jsp
==========
<rich:panelMenu id="mainMenu"
mode="ajax" iconExpandedGroup="disc" iconCollapsedGroup="disc"
iconExpandedTopGroup="chevronUp" iconGroupTopPosition="right"
iconCollapsedTopGroup="chevronDown" style="width:170px;background-color:#B0E0E6;border:thin solid blue"
expandSingle="true" styleClass="menustyle" >
<rich:panelMenuGroup label="Section A"
expanded="true" immediate="true" ignoreDupResponses="true" name="tables">
<rich:panelMenuItem label="System A" name="System A"
action="#{navigate.doSystemA}" reRender="centerGrid" styleClass="menustyle">
</rich:panelMenuItem>
<rich:panelMenuItem label="System B" name="System B"
action="#{navigate.doSystemB}"reRender="centerGrid" styleClass="menustyle">
</rich:panelMenuItem>
</rich:panelMenuGroup>
</rich:panelMenu> -
14. Re: Bean executed twice - while calling and exiting the web
nbelaevski Mar 17, 2009 6:45 PM (in response to aish)Enclose components that generate requests (e.g. that have "action" attribute in reference guide/tld) into a4j:region components. Data tables should not be included into regions. Check livedemo for "region" component to see how this works.