Re: Reading out a Component's formal parameters' values
Thanks for the tip! Having read the documentation on Environmentals, it looks to me like I have to push the required values in the outer component in a method that will lead to the invocation of the validator method where I need them, and pop the values, for instance, when this method returns. If I understand this correctly, this would be easy if only I could store the values in the validator instance, for instance during rendering, for later use in the validator. However it seems like Validator instances are shared in Tapestry, which makes this option unfeasible. This being said, my only option seems to be that when, for instance, I need values A, B and C in my validator's /isRequired()/ and /validate(Field, Void, MessageFormatter, Object)/ methods , I need to find the methods in *mycomp* that will cause the invocation of these validator methods, and push pop the values in there. Do I understand this correctly and if so, is there an easy way to find these methods (my IDE's call hierarchy doesn't provide me with the answers)? Or, isn't there an easier way to read a component's state from within a validator that it contains? Some additional context: the custom validator is just a Conditional Required validator, and the outer component mycomp knows (already during rendering), whether this conditional validator should be active or not. -- View this message in context: http://tapestry.1045711.n5.nabble.com/Reading-out-a-Component-s-formal-parameters-values-tp5680502p5682551.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Help with Dynamic Number of Form Elements
Lets assume your application looks like this: public class QuestionAndAnswers { private Question question; private ListAnswer possibleAnswers; } public class AnsweredQuestion { private Question question; private Answer answer; } public interface WebService { public ListQuestionAndAnswers getQuiz(String quizId); } I think I'd do it like this public class Page { @Inject private WebService webService; @Property private ListAnsweredQuestion answeredQuestions; @Property private AnsweredQuestion current; private MapQuestion, Listlt;Answer answerMap; public SelectModel getSelectModel() { ListAnswer possibleAnswers = answerMap.get(current); return createSelectModel(possibleAnswers); } public ValueEncoderAnsweredQuestion getEncoder() { // this will be used to serialize/deserialize each value to a hidden value in the form } public void onPrepareRender() { ListQuestionAndAnswers qsAndAs = webService.getQuiz(String quizId); // initialize answeredQuestions // initialize answerMap } } tml t:loop source=answeredQuestions value=current encoder=encoder ${current.question.question} t:select value=current.answer model=selectModel / /t:loop -- View this message in context: http://tapestry.1045711.n5.nabble.com/Help-with-Dynamic-Number-of-Form-Elements-tp5681909p5682584.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: CSS Driven Tabs
Thanks, Geoff. Love Jumpstart. Sticking with my counsel on this onejust doing a simple one-level menu, so pretty sure I nailed it, for now ;-) I selected the unravel CSS 2.0 tabs since it makes CSS do all the heavy-lifting. Always a better approach, if feasible. And the CSS itself is pure with no imagery etc. With tabX in the styles being replaced by componentResourcs.getPageName() as the alternate id mechanism in the unravel CSS 2.0 code, the polymorphism required in the component template falls into place. Now, all the components and page classes involved are completely free of any tabs related code, almost oblivious to the menu driving the application. Just importing the tabs.css into Layout.java in the usual manner. Nothing else there. No request parameters, Environment push-pop etc needed anymore. Basically, all the magic happens within Layout.tml which can (thankfully) pick up the pageName - and hence use it to conditionally style the page. Specifically, in the unravel CSS 2.0 code you would simply replace tabX with your page names. In the example below, Index replaces tab1, Products replaces tab2, Library replaces tab3 etc... body id=${prop:componentResources.pageName} html xmlns=http://www.w3.org/1999/xhtml; xmlns:t=http://tapestry.apache.org/schema/tapestry_5_3.xsd; xmlns:p=tapestry:parameter head meta http-equiv=content-type content=text/html; charset=utf-8/ titleWhatever/title /head body id=${prop:componentResources.pageName} ul id=tabnav li class=Indext:pagelink page=indexHome/t:pagelink/li li class=Productst:pagelink page=productsProducts/t:pagelink/li li class=Libraryt:pagelink page=libraryBibliography/t:pagelink/li [etc...] /ul t:body/ /body /html -- View this message in context: http://tapestry.1045711.n5.nabble.com/Can-Component-Template-be-Informed-by-Page-Class-tp5681397p5682662.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Cookies: Invalid cookie. Value not a token or quoted value
Hi, I have developed an application in tapestry and yesterday that application went to live where I have faced a problem in tapestry cookies. I have used the cookies to store the user related informations import org.apache.tapestry5.services.Cookies; @Inject private Cookies cookies; cookies.writeCookieValue(isUserLogin, True, -1); The above is what i am coding to store the datas. When I looked in my log file I have seen the below lines: *[2012-05-03 09:24:16.029] Cookies: Invalid cookie. Value not a token or quoted value* this displays continuously, however my UI works good but this line is getting continuously logged in the log file, what is wrong here? Environment is: Server - virgo-tomcat-server-3.0.2 Tapestry version is - 5.3.1 Logger - org.apache.log4j.Logger, Version - log4j-1.2.15 Thanks in advance, Karthi. -- View this message in context: http://tapestry.1045711.n5.nabble.com/Cookies-Invalid-cookie-Value-not-a-token-or-quoted-value-tp5682745.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Can Component Template be Informed by Page Class
On Wed, 02 May 2012 21:28:05 -0300, netdawg net.d...@yahoo.com wrote: OK. Lets leave it at that, I guess. Agree to disagree ;-). 1. Polymorphism is not about implementation at all. It is about interfaces, which is what Components can aspire to be, sort of. In that case, components, do not get tied to page properties - they use only those available - and if not, they behave as if those properties do not exist. That is Polymorphism, for me. So a shape would draw only if there was concrete draw provided, other it would ignore the draw request. No, this is not the definition of polymorphism in software development. Quite far from it, actually. You can have polymorphism without interfaces in Java: int i = 2; long x = i; i is not a long, yet its value still can be assigned to a long. That's a type of polymorphism called coercion. Polymorphism is the ability of something to appear in different forms in different contexts. Example: passing a String to a method that receives an Object. In this case, String appears as if it was an Object to this method. This is called inclusion polymorphism. In addition, the dynamic typed languages are all about polymorphism. 2. This discussion is about expanding horizons of Tapestry... I don't see it that way. You're asking for Tapestry to have a feature that goes against its principles. To make things worse, there are way to do what you want already implemented in the framework. I didn't want to pull an argument by authority, but I know what I'm talking about (at least in this case). When doing my master's degree, I was a TA in Object-Oriented Programming. Later I was the coordinator and professor of a graduate course on Java. I have more than 4360 posts in the Tapestry mailing lists. For helping people, I've been voted as a Tapestry committer and then a member of the Project Management Committee. not saying this a Very Bad Thing etc or giving up because it is difficult. I'm not saying this is difficult. I'm saying it's the wrong thing to do. It goes against the principles of Tapestry, good practices and good architecture. 3. I see pageName is just another page property...nothing more, nothing less (or should be, if not). Therefore, all other page properties should be visible as well. Of course, I have not looked at the code... No, the page name is not just another page property. That method in ComponentResources returns the logical name of the page, which is part of the not a property of your page class. You insist in saying this. That said, THANKS, I like the idea of ComponentResources.getPage()...*may* indeed be the answer I was look for...but I am already on a roll, so perhaps will look into later and report back You're welcome! -- Thiago H. de Paula Figueiredo Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, and instructor Owner, Ars Machina Tecnologia da Informação Ltda. http://www.arsmachina.com.br - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Help with Dynamic Number of Form Elements
Hi! On Wed, 02 May 2012 20:56:18 -0300, Ryon Day ryon_...@yahoo.com wrote: @property private ListSelectModel _questionSelectModels; // This is never null; it's populated during onPrepareForRender(); @propertyprivate SelectModel _currentModel Here is my Template: form t:type=form t:id=questionsEnrollForm loop t:source=questionSelectModels t:value=currentModel t:formState=ITERATION Question: select t:type=select t:id=selected t:value=selectedQuestionId t:model=${currentModel} / /loop input type=submit value=submit/ /form Result:Exception: Render queue error in BeforeRenderTemplate[Enroll:selectedquestionid]: Parameter 'model' of component Enroll:selectedquestionid is bound to null. This parameter is not allowed to be null. Here's what probably was your mistake: loop t:source=questionSelectModels t:value=currentModel t:formState=ITERATION currentModel should be passed to the model parameter of Select, not value. Loop's value is supposed to be a property which will store the current object being iterated. The source parameter is the array or collection being iterated, not the SelectModel. Another problem: select t:type=select t:id=selected t:value=selectedQuestionId t:model=${currentModel} / The value parameter of Select is meant to be the value you're selecting, aka, the object you want to select, so you don't need to use the object id, you can use the object itself. Another problem is using ${} expansions when passing parameters to components. Never, never, ever do that. This causes the parameter value to be coerced to String and then this String coerced to the type of the parameter. -- Thiago H. de Paula Figueiredo Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, and instructor Owner, Ars Machina Tecnologia da Informação Ltda. http://www.arsmachina.com.br - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Is it possible to add Field validators at render-time?
Hi, I was wondering whether it is possible to add Validators to a Tapestry field (e.g., TextField) at render-time (based on a runtime property)? More specifically, I'd like to know whether I can avoid doing: t:if test=required t:textfield ... validate=a,b,c,required p:else t:textfield ... validate=a,b,c /p:else/t:if and change it by something like t:textfield ... validate=a,b,c${prop:andRequired} / with public String getAndRequired { if(isRequired()) return ,required; else return ; } in the page's java source (note: this code does not work). I already thought of creating a custom 'required' validator, but there seems to be no way to initialize it. I was thinking of initializing it in the tml using t:validate=a,b,c,myrequired=${prop:required}, but this also doesn't seem to work... Thanks in advance -- View this message in context: http://tapestry.1045711.n5.nabble.com/Is-it-possible-to-add-Field-validators-at-render-time-tp5682920.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Igor Drobiazko Book
Thanks for update. First chapters I got under early access from Manning were very promising. Looking forward for full version. Regards, Nicholoz Kiknadze On Wed, May 2, 2012 at 10:45 PM, Igor Drobiazko igor.drobia...@gmail.comwrote: Sorry for the late reply. I somehow managed to miss this mail. I had a big progress until end of February / beginning of March. Unfortunately nothing happened between March and now, but I'm back on track. I'd love to tell you any dates, but I don't want to disappoint anybody if I miss the date again. I'm working hard to get the book published and trying to find some time slots between all the other things. On Fri, Apr 27, 2012 at 10:35 AM, Nicholoz Kiknadze 226...@gmail.com wrote: Just resending initial message of this thread. Wonder if there is any progress - three months ago it was only couple of chapters left... Hi, As I recall, after Manning canceled Drobiazko's book he was going to publish it on his own. Any news out there? I'm sure lots of us in this list are waiting for it. -- Best regards, Igor Drobiazko http://tapestry5.de http://twitter.com/drobiazko
Re: Is it possible to add Field validators at render-time?
You should be able to use two bindings together like this: t:textfield ... validate=validate:prop:validators public String getValidators() { StringBuilder validators = new StringBuilder(a,b,c); if (required) { validators.append(,required); } return validators.toString(); } -- View this message in context: http://tapestry.1045711.n5.nabble.com/Is-it-possible-to-add-Field-validators-at-render-time-tp5682920p5683051.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Is it possible to add Field validators at render-time?
Hmm... try validate=prop:validate:validators -- View this message in context: http://tapestry.1045711.n5.nabble.com/Is-it-possible-to-add-Field-validators-at-render-time-tp5682920p5683113.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Is it possible to add Field validators at render-time?
Another option is: t:textfield t:id=textField validate=prop:validators / @Inject Field textField; @Inject FieldValidatorSource fieldValidatorSource; public FieldValidator getValidators() { StringBuilder validators = new StringBuilder(a,b,c); if (required) { validators.append(,required); } fieldValidatorSource.createValidators(textField, validators.toString()); } -- View this message in context: http://tapestry.1045711.n5.nabble.com/Is-it-possible-to-add-Field-validators-at-render-time-tp5682920p5683128.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Is it possible to add Field validators at render-time?
No go :/. org.apache.tapestry5.ioc.Registry - Exception assembling root component of page MyPage: Could not convert 'prop:validate:validators' into a component parameter binding: Error parsing property expression 'validate:validators': Unable to parse input at character position 9. -- View this message in context: http://tapestry.1045711.n5.nabble.com/Is-it-possible-to-add-Field-validators-at-render-time-tp5682920p5683135.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Is it possible to add Field validators at render-time?
Thanks, that'll work indeed. Do you happen to know whether it's also possible to inject such a field from the body of a custom component in that custom component? For instance, let's say we have: t:mycomponent t:textfield t:id=tf1 ... / /t:mycomponent Where I'd like to access the tf1 textfield in mycomponent's java class to create the validator and store it in a render variable that is then accessible while rendering, allowing something like this: t:mycomponent t:textfield t:id=tf1 validate=var:validators ... / /t:mycomponent I tried to add the following in the MyComponent class, which does not seem to work: boolean setupRender() { TextField tf = resources.getEmbeddedComponent(tf1); // construct validators here resources.getPage().getComponentResources().storeRenderVariable(validators, validators); } (the getEmbeddedComponent fails) -- View this message in context: http://tapestry.1045711.n5.nabble.com/Is-it-possible-to-add-Field-validators-at-render-time-tp5682920p5683187.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Is it possible to add Field validators at render-time?
I think that the var: binding is a bit of an edge case and I think it's best to avoid it. I've never needed it and have always managed to get by with component properties. -- View this message in context: http://tapestry.1045711.n5.nabble.com/Is-it-possible-to-add-Field-validators-at-render-time-tp5682920p5683254.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Is it possible to add Field validators at render-time?
In your example, you are reading from the textfield's render variables (using var:) but you are storing on the page's render variables (resources.getPage().getComponentResources().storeRenderVariable()) -- View this message in context: http://tapestry.1045711.n5.nabble.com/Is-it-possible-to-add-Field-validators-at-render-time-tp5682920p5683263.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Is it possible to add Field validators at render-time?
Yup I know about the page render variables, but that works. The problem is getting access to the embedded field.. (i.e., the TextField, or any field with a specific name, in the body of the custom component) The custom component itself doesn't have a tml file, it just employs the render phase events to do its job. -- View this message in context: http://tapestry.1045711.n5.nabble.com/Is-it-possible-to-add-Field-validators-at-render-time-tp5682920p5683291.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Is it possible to add Field validators at render-time?
Correction: In your example, you are reading from mycomponent's render variables but are writing to the page's render variables. -- View this message in context: http://tapestry.1045711.n5.nabble.com/Is-it-possible-to-add-Field-validators-at-render-time-tp5682920p5683292.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Is it possible to add Field validators at render-time?
1. What is the value of resources.getComponentModel().getEmbeddedComponentIds(); 2. Try afterRenderBody() instead of beforeRender() -- View this message in context: http://tapestry.1045711.n5.nabble.com/Is-it-possible-to-add-Field-validators-at-render-time-tp5682920p5683326.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Displaying the current locale's language
Hello, I need to be able to specify the anchor's hreflang attribute in a T5 action link. 1. There does not seem to be any such attribute for the tapestry action link. Is there a workaround? 2. I want to use the current locale's language such as fr or en. Here is what I tried: @Inject private PersistentLocale persistentLocale; @Property @Persist(PersistenceConstants.FLASH) private String language; @OnEvent(EventConstants.ACTION) void changeLocale(String language) { persistentLocale.set(new Locale(language)); language = persistentLocale.get().getLanguage(); } and then ${language} This result in a blank for the language variable. Can anyone please help? Regards, Julien.
Re: Is it possible to add Field validators at render-time?
Lance, I'm currently unable to access my workstation, but I invoked the /resources.getComponentModel().getEmbeddedComponentIds();/ in both setupRender() and cleanupRender() earlier today. Both invocations returned an empty list. -- View this message in context: http://tapestry.1045711.n5.nabble.com/Is-it-possible-to-add-Field-validators-at-render-time-tp5682920p5683688.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Can Component Template be Informed by Page Class
Thiago, I perfectly understand where you are coming from. But it is hardly defensible. And, I suspect you know it. I have just proven to you polymorphic behavior of components using just pageName. Imagine what else can done, in menus alone, with more visibility - multi-level drill-downs etc. The possibilities are simply fantastic. If Tapestry, cannot (or will not) do it - there are other frameworks who will. Waving your resume, or credentials, is not going to help in the face of sheer power of logic, or the market. If you do not want to call it Polymorphism - fine - call it sometihng else. I was using that term loosely to convey some sense of different behavior based on what page the component is templating. The objective here is to enhace that behavior, not block the very consideration of it. -- View this message in context: http://tapestry.1045711.n5.nabble.com/Can-Component-Template-be-Informed-by-Page-Class-tp5681397p5683836.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Is it possible to add Field validators at render-time?
On Thu, 03 May 2012 13:33:11 -0300, wout86 wouter.amerij...@gmail.com wrote: I'm currently unable to access my workstation, but I invoked the /resources.getComponentModel().getEmbeddedComponentIds();/ in both setupRender() and cleanupRender() earlier today. Both invocations returned an empty list. It seems to me that, from another component or a page, you're trying to set things on something in another component. Don't do that. Instead, pass some parameter to the component that will be used for it to implement the field validation logic itself. -- Thiago H. de Paula Figueiredo Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, and instructor Owner, Ars Machina Tecnologia da Informação Ltda. http://www.arsmachina.com.br - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Can Component Template be Informed by Page Class
I officially give up. You're using wrong definitions of concepts, and the consequence is that just you will understand what you're talking about. And you can't read my mind to know what I'm thinking. You have proven nothing beyond the fact that you don't know what polymorphism is. In a component, using ComponentResources.getPage() or getPageName() you can figure out in which page the component is, even if this is a bad approach in most situations. People already do many magical things (Taha, wink! ;)) with Tapestry the way it is. If you explained better what you want to do we'll be able to tell how you implement the Tapestry way. I'm not sure I'll take the time, though. On Thu, 03 May 2012 14:21:49 -0300, netdawg net.d...@yahoo.com wrote: Thiago, I perfectly understand where you are coming from. But it is hardly defensible. And, I suspect you know it. I have just proven to you polymorphic behavior of components using just pageName. Imagine what else can done, in menus alone, with more visibility - multi-level drill-downs etc. The possibilities are simply fantastic. If Tapestry, cannot (or will not) do it - there are other frameworks who will. Waving your resume, or credentials, is not going to help in the face of sheer power of logic, or the market. If you do not want to call it Polymorphism - fine - call it sometihng else. I was using that term loosely to convey some sense of different behavior based on what page the component is templating. The objective here is to enhace that behavior, not block the very consideration of it. -- View this message in context: http://tapestry.1045711.n5.nabble.com/Can-Component-Template-be-Informed-by-Page-Class-tp5681397p5683836.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org -- Thiago H. de Paula Figueiredo Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, and instructor Owner, Ars Machina Tecnologia da Informação Ltda. Consultor, desenvolvedor e instrutor em Java, Tapestry e Hibernate http://www.arsmachina.com.br - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Can Component Template be Informed by Page Class
Good grief. O well, that is probably more oxygen for others. Thanks for you inputs nevertheless - the ones with substance, anyway. As for wink, wink, we are already doing magic - it borders on delusional - suggesting some sort of inside clique that is bullying everyone else - helping some and not others - you have perfect right to do that, but that there will more footsteps out the door than inpossibly mine too. Good bye. -- View this message in context: http://tapestry.1045711.n5.nabble.com/Can-Component-Template-be-Informed-by-Page-Class-tp5681397p5684049.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Is it possible to add Field validators at render-time?
Thiago, I want to apply the same logic that's applied when using a Page property in a tml to output text: I want to use a component's property (render variable in this case) in its body to set the validator for a field in this body. That doesn't seem too wrong to me, does it? -- View this message in context: http://tapestry.1045711.n5.nabble.com/Is-it-possible-to-add-Field-validators-at-render-time-tp5682920p5684066.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Can Component Template be Informed by Page Class
You /do/ realize that Thiago has already spent considerable time trying to help you? In any event, your conceptual understanding of Tapestry seems a bit off. Not trying to be mean, just stating fact. For instance: Basically, is there is a way for a component to inherit properties of child component (page)? This suggests that you're thinking of the page as the child component. But the page isn't the child component. The page is the parent component. You've also referred to pages inheriting from components: pages, like Index, are not inheriting layout etc, from component Layout? What am I missing? There's no inheritance involved. Tapestry pages and components are generally built by composition, not inheritance. Consider: class Person { private String firstName; private String lastName; } Person is /composed/ of two String objects. But Person does not /inherit/ anything from String. It's not a String, it's a Person with two String properties. Likewise, String is not in any way tied specifically to Person. Imagine if the String object in java had some code like: if (containingObject.firstName.equals(George)) {...} It's a bit preposterous, don't you think? :) Yet, this is precisely what you're proposing. Your Page is like the Person. It is composed of components, in an analogous way to how Person is composed of two String properties. Making your Components depend on specific details of the page (like whether it has a specific property) is a recipe for brittle components with no potential for reuse. Which is a shame because the point of components is reuse. All of that said, it's normal to adjust the behavior of the component to the requirements of the container. The two normal ways to do this are component parameters and the Environment service. Both of these solutions have been mentioned multiple times (3? 4?), but it appears that you are unfamiliar with the concepts, eg: I am not sure what the Environment solution referred really is. A good place to start is the documentation. :) See: http://tapestry.apache.org/component-parameters.html For starters on component parameters, and: http://tapestry.apache.org/environmental-services.html For information on using the Environment solution. Finally, you can accomplish directly what you're trying to do as: Index.java: public class Index implements MyInterface { public Object getSomeProperty() {..}//defined by MyInterface } Index.tml: t:layout/ Layout.java: @Inject private ComponentSource cs; @Inject private ComponentResources resources; @Cached public MyInterface getMyInterfaceInstance() { Object o = cs.getPage(resources.getPageName()); if (o instanceof MyInterface) { return (MyInterface) o; } else { return /* something else here, some reasonable value. null? Default implementation of MyInterface?*/; } } Layout.tml: ${myInterfaceInstance.someProperty} But that's an awful lot of work for something that could be accomplished as: public Class Index { public Object getSomeProperty() {...} } Index.tml: t:layout parameterName=someProperty/ Layout.java: @Parameter private Object parameterName; Layout.tml: ${parameterName} You didn't have to create the interface. Layout can be used on any page. And any property can be used to satisfy the need for parameterName. Cheers, Robert On May 3, 2012, at 5/31:49 PM , netdawg wrote: Good grief. O well, that is probably more oxygen for others. Thanks for you inputs nevertheless - the ones with substance, anyway. As for wink, wink, we are already doing magic - it borders on delusional - suggesting some sort of inside clique that is bullying everyone else - helping some and not others - you have perfect right to do that, but that there will more footsteps out the door than inpossibly mine too. Good bye. -- View this message in context: http://tapestry.1045711.n5.nabble.com/Can-Component-Template-be-Informed-by-Page-Class-tp5681397p5684049.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Can Component Template be Informed by Page Class
All:Again, I appreciate the inputs, efforts and suggestions, even good advice. And, if someone does something differently, it is not hacky. The blog post, BTW, was for you specifically for your constructive comments. I was inspired to do that since we were just waving hands on this forum, going off in tangents. You now have something concrete. Lets improve it together. I have (and will ) incorporate many of those comments - just not all of them - unless I have code that actually works. Just declaring try this and that is not sufficient. Finally, as for time spent, we are all in the same canoe. This is the only way this tool gets sharpened. -- View this message in context: http://tapestry.1045711.n5.nabble.com/Can-Component-Template-be-Informed-by-Page-Class-tp5681397p5684235.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Can Component Template be Informed by Page Class
There's doing things a little different, and then there's driving on the wrong side of the road ... on the highway. There's specific reasons for many of the constraints in Tapestry, often related to efficiency, security, encouraging users to create maintainable code, or simply general correctness. But the model for Tapestry is that the container (the page, or containing component) pushes data INTO the component, by establishing bindings: properties of the container that can be read by the component through its @Parameter-annotated fields. It is possible for a component to have knowledge of its container: the @InjectContainer annotation can be used for that purpose. However, solutions based on the component having too much knowledge of their container have been proven, in the wild to be brittle, hard to understand, hard to maintain. I've seen this is client code I've had to clean up (and the code is *always* shorter and clearer, as well). The right way, which is to reason about the minimum set of information a component needs to operate, has proven itself time and again to be the best approach. I often post a link to this document: http://catb.org/esr/faqs/smart-questions.html It goes into great length about how to phrase your question the correct way to best ensure an answer. Part of the core is stripping away as much as you can, to reduce it to a question of stimulus, expected response, and actual response. I pushed the button, expecting the car to start, but instead the radio came on. is vastly preferable to I think the inputs on the dashboard need to be reorganized. Showing that you can think clearly, and ask questions intelligibly, is very necessary to quickly prove yourself to others, the people who could more easily ignore you than help you. On Thu, May 3, 2012 at 1:34 PM, netdawg net.d...@yahoo.com wrote: All: Again, I appreciate the inputs, efforts and suggestions, even good advice. And, if someone does something differently, it is not hacky. The blog post, BTW, was for you specifically for your constructive comments. I was inspired to do that since we were just waving hands on this forum, going off in tangents. You now have something concrete. Lets improve it together. I have (and will ) incorporate many of those comments - just not all of them - unless I have code that actually works. Just declaring try this and that is not sufficient. Finally, as for time spent, we are all in the same canoe. This is the only way this tool gets sharpened. -- View this message in context: http://tapestry.1045711.n5.nabble.com/Can-Component-Template-be-Informed-by-Page-Class-tp5681397p5684235.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org -- Howard M. Lewis Ship Creator of Apache Tapestry The source for Tapestry training, mentoring and support. Contact me to learn how I can get you up and productive in Tapestry fast! (971) 678-5210 http://howardlewisship.com - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org