1 2 Previous Next 17 Replies Latest reply: Jan 12, 2011 1:07 PM by Ilya Sorokoumov RSS

Full usage of ComboBox

Olalekan Ogunleye Newbie

Hi All,

 

I was wondering if someone can just help me out on this and or explain to me how and what to do on it. OK this is the thing:

 

I want to use a comboBox. My comboBox has been prepopulated from the table. However, when a user selects an option from the combox I want to be able to render a different form basedon the user selection.

 

Therefore, I will like to ask if someone can direct me to any example on this or someone can show me a skeleton way of doing this.

 

Thank you for your anticipated and positive response

  • 1. Re: Full usage of ComboBox
    Ilya Sorokoumov Master

    So you want a user to select one of comboBox items and then show him some specific form based on the selected item. Does user have to press a button to submit his choise? If so you can use a4j:include & ajax navigation in order to reRender page partialy. Does it fit for you?

  • 2. Re: Full usage of ComboBox
    Olalekan Ogunleye Newbie

    Thank you for your response Ilya. However, The user does not need to press the button after selecting the button. The moment the user selects his choice the form is displayed and after filling the form that is being displayed then he can press a submit button to submit the form. Any direction? Thank you

  • 3. Re: Full usage of ComboBox
    Ilya Sorokoumov Master

    1. use a4j support like in http://docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/a4j_support.html

    2. add your forms into a wrapper like the following

    <h:panelGroup id="wrap">

         <h:form id="form1" rendered="#{el1}"/>

         <h:form id="form2" rendered="#{el2}"/>

    </h:panelGroup>

    3. reRender wrap element on change event

     

    WARN: #{elX} must still be true when a user sumbits formX otherwice JSF ignores a submit of formX

  • 4. Re: Full usage of ComboBox
    Ilya Sorokoumov Master

    This article http://community.jboss.org/wiki/CommonAjaxRequestsProblems could be very usefull for you

  • 5. Re: Full usage of ComboBox
    Olalekan Ogunleye Newbie

    Hi,

     

    I am still having problem implementing this. Can someone please show me an example of how this has been done before or send me the link may be this could be useful. Thank you

  • 6. Re: Full usage of ComboBox
    Ilya Sorokoumov Master

    Could you post code(jsf page + bean) which you have now and then I can try to help you.

  • 7. Re: Full usage of ComboBox
    Olalekan Ogunleye Newbie

    Ilya Sorokoumov wrote:

     

    Could you post code(jsf page + bean) which you have now and then I can try to help you.

    Please find attached the codes (JSF only) for the app. The main page is service configuration and what I am planing to do is that I want the content of the other pages be shown in service configuration depending on what a user selects from the comboBox in serviceConfiguration. Thanks for your help.

  • 8. Re: Full usage of ComboBox
    Ilya Sorokoumov Master

    I guess that you can do it in the following way:

    1) add valueChangeListener to comboBox in order to handle a selection event

    2) use ui:include into your rich:panel where you want to have different content

    3) use attribute src of ui:include like this src="#{yourBean.somePath}". somePath should be changed in your valueChangeListener when user selects some option in comboBox.

    4) You should reRender your rich:panel when comboBox value is changed

     

    P.S. if ui:include won't work try a4j:include instead. But try ui:include before a4j because there may be some another issues with a4j:include.

    P.S.S. Let me know about how it goes

     

    Regards,

    Ilya.

  • 9. Re: Full usage of ComboBox
    Olalekan Ogunleye Newbie

    Hi llya,

     

    I have followed the step you advised that I should follow but all to no avail. I went as far as tried different solution of the same way but still I can only get my comboBox to fetch the value but cannot display the pages as I want. I have therefore, attached my code to help see what I am doing wrong. I will be much grateful if anyone can tell me what I am doing wrong.

     

    Attach is my codes. The (needed1 and needed2).txt are the backups of various BB codes that I used before I used tha ValuchangedBean.Java.

     

    Someone please help.

  • 10. Re: Full usage of ComboBox
    Ilya Sorokoumov Master

    Hi Olalekan,

    I looked into your code and I have several suggestions for you:

    1) Do not use/try something if you are not sure that it's possible. Try to use code from demos/blog posts etc. but do not combine them because you will never find a mistake especially if there are a lot of them in your code at the same time.

    2) Try to debug your code by using all possible mechanisms (System.out.println, rich:messages, look at server log files, firebug etc.)

    3) Revise your knowledge about JSF. Read articles about actions/listeners/validators etc.

    4) If you are using some RF component make sure that you understand how it works. Look at RF online documentaion / demo for the details.

    5) A solving of every complicated issue consists of solving several smaller issues. Try to split your problem to pieces .

    My solution follows below and it works fine

    package test;

    import java.io.Serializable;

    public class TestBean implements Serializable {

      private static final long serialVersionUID = 1L;

      private String state = "";

      public void valueChangeListener(javax.faces.event.ValueChangeEvent e) {

                        state = (String) e.getNewValue();

              }

              public void setState(String state) {

                        this.state = state;

              }

      public String getState() {

                        return state;

              }

    }

    faces-config.xml:

    <managed-bean>

      <managed-bean-name>testBean</managed-bean-name>

      <managed-bean-class>test.TestBean</managed-bean-class>

      <managed-bean-scope>request</managed-bean-scope>

      </managed-bean>

     

    xhtml page:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.og/TR/xhtml1/DTD/xhtml-transitionl.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml"

          xmlns:h="http://java.sun.com/jsf/html"

          xmlns:f="http://java.sun.com/jsf/core"

          xmlns:ui="http://java.sun.com/jsf/facelets"

          xmlns:a4j="http://richfaces.org/a4j"

          xmlns:rich="http://richfaces.org/rich">

     

     

    <head>

              <title>Test</title>

    </head>

     

     

    <body>

              <a4j:keepAlive beanName="testBean"></a4j:keepAlive>

     

     

              <h:form>

                        <rich:comboBox value="#{testBean.state}" valueChangeListener="#{testBean.valueChangeListener}">

                                            <f:selectItem itemValue=""/>

                                <f:selectItem itemValue="1"/>  

                                <f:selectItem itemValue="2"/>

                                <f:selectItem itemValue="3"/>

                                <a4j:support event="onchange" reRender="wrap1,wrap2,wrap3"/>

                        </rich:comboBox>

              </h:form>

     

     

              <h:panelGroup id="wrap1">

                        <h:panelGroup rendered="#{testBean.state == '1'}">

                                  11111111111

                        </h:panelGroup>

              </h:panelGroup>

              <h:panelGroup id="wrap2">

                        <h:panelGroup rendered="#{testBean.state == '2'}">

                                  22222222222

                        </h:panelGroup>

              </h:panelGroup>

              <h:panelGroup id="wrap3">

                        <h:panelGroup rendered="#{testBean.state == '3'}">

                                  33333333333

                        </h:panelGroup>

              </h:panelGroup>

     

     

    </body>

    </html>

    Regards,

    Ilya.


  • 11. Re: Full usage of ComboBox
    Olalekan Ogunleye Newbie

    Thanks a lot for your help and the detailed advice Ilya. However, I must say that it is difficult to implement the solution that you have advised. The reason being the fact that anytime I edit the faces-config.xml. My JBoss starts running in a loop and it will not allow my apps to be deployed on the server. I have had this problem with pages.xml before and till this moment I have not known the reason why this has to be so. Then what I did was to go inside pages.xml after shutting down eclipse and edit it. I did the same to faces-config.xml and it is not working out for me. I guess that is one of the price one has to pay for using open source system. Any idea as to how to go around this?

     

    Regards

  • 12. Re: Full usage of ComboBox
    Ilya Sorokoumov Master

    I'm not an expert in Seam so can't tell you a lot. Do you need to define you beans in faces-config.xml if you can use @Name? I just showed my implementation and it works on Jboss 5.1/JSF1.2/Facelets 1.1.15-B1/RichFaces 3.3.3Final. If you use another environment you should adapt my solution to it. May be you should write about your problem(with Jboss & Eclipse) on some other forums(Jboss server/Eclipse etc.). B.T.W what environment are you using?

  • 13. Re: Full usage of ComboBox
    Olalekan Ogunleye Newbie

    I am using Eclipse/JBoss and I am solely developing seam apps. However, I do not need to define my beans in faces-config.xml if I can use at name but I think I should first implement it the way it is before I start making changes. Thank you

  • 14. Re: Full usage of ComboBox
    Olalekan Ogunleye Newbie

    Hi Ilya,

     

    Thank you for your prompt help. I have re looked at the code but I found out that the form can only be displayed with the h:selectOneMenu as oppose to rich:comboBox. Thus far it is work but the problem that I am having now is that my webform that I want to display is not display. But when I change the value in the selectOneMenu, it fires the 11111, 22222, 33333 but it does not display my form and what I get is "WARNING [renderkit] 'for' attribute cannot be null" from my JBoss console. Can you or anyone tell me what I am doing wrong? Please see attached my code.

     

    serviceConfiguration.xhtml is the main body and the rest *.xhtml are the forms that I want to rendere.

     

    Thank you

1 2 Previous Next