Re: T5: conditional parameter binding or something
I'm not sure I understood it completely, so first I'll how I see it from your description. You have a list of items to display, you have maxItems to display per page, you only want to show some items based on their state. Your division of responsibilities is putting too much into one place and causing problems. I'm not a MVC freak, but I belive you can apply it here to avoid the problems above, your data is list of facets. you skiiped model part and put data directly into view... add a model that will be aware of the data and return count by counting only facets that should be displayed. model when asked for items should return only those that are visible, this way your View component can handle paging without being aware of the filter applied to the data. Davor Hrg On Dec 4, 2007 6:42 PM, Britske [EMAIL PROTECTED] wrote: I quickly solved it with some kind of hack for those interested, but I'm still curious if the kind of binding I described is possible at all. Cheers, Geert-Jan A hack that's working: introduced 2 extra fields: facetmaxInc and FacetOld; public void setFacetCounter(int facetCounter) { this.facetCounter = facetCounter; if(facet!=null facet.equals(facetold)) { facetMaxInc = facetMax; facetold = facet; } if(facet!=null facet.getFacet().isSelected()) { facetMaxInc++; } } and check on facetMaxInc. Britske wrote: I need a bit of introduction to lay down the problem, so please bare with me: I have a component which renders lists of items. A parameter (childcounter) keeps track of the number of rendered items in the current List. I have the requirement. to be able to define on a per-page basis how many items are rendered at max. I implemented this by simply binding childcounter param and checking it against a field (say: maxitems) on the page. Depending on that I can decide on a per-page basis what to do with items that exceed the maxitems-threshold. (render different blocks, etc) So far so good. Currenly Im using this component to render facets (http://en.wikipedia.org/wiki/Faceted_classification) as part of a navigation menu. The requirement is to (for each list) render all SELECTED facets first and then render x (say 5) UNSELECTED facets per list, where x is defined by maxitems. The problem: the component doesn't know (and shouldnt know) that it is rendering facets. So it doens't know if a facet is selected or unselected. Based on that the childcounter is incremented each time a selected or unselected facet is rendered, and the maxitem-treshold is reached when 5 facets per group are rendered (independent whether they are selected or unselected). Obviously thats not what I want. The solution (so I thought) 1. The component doens't know that it's rendering facets, but the page knows. Moreover, the component outputs the item that it is currently rendering. (the facet in this case). 2. the param childcounter of the component is bound to the page field 'facetCounter' since as I understand it a param-binding is bi-directional I did the following: Page: -- @Component(parameters = {result=facetdsText, row=gGroup,childrow=facet,ulClass=literal:facets, childcounter=facetcounter}) private CompositeFlexLi facetBlock; public void setFacetCounter(int facetCounter) { if(facet==null || !facet.getFacet().isSelected()) { this.facetCounter = facetCounter; } } What it does is obvious: 1. the component renders and updates childcounter, which in effect calls setFacetCounter(int facetCounter), since its bound to facetCounter. 2. facetCounter is only updated when the current item is a UNSELECTED facet (which it knows in contrast to the component) The actual problem now is that facetCounter indeed is only updated when a facet is unselected, but the parameter 'childcounter' is still updated, although it is bound to the field facetCounter which is not updated (they aren't in sync). The behavior now is the following: (say i have 2 selected facets) childcounter: 1,2,3,4,5 facetfield: 0,0,3,4,5 while i figured it would be: childcounter: 0,0,1,2,3,4,5 facetfield: 0,0,1,2,3,4,5 Was I expecting to much 'binding-magic' to happen here, or am I missing something? If not, what would be your suggestion to tackle this issue? (making the component aware that its rendering facets is as I explained no option) Thanks in advance, Geert-Jan -- View this message in context: http://www.nabble.com/T5%3A-%22conditional-parameter-binding%22-or-something-tf4944458.html#a14155609 Sent from the Tapestry - User mailing list archive at Nabble.com.
T5: conditional parameter binding or something
I need a bit of introduction to lay down the problem, so please bare with me: I have a component which renders lists of items. A parameter (childcounter) keeps track of the number of rendered items in the current List. I have the requirement. to be able to define on a per-page basis how many items are rendered at max. I implemented this by simply binding childcounter param and checking it against a field (say: maxitems) on the page. Depending on that I can decide on a per-page basis what to do with items that exceed the maxitems-threshold. (render different blocks, etc) So far so good. Currenly Im using this component to render facets (http://en.wikipedia.org/wiki/Faceted_classification) as part of a navigation menu. The requirement is to (for each list) render all SELECTED facets first and then render x (say 5) UNSELECTED facets per list, where x is defined by maxitems. The problem: the component doesn't know (and shouldnt know) that it is rendering facets. So it doens't know if a facet is selected or unselected. Based on that the childcounter is incremented each time a selected or unselected facet is rendered, and the maxitem-treshold is reached when 5 facets per group are rendered (independent whether they are selected or unselected). Obviously thats not what I want. The solution (so I thought) 1. The component doens't know that it's rendering facets, but the page knows. Moreover, the component outputs the item that it is currently rendering. (the facet in this case). 2. the param childcounter of the component is bound to the page field 'facetCounter' since as I understand it a param-binding is bi-directional I did the following: Page: -- @Component(parameters = {result=facetdsText, row=gGroup,childrow=facet,ulClass=literal:facets, childcounter=facetcounter}) private CompositeFlexLi facetBlock; public void setFacetCounter(int facetCounter) { if(facet==null || !facet.getFacet().isSelected()) { this.facetCounter = facetCounter; } } What it does is obvious: 1. the component renders and updates childcounter, which in effect calls setFacetCounter(int facetCounter), since its bound to facetCounter. 2. facetCounter is only updated when the current item is a UNSELECTED facet (which it knows in contrast to the component) The actual problem now is that facetCounter indeed is only updated when a facet is unselected, but the parameter 'childcounter' is still updated, although it is bound to the field facetCounter which is not updated (they aren't in sync). The behavior now is the following: (say i have 2 selected facets) childcounter: 1,2,3,4,5 facetfield: 0,0,3,4,5 while i figured it would be: childcounter: 0,0,1,2,3,4,5 facetfield: 0,0,1,2,3,4,5 Was I expecting to much 'binding-magic' to happen here, or am I missing something? If not, what would be your suggestion to tackle this issue? (making the component aware that its rendering facets is as I explained no option) Thanks in advance, Geert-Jan -- View this message in context: http://www.nabble.com/T5%3A-%22conditional-parameter-binding%22-or-something-tf4944458.html#a14155127 Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: T5: conditional parameter binding or something
I quickly solved it with some kind of hack for those interested, but I'm still curious if the kind of binding I described is possible at all. Cheers, Geert-Jan A hack that's working: introduced 2 extra fields: facetmaxInc and FacetOld; public void setFacetCounter(int facetCounter) { this.facetCounter = facetCounter; if(facet!=null facet.equals(facetold)) { facetMaxInc = facetMax; facetold = facet; } if(facet!=null facet.getFacet().isSelected()) { facetMaxInc++; } } and check on facetMaxInc. Britske wrote: I need a bit of introduction to lay down the problem, so please bare with me: I have a component which renders lists of items. A parameter (childcounter) keeps track of the number of rendered items in the current List. I have the requirement. to be able to define on a per-page basis how many items are rendered at max. I implemented this by simply binding childcounter param and checking it against a field (say: maxitems) on the page. Depending on that I can decide on a per-page basis what to do with items that exceed the maxitems-threshold. (render different blocks, etc) So far so good. Currenly Im using this component to render facets (http://en.wikipedia.org/wiki/Faceted_classification) as part of a navigation menu. The requirement is to (for each list) render all SELECTED facets first and then render x (say 5) UNSELECTED facets per list, where x is defined by maxitems. The problem: the component doesn't know (and shouldnt know) that it is rendering facets. So it doens't know if a facet is selected or unselected. Based on that the childcounter is incremented each time a selected or unselected facet is rendered, and the maxitem-treshold is reached when 5 facets per group are rendered (independent whether they are selected or unselected). Obviously thats not what I want. The solution (so I thought) 1. The component doens't know that it's rendering facets, but the page knows. Moreover, the component outputs the item that it is currently rendering. (the facet in this case). 2. the param childcounter of the component is bound to the page field 'facetCounter' since as I understand it a param-binding is bi-directional I did the following: Page: -- @Component(parameters = {result=facetdsText, row=gGroup,childrow=facet,ulClass=literal:facets, childcounter=facetcounter}) private CompositeFlexLi facetBlock; public void setFacetCounter(int facetCounter) { if(facet==null || !facet.getFacet().isSelected()) { this.facetCounter = facetCounter; } } What it does is obvious: 1. the component renders and updates childcounter, which in effect calls setFacetCounter(int facetCounter), since its bound to facetCounter. 2. facetCounter is only updated when the current item is a UNSELECTED facet (which it knows in contrast to the component) The actual problem now is that facetCounter indeed is only updated when a facet is unselected, but the parameter 'childcounter' is still updated, although it is bound to the field facetCounter which is not updated (they aren't in sync). The behavior now is the following: (say i have 2 selected facets) childcounter: 1,2,3,4,5 facetfield: 0,0,3,4,5 while i figured it would be: childcounter: 0,0,1,2,3,4,5 facetfield: 0,0,1,2,3,4,5 Was I expecting to much 'binding-magic' to happen here, or am I missing something? If not, what would be your suggestion to tackle this issue? (making the component aware that its rendering facets is as I explained no option) Thanks in advance, Geert-Jan -- View this message in context: http://www.nabble.com/T5%3A-%22conditional-parameter-binding%22-or-something-tf4944458.html#a14155609 Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]