1 2 Previous Next 17 Replies Latest reply on Nov 19, 2007 4:53 PM by whafrog

    Dynamic widgets?

    whafrog

      What is the best way to deal with dynamic ajax creation of new widgets?

      I have a page where I need to track, say, lender benefits. One lender might offer 0.5% interest rate reduction after 12 on-time payments, another might offer 0.3% after the first 12 payments, and another 0.5% after 24. Ideally the lender could click a "+" button to add as many of that type of benefit as they like.

      I know how to do this in normal DHTML. In the old days I'd use javascript to dynamically generate the widget to display and a unique name on the form, and then process the request parameters on the server side, parsing the parameter names for the benefit type.

      But how do I do this in Seam? Any good tutorials out there that go beyond the basic one-to-one widget-datafield examples?

      TIA, Jon

        • 1. Re: Dynamic widgets?
          pmuir

          I would assume you have a backing list for the benefits. So, when you hit +, submit the form, add an item to the list, and rerender. You can use ajax if you don't want to submit the whole page. The seamdiscs example does it (without ajax) for adding band members.

          • 2. Re: Dynamic widgets?
            whafrog

            Yes, I had figured I could use a backing list, but I was hoping to avoid a form submission. I can use my old ajax and parameter processing code, I just wondered if there was a "Seam way" to do it. Thanks.

            • 3. Re: Dynamic widgets?
              pmuir

              That is the seam way ;)

              • 4. Re: Dynamic widgets?
                whafrog

                Thanks.

                I have a related question: is it possible to reference a Map of backing beans and lists? I haven't see any example of this. Using my example above, there is a master list of benefits, and each lender can have a varying subset of the master list. To reference the specific benefit, I'd like to be able to use the database name, rather than concoct some property name. It would also keep the Session Bean code tidier since the Map could be subclassed and self-initializing.

                Eg, in the Session bean ("benefitManager"):

                @In @Out
                private BenefitMap benefitTypes;


                In the page:

                <h:outputLabel for="name">Percent</h:outputLabel>
                <h:inputText value="#{benefitManager.benefitTypes.get('BENEFIT_TYPE_1').percent}"/>
                


                If there are examples of this I can look at please let me know.

                Thanks, Jon


                • 5. Re: Dynamic widgets?

                  JBoss EL should let you do that. If you're outjecting benefitTypes as shown, your EL expression would be "#{benefitTypes.get('BENEFIT_TYPE_1').percent}"; otherwise, if you were just had a getter called "getBenefitTypes" on BenefitManager, it'd be "#{benefitManager.benefitTypes.get('BENEFIT_TYPE_1').percent}"

                  Half the reason I love Seam so much is solely because of JBoss EL and its support for parameterized method invocations :)

                  • 6. Re: Dynamic widgets?

                    No doubt. If found that I hardly ever have to use @Datamodel and @DatamodelSelection anymore. And it rocks for nested datatables.

                    • 7. Re: Dynamic widgets?
                      whafrog

                       

                      "IGx89" wrote:
                      JBoss EL should let you do that. If you're outjecting benefitTypes as shown, your EL expression would be "#{benefitTypes.get('BENEFIT_TYPE_1').percent}"; otherwise, if you were just had a getter called "getBenefitTypes" on BenefitManager, it'd be "#{benefitManager.benefitTypes.get('BENEFIT_TYPE_1').percent}"

                      Half the reason I love Seam so much is solely because of JBoss EL and its support for parameterized method invocations :)


                      Thanks, what great news! I'm assuming I have to incorporate the EL libraries...


                      • 8. Re: Dynamic widgets?

                        Actually no, JBoss EL is bundled with Seam :)

                        • 9. Re: Dynamic widgets?
                          whafrog

                           

                          "IGx89" wrote:
                          Actually no, JBoss EL is bundled with Seam :)


                          I must be missing something though, as I'm getting an EL parsing exception using that format. I decided to use a getter, so the action class ("lenderbenefits") has:

                          private BenefitMap benefitMap = new BenefitMap();
                           public BenefitMap getBenefitMap() { return benefitMap; }


                          And the facelets page has:

                          <h:inputText value="#{lenderbenefits.benefitMap.getBenefit('ORIGINATION_FEE').percentReduction}" size="5"/>


                          BenefitMap has a getter:

                          private HashMap<String, LenderBenefit> benefits = new HashMap<String, LenderBenefit>();
                          public LenderBenefit getBenefit(String benefitName)
                          {
                           return benefits.get(benefitName);
                          }


                          And LenderBenefit has a property "percentReduction". But I get the following exception:

                          11:53:02,078 ERROR [STDERR] Nov 19, 2007 11:53:02 AM com.sun.facelets.FaceletViewHandler handleRenderException
                          SEVERE: Error Rendering View[/lenderbenefits.xhtml]
                          com.sun.facelets.tag.TagAttributeException: /lenderbenefits.xhtml @30,128 value="#{lenderbenefits.benefitMap.getBenefit('ORIGINATION_FEE').p
                          ercentReduction}" Error Parsing: #{lenderbenefits.benefitMap.getBenefit('ORIGINATION_FEE').percentReduction}
                           at com.sun.facelets.tag.TagAttribute.getValueExpression(TagAttribute.java:259)
                           at com.sun.facelets.tag.jsf.ValueHolderRule$DynamicValueExpressionMetadata.applyMetadata(ValueHolderRule.java:101)
                           at com.sun.facelets.tag.MetadataImpl.applyMetadata(MetadataImpl.java:36)
                           at com.sun.facelets.tag.MetaTagHandler.setAttributes(MetaTagHandler.java:62)
                           at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:144)
                           at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
                           at com.sun.facelets.tag.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
                           at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)
                           at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
                           at com.sun.facelets.tag.ui.DefineHandler.applyDefinition(DefineHandler.java:64)
                           at com.sun.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:128)
                           at com.sun.facelets.impl.DefaultFaceletContext$TemplateManager.apply(DefaultFaceletContext.java:306)
                           at com.sun.facelets.impl.DefaultFaceletContext.includeDefinition(DefaultFaceletContext.java:279)
                           at com.sun.facelets.tag.ui.InsertHandler.apply(InsertHandler.java:68)
                           at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
                           at com.sun.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:49)
                           at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
                           at com.sun.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:25)
                           at com.sun.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:248)
                           at com.sun.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:294)
                           at com.sun.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:273)
                           at com.sun.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:143)
                           at com.sun.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:113)
                           at com.sun.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:49)
                           at com.sun.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:25)
                           at com.sun.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:95)
                           at com.sun.facelets.FaceletViewHandler.buildView(FaceletViewHandler.java:503)
                           at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:546)
                           at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
                           at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
                           at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
                           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
                           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                           at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:63)
                           at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:60)
                           at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
                           at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
                           at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
                           at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:57)
                           at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
                           at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:79)
                           at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
                           at org.jboss.seam.web.SeamFilter.doFilter(SeamFilter.java:84)
                           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                           at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                           at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
                           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
                           at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
                           at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
                           at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
                           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
                           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
                           at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
                           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
                           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
                           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
                           at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
                           at java.lang.Thread.run(Thread.java:595)
                          Caused by: javax.el.ELException: Error Parsing: #{lenderbenefits.benefitMap.getBenefit('ORIGINATION_FEE').percentReduction}
                           at org.apache.el.lang.ExpressionBuilder.createNodeInternal(ExpressionBuilder.java:125)
                           at org.apache.el.lang.ExpressionBuilder.build(ExpressionBuilder.java:146)
                           at org.apache.el.lang.ExpressionBuilder.createValueExpression(ExpressionBuilder.java:190)
                           at org.apache.el.ExpressionFactoryImpl.createValueExpression(ExpressionFactoryImpl.java:68)
                           at org.jboss.seam.ui.facelet.SeamExpressionFactory.createValueExpression(SeamExpressionFactory.java:107)
                           at com.sun.facelets.tag.TagAttribute.getValueExpression(TagAttribute.java:256)
                           ... 62 more
                          Caused by: org.apache.el.parser.ParseException: Encountered "(" at line 1, column 39.
                          Was expecting one of:
                           "}" ...
                           "." ...
                           "[" ...
                           ">" ...
                           "gt" ...
                           "<" ...
                           "lt" ...
                           ">=" ...
                           "ge" ...
                           "<=" ...
                           "le" ...
                           "==" ...
                           "eq" ...
                           "!=" ...
                           "ne" ...
                           "&&" ...
                           "and" ...
                           "||" ...
                           "or" ...
                           "*" ...
                           "+" ...
                           "-" ...
                           "?" ...
                           "/" ...
                           "div" ...
                           "%" ...
                           "mod" ...


                          Am I missing any libraries?

                          Thanks for your help so far!


                          • 10. Re: Dynamic widgets?
                            whafrog

                            I should have mentioned: JBoss 4.2.0GA, Seam 1.2.1GA. If this is a 2.0 feature... :-( not sure the boss will let me upgrade just yet.

                            • 11. Re: Dynamic widgets?

                              Ahh, sorry, yeah, it's a 2.0 feature :(

                              • 12. Re: Dynamic widgets?
                                whafrog

                                So, just assuming the Boss DID let me upgrade, any known issues with using 4.2.0GA, or do I have to upgrade that too? I'm pretty sure THAT one's out of the question...

                                • 13. Re: Dynamic widgets?

                                  I would go with 4.2.2 because is has some EJB and other fixes. It will probably be easier to go from 4.2.0 to 4.2.2 than from 1.2.1 to 2.0 anyway.

                                  • 14. Re: Dynamic widgets?
                                    whafrog

                                    We already have other applications deployed using 4.2.0, but this will be our first Seam app, so probably best to upgrade that now. Thanks for your help!

                                    1 2 Previous Next