8 Replies Latest reply on Mar 4, 2009 2:16 PM by icampista

    Custom component: Multiple values (with JBoss Seam)

      Hi!

      We're trying to create a custom RichFace. The UI for it should present several elements.
      We managed to have the values set and read by the RichFace itself. But we're not sure about how to communicate with Seam's page description file.

      I picture something like this:
      <hno:inputTNM id="tnm" valueT="#{backingBean.T}" valueN="#{backingBean.N}" ... />

      Two problems:
      1) How would I get those custom attributes?
      2) Does it help me at all? IOW: Would the injection of a HTTP-parameter from an existing bean into the component work at all (.page.xml file)

      <param name="tnm" value="#{backingBean.???}"

      I am stuck. Any pointers are appreciated,
      Stefan

        • 1. Re: Custom component: Multiple values (with JBoss Seam)
          nbelaevski

          1) What is hno:inputTNM - Facelets template, self-written component? Also please post some more information about "getting those attributes": all attributes are available through component getters and setters. How did you try to get them?

          2) I think this should work ok. You can try with the simpler component like h:outputText if you're not sure whether your component is functioning well.

          • 2. Re: Custom component: Multiple values (with JBoss Seam)

             

            "nbelaevski" wrote:
            1) What is hno:inputTNM - Facelets template, self-written component? Also please post some more information about "getting those attributes": all attributes are available through component getters and setters. How did you try to get them?


            Yes, it's a self written component. We are completely new to JBoss, seam and RichFaces. We used the CDK guide and the inputDate example there as guide for the component. The difference between the TNM component and the inputDate component is, roughly, that the TNM component shall offer three edit fields <input type="text" ...> each of them holding a value.

            I can't post code right now, as we developed it on another PC at another location. But I'll gladly post when I get a hold of the files again, if needed.


            2) I think this should work ok. You can try with the simpler component like h:outputText if you're not sure whether your component is functioning well.


            Passing only one text from one input field works well. We're having problems understanding where or how to pass more than one piece of data from the RichFace to the application.

            Stefan
            p.s.: Sorry for not disabling HTML in my original post


            • 3. Re: Custom component: Multiple values (with JBoss Seam)
              nbelaevski

              You should write code to update several fields manually, e.g.: http://fisheye.jboss.org/browse/RichFaces/trunk/ui/listShuttle/src/main/java/org/richfaces/component/UIListShuttle.java?r=12261 - updateModel(FacesContext context) method. Superclass method is here:
              http://fisheye.jboss.org/browse/RichFaces/trunk/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingBaseComponent.java?r=12319 - updateModel(FacesContext context, UpdateModelCommand command)

              • 4. Re: Custom component: Multiple values (with JBoss Seam)

                 

                "nbelaevski" wrote:
                You should write code to update several fields manually, [...]


                Thanks for those pointers. [...]
                So if I understand it correctly, the component has attributes activeItem, sourceSelection, ... that can be used in the Seam page like <ns:listShuttle activeItem="#{someBean.active}" sourceSelection="#{someBean.source}" ... />?

                If so, I think I get the idea.

                Another question: Would it be "cleaner" to implement multiple values in one class so that our component looked like:
                <hno:inputTNM value="#{someBean.aggregatedTNM}" ...>
                where aggregatedTNM would be a class containing the T, N and M value.

                Then we'd have to use a converter to somehow mangle the values into a HTTP parameter and back into a class. Right?

                Thanks for your help,
                Stefan

                • 5. Re: Custom component: Multiple values (with JBoss Seam)
                  nbelaevski

                   

                  "looseleaf" wrote:
                  "nbelaevski" wrote:
                  You should write code to update several fields manually, [...]


                  Thanks for those pointers. [...]
                  So if I understand it correctly, the component has attributes activeItem, sourceSelection, ... that can be used in the Seam page like <ns:listShuttle activeItem="#{someBean.active}" sourceSelection="#{someBean.source}" ... />?

                  Yes, you are right. I can also say that this can be used either with Seam or without it - these attributes are just standard JSF attributes and have no special handling in Seam.

                  "looseleaf" wrote:
                  Another question: Would it be "cleaner" to implement multiple values in one class so that our component looked like:
                  <hno:inputTNM value="#{someBean.aggregatedTNM}" ...>
                  where aggregatedTNM would be a class containing the T, N and M value.
                  Yes, this will be a "cleaner" approach (in the sense that you can reuse existing code), however sometimes business requirements may be satisfied only by introduction of several attributes. Choose the approach you like more.

                  "looseleaf" wrote:
                  Then we'd have to use a converter to somehow mangle the values into a HTTP parameter and back into a class. Right?
                  Processing incoming HTTP parameters is usually done by renderer class (in decode method they're read from request and in encode* methods they're output back to the client as form fields being submitted by the sequential request).


                  • 6. Re: Custom component: Multiple values (with JBoss Seam)
                    nbelaevski

                    You can read this for more information on how JSF components work: http://books.google.com/books?id=Iv9r-CT6ZwwC&printsec=frontcover&dq=ajax+jsf#PPP1,M1

                    • 7. Re: Custom component: Multiple values (with JBoss Seam)

                      Thanks for your elaborations, I really appreciate them.

                      Coming from a completely different field of software development, starting with JBoss Seam means being confronted with a *lot* of new frameworks and architecture, where it's easy to lose orientation.

                      Thanks again!
                      Stefan

                      • 8. Re: Custom component: Multiple values (with JBoss Seam)
                        icampista


                        I'm having the same difficulty. But I kinda understood now.

                        Actually a small correction to the links:

                        The superclass is UIInput. The code is coming in my case from MyFaces core implementation.

                        With this code below it means that only the value attr is updated. (WHAT WE DONT WANT), so now is just to overwrite it in you component java class. (usually the class that extends UIInput)


                        public void updateModel(FacesContext context)
                        {
                        if (!isValid())
                        {
                        return;
                        }
                        if (!isLocalValueSet())
                        {
                        return;
                        }
                        ValueExpression expression = getValueExpression("value");
                        if (expression == null)
                        {
                        return;
                        }

                        try
                        {
                        expression.setValue(context.getELContext(), getLocalValue());
                        setValue(null);
                        setLocalValueSet(false);
                        }
                        catch (Exception e)
                        {
                        context.getExternalContext().log(e.getMessage(), e);
                        _MessageUtils.addErrorMessage(context, this, UPDATE_MESSAGE_ID,
                        new Object[]
                        { _MessageUtils.getLabel(context, this) });
                        setValid(false);

                        /*
                        * we are not allowed to throw exceptions here - we still need the
                        * full stack-trace later on to process it later in our
                        * error-handler
                        */
                        queueExceptionInRequest(context, expression, e);
                        }
                        }



                        Cheers,
                        Igor