-
1. Re: self-rerendering regions
joe.marques Feb 9, 2009 10:53 PM (in response to joe.marques)FYI, I made a typo when simplifying my code for purposes of this post. Obviously, "ResourceUIBean" should just be "Bean".
-
2. Re: self-rerendering regions
sergeysmirnov Feb 10, 2009 1:09 AM (in response to joe.marques)Your first code should work also if ResourceUIBean scope is longer than request. I hope it is longer in your code. Are you sure you did not "simplify" something important?
-
3. Re: self-rerendering regions
joe.marques Feb 10, 2009 9:10 AM (in response to joe.marques)I moved the Bean to session scope, it still fails in exactly the same way -- the page rendered, I click the image the first time and it toggles successfully, I click the image again and it does nothing. I have an a4j:status tag on the page, so I know some request is being sent. Breakpoints in the Bean tell me the isState() method is still being called, but the toggleState() method is not.
-
4. Re: self-rerendering regions
ilya_shaikovsky Feb 10, 2009 9:15 AM (in response to joe.marques)please post non-simplified code.
-
5. Re: self-rerendering regions
joe.marques Feb 10, 2009 9:43 AM (in response to joe.marques)facelet:
<h:panelGroup> <a4j:outputPanel id="favoritesPanel"> <a4j:form id="favoritesForm"> <a4j:commandButton id="favoritesButton" reRender="favoritesPanel" status="commonStatus" image="#{FavoritesUIBean.favorite ? '/images/star_on_24.png' : '/images/star_off_24.png'}" action="#{FavoritesUIBean.toggleFavorite}"> <f:param name="id" value="#{FavoritesUIBean.id}"/> </a4j:commandButton> <rich:toolTip for="favoritesPanel"> <h:outputText value="Add resource to favorites list" rendered="#{!FavoritesUIBean.favorite}"/> <h:outputText value="Remove resource from favorites list" rendered="#{FavoritesUIBean.favorite}"/> </rich:toolTip> </a4j:form> </a4j:outputPanel> </h:panelGroup>
managed bean:public class FavoritesUIBean { private int id; public boolean isFavorite() { id = WebUtility.getResourceId(FacesContextUtility.getRequest()); return QuickFavoritesUtil.determineIfFavoriteResource(FacesContextUtility.getRequest()); } public int getId() { return id; } public String toggleFavorite() { WebUser user = EnterpriseFacesContextUtility.getWebUser(); WebUserPreferences preferences = user.getWebPreferences(); WebUserPreferences.FavoriteResourcePortletPreferences favoriteResourcePreferences = preferences .getFavoriteResourcePortletPreferences(); int resourceId = WebUtility.getResourceId(FacesContextUtility.getRequest()); boolean isFav = favoriteResourcePreferences.isFavorite(resourceId); if (isFav) { favoriteResourcePreferences.removeFavorite(resourceId); } else { favoriteResourcePreferences.addFavorite(resourceId); } preferences.setFavoriteResourcePortletPreferences(favoriteResourcePreferences); preferences.persistPreferences(); return null; } }
-
6. Re: self-rerendering regions
joe.marques Feb 11, 2009 12:13 PM (in response to joe.marques)the bulk of the non-simplified code is posted. anything else you need from me. has this been reproduced on your end?
-
7. Re: self-rerendering regions
sergeysmirnov Feb 11, 2009 4:16 PM (in response to joe.marques)There is no problem with self-rerendering region for sure. I created the sample application based on your fist "simplify" code and it worked perfect. Of course, the been has no so complicated. Just getter, setter and toggle.
So, I suggest the problem is in your java code.
What I have working is:.... <f:view> <a4j:outputPanel id="statePanel"> <a4j:form id="stateForm"> <a4j:commandButton id="stateButton" reRender="statePanel" image="#{resourceUIBean.state ? '/turnOff.png' : '/turnOn.png'}" action="#{resourceUIBean.toggleState}"> </a4j:commandButton> <h:outputText value="State On" rendered="#{resourceUIBean.state}"/> <h:outputText value="State Off" rendered="#{!resourceUIBean.state}"/> </a4j:form> </a4j:outputPanel> </f:view>
<managed-bean> <managed-bean-name>resourceUIBean</managed-bean-name> <managed-bean-class>org.richfaces.ResourceUIBean</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean>
package org.richfaces; /** * @author $Autor$ * */ public class ResourceUIBean { public boolean state = false; public void toggleState() { this.state = !this.state; System.out.println("It is toogled to "+ this.state); } public void setState(boolean state) { this.state = state; } public boolean getState() { return this.state; } public boolean isState() { return this.state; } }
-
8. Re: self-rerendering regions
joe.marques Feb 13, 2009 12:42 AM (in response to joe.marques)ok, i finally got it. as it turns out, the a4j:form i had in the example code was nested inside some other h:form, which for some reason only made the first toggle work. as soon as i moved the a4j:form alongside the h:form, things started working. thanks for your time and the complete example. it helped me debug and resolve my issue.