1 2 Previous Next 19 Replies Latest reply on Apr 3, 2008 2:15 PM by ayanul Go to original post
      • 15. Re: simple things wont work - toggle panel again
        moldovan

        Hy marinew!

        Following workaround can help you. Maybe it is not the best way, but for sure the shortest:

        Only set the selected value, if it is not null.

        So your set()-method will look something like this:

        public void setSelectedCountry(String selectedCountry) {
         if(selectedCountry != null)
         this.selectedCountry = selectedCountry;
        }


        I'm currently using this workaround in my webapp, but I'm still waiting for an bugfix. Seems that in Version 3.2.0.GA the "null value" - problem also exists!


        • 16. Re: simple things wont work - toggle panel again
          ilya_shaikovsky

          sorry for loosing your post.

          please in order to get current info please repost the problems which not solved in 3.2.0 GA or just open concrete isuues in jira

          • 17. Re: simple things wont work - toggle panel again
            moldovan

            Hello ilya!

            Concrete Description about the problem:
            in my page i have a SimpleTogglePanel defined, which contains a selectOneMenu inside.

            Select a value from the selectOneMenu, and close the SimpleTogglePanel - you wil see that the set-method of the "selected-value" is getting called and your selection will be stored in these selected-value.
            When you reopen the SimpleTogglePanel, you see that the set-method is called (why, I'm not sure) and "null" will be set to the selected-value. After this call of the set-method the expected call of the get-method is working - but in cause of the last set-call with null - and null will be returned.
            And because null will not be found in the list of selectItems from the selectOneMenu, the first selectItem will be selected.

            Simplified:
            selectOneMenu with following list: Austria, Germany, Slovakia, Croatia
            1.) select slovakia
            2.) then close the SimpleTogglePanel
            3.) reopen the SimpleTogglePanel
            4.) and you will see austria as selected value (because you lost your selection in step 3!)

            You can reproduce it with folowing code:

            The JSP:

            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
             "http://www.w3.org/TR/html4/loose.dtd">
            <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
            <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
            <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
            <%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t" %>
            <%@ taglib uri="http://myfaces.apache.org/sandbox" prefix="s" %>
            <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
            <%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
            
            <f:view>
             <t:document>
             <t:documentHead>
             <title>Test the SimpleTogglePanel</title>
             </t:documentHead>
             <t:documentBody>
             <a4j:region id="siteregion">
             <t:div style="width: 100%;">
             <t:div style="margin-right: auto; margin-left: auto; text-align: center;">
             <a4j:status id="statuscomponent" for="siteregion">
             <f:facet name="start">
             <h:graphicImage value="images/connect_active.gif" />
             </f:facet>
             <f:facet name="stop">
             <h:graphicImage value="images/connect_idle.gif" />
             </f:facet>
             </a4j:status>
             </t:div>
             </t:div>
             <a4j:form ajaxSubmit="true" >
             <t:div id="mydiv" style="margin-top: 50px;" >
            
             <rich:simpleTogglePanel label="Klicken zum öffnen/schließen" width="500" height="300" switchType="ajax" reRender="mydiv">
             <h:outputText value="Bitte selektieren Sie ihr Land: "/>
             <h:selectOneMenu value="#{countries.selectedCountry}" >
             <f:selectItems value="#{countries.countryNames}" />
             </h:selectOneMenu>
             <rich:spacer style="display: block;" height="20" />
            
             <%--
             <h:outputText value="Wenn sie noch ein Land hinzufügen wollen, geben Sie es hier ein: " />
             <h:inputText value="#{countries.inputCountry}" />
             <a4j:commandButton value="hinzufügen" action="#{countries.addCountry}" status="statuscomponent" />
             --%>
            
             </rich:simpleTogglePanel>
            
             <t:div style="margin-top: 15px; font-size: 8pt; font-family: verdana, arial;" >
             <h:outputText value="gewähltes Land: "/>
             <h:outputText id="outputselectedcountry" value="#{countries.selectedCountry}" />
             </t:div>
            
             <t:div style="margin-top: 15px; font-size: 8pt; font-family: verdana, arial;">
             <h:outputText value="Klicke folgenden Link für ein Ajax-Site-Refresh --> "/>
             <a4j:commandLink value="refresh site via ajax" status="statuscomponent" reRender="mydiv" />
             </t:div>
            
             </t:div>
             </a4j:form>
             <a4j:log popup="false" level="INFO" />
             </a4j:region>
             </t:documentBody>
             </t:document>
            </f:view>
            


            The Bean:
            package net.wimaxxed.ajaxwebapp.webapp.bean;
            
            import javax.faces.model.SelectItem;
            
            import org.apache.commons.logging.Log;
            import org.apache.commons.logging.LogFactory;
            
            import java.util.ArrayList;
            import java.util.List;
            
            public class Countries
            {
             private List countryNames;
             private String selectedCountry;
             private String inputCountry;
            
             private static final Log log = LogFactory.getLog(Countries.class);
            
             public Countries()
             {
             countryNames = new ArrayList();
             countryNames.add(new SelectItem("Austria"));
             countryNames.add(new SelectItem("Slovakia"));
             countryNames.add(new SelectItem("Croatia"));
             countryNames.add(new SelectItem("Germany"));
            
             selectedCountry = "Croatia";
             }
            
             /*
             public String addCountry()
             {
             countryNames.add(new SelectItem(inputCountry));
             return null;
             }
             */
            
             public List getCountryNames() {
             return countryNames;
             }
            
             public void setCountryNames(List countryNames) {
             this.countryNames = countryNames;
             }
            
             public String getSelectedCountry() {
             log.info("getMethod() - selectedCountry _> "+selectedCountry);
             return selectedCountry;
             }
            
             public void setSelectedCountry(String selectedCountry) {
             log.info("setMethod() - selectedCountry _> "+selectedCountry);
             this.selectedCountry = selectedCountry;
             }
            
             public String getInputCountry() {
             return inputCountry;
             }
            
             public void setInputCountry(String inputCountry) {
             this.inputCountry = inputCountry;
             }
            }
            


            Hope this helps to reproduce my problem.

            Cheers moldovan!

            • 18. Re: simple things wont work - toggle panel again
              marinew

              Thanks a lot, Moldovan !!

              Your tip works fine for me.
              Thanks again.

              • 19. Re: simple things wont work - toggle panel again
                ayanul
                1 2 Previous Next