JSF and PrimeFaces custom component with other components inside [duplicate] - jsf-2

This question already has answers here:
Component to iterate and render a nested tree-like object structure in JSF
(2 answers)
Closed 7 years ago.
Description:
I am creating an e-shop in JSF. On the right side I want to have the all categories of my shop.
I use recursive method to go through all categories (category can have parent category).
So the way I have choosen to do it is creating my own component.
Is this thinking correct?
How to do it this way or maybe I should try something else?
My attempt of solving this problem:
Create custom component which extends UIComponentBase (maybe I should extends
something else).
Then create another components (CommandButtons) inside of this component ,
which will be added to host the component.
Another issue is how can I launch actionListener of my button?
Beacause they are not automatically launched?
Has anybody created these kinds of components?

You're basically looking for an UI component which can render a tree hierarchy. PrimeFaces already offers two tree based components out the box, the <p:tree> and <p:treeTable>. Click the links to see several showcase examples.
If you intend to have full freedom over the markup of a tree hierarchy, then you may find the OmniFaces <o:tree> more useful. It does not render any HTML, so you have all HTML freedom to markup the tree nodes accordingly.
Or if you really insist in developing your own and thus reinventing the wheel, look in the source code of those components. They are open source.

Related

React newbie: sharing state across unlinked components

I'm a React newbie trying to integrate React into a Rails site. I have a CommentForm component at the very top of the page/html, and a Comments component at the bottom of the same page. At present, both are rendered through React-On-Rails' react_component method.
The problem is that, upon submitting a form in CommentForm, I'd like to change this.state.comments in the Comments component. I'm familiar with the idea of ensuring state is bubbled up to a common parent component, but at present, these two components don't have a common parent (or any parents at all).
So, with the disclaimer that I've been learning React for all of 2 days and am likely very confused, what's best practice for overcoming this sort of issue? Options as I see them:
Rewrite the entire rails view as a single parent component with the two components as children underneath. This doesn't sound fun - there's a lot of html generated by a lot of rails helpers between the two components on the page
Use Redux to create a store that's shared between the two components(???)
Somehow create a parent component while still rendering the two other components in separate parts of the page(?)
Accessing Comment's state attributes from within CommentForm or some shared resource (eg: window scope), which, from my limited understanding, isn't the React Way
I'm guessing this is a common problem, but I'm uncertain what the general wisdom is to fix it. Any ideas appreciated.
The first option would be doing the react way only (with no external libraries). If your project it's not that big, could be a solution.
The third and fourth option are definitely not the way to go.
For what you said, using Redux seems to be the easiest solution.
The Comments component should be drawing all the comments in your global store and the CommentForm should add the comments to the store (and probably send an AJAX request for saving server side also).
Then, these components will share the same Provider and have access to same Store.
I'd suggest you watching Dan's Course
Redux is the perfect use case for this honestly. It doesn't take too long to implement but if you've never done it before you're gonna need a day or two to wrap your head around it.
In general, as your project grows even more, you will have a much easier time managing one state instead of a thousand component wide states.
So, if you're gonna have more situations like this, or situations where you have to pass down props through more than 3 components. I'd implement Redux now and be future proof.

Developing web applications with widgets (or re-usable components) in ROR [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have experience in writing code... but new to developing web applications.
I am in process of choosing a framework for my project. Based on my initial research almost everything is very VIEW centric where after all business logic has been executed a model is populated with data and passed on to the VIEW.
So the lowest level of granularity is the VIEW.
But I wonder what is the right technology to use if I wanted to develop re-usable widgets or controls. and then reuse them across multiple VIEWS.
i would prefer if the controls are in JavaScript and then they can easily be reused across pages.
So if I were to select Ruby on Rails ... does it have anything to help me write code in reusable widgets... or will it simply ask me to write the VIEWS which work with the data provided by the model?
Sorry if this is newbie question.
What do you use to write reusable Widgets in ROR?
to eloborate on what I mean by a widget.
Suppose I am writing a discussion forum web application. I want to write a widget called post which has 3 views. View 1 is edit mode. View 2 is summary mode. view 3 is Detail mode.
I throw in this widget in a page called QuestionStream and in this page the widget appears in summary view. I perform data binding so that i get a list of questions.
I throw in this widget in a page called ThreadView and in this page the widget appear in detailed view. I perform data binding and I get all the details of the question.
I throw in this widget in a page called NewQuestion and in this page the widget appears in edit view.
So its a self contained control... but is reused in multiple places in different modes (so to speak).
OK, well I hope I understood your question correctly.
Firstly I want to start by saying that web apps tend to be very "view-centric" since that's kind of (in a very abstract way) the basis of the REST architecture (i.e. the Internet). It's about stateless resources. You can imagine a resource being a form printed on a document. I've generated all the fields I require and I've printed it out and handed you the piece of paper. At this point I really don't know or care how you will fill out the form or with what data. I will only care about the data's validity once you hand me back the form and I can begin checking (for simplicity I've ignored AJAX concepts, that give you real-time validations/interactions). I think it's this 'statelessness' that makes it appear very 'view-centric', but don't be fooled, there's a lot going on under the hood.
With that said, there are three common ways of sharing code across your application.
PARTIALS - reusable view code - These are reusable snippets that can be used in your views - example: each item listed on Amazon has the same format (thumbnail, title, author/manufacturer, rating & price). It would make sense to write this View snippet once and just pass an array of objects where each object's attributes are then passed individually into the same partial and placed side by side
HELPERS - reusable methods - Helpers are again used in the views. Essentially it is common functionality that has been consolidated into a method so it can be reused multiple times, and by passing in different parameters you could make your method respond differently based on the situation (i.e. the current logged in user, or the current controller that has triggered this view). Example: I could create a helper method that could toggle my product listings from a detailed view, to a list view (not the best example, but I hope it gets the message across).
CONCERNS - reusable code across models - Concers are meant to "extract common and/or context specific chunks of code in order to clean up the models and avoid them getting too fat and messy". Please see this link for an example.
Your question was a bit tricky but I hope my answer helped clear a few things up for you.
As for your example, the 3 different views could be 3 different partials. You could then write a helper method that looks at the current controller, and determine which partial should be loaded. Digging a little deeper, you could then use concerns to keep your models' code DRY (Don't Repeat Yourself) - assuming you have multiple models with similar functionality.

Create a quiz with polymer or angular? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I would like to create a quiz with dart. Checkboxes, radiobuttons, dropdownmenu, inputfields, ...
Furthermore I would like to load the quiz from a database, display it on a website and store also the results of a specific user to a database. Redis or mysql.
The big question for me: Should I use polymer.dart or angular.dart? Both are capeable of doing it but what would be the obvious choice?
Polymer and Angular might look very similar because they both have templating and data-binding, but they're actually quite different.
Polymer isn't really a full application framework so much as it is a framework for creating W3C Custom Elements1. It relies on new, upcoming, and hopeful standards like Shadow DOM, Object.observe, Mutation Observers, Scoped CSS, the element, Template Binding, Node.bind(), Custom Elements and HTML Imports and basically makes it easier to use them together to create custom elements. You actually don't need to use Polymer at all to create custom elements, it would just be more tedious. The Polymer project has also built polyfills for those standards, so it's sometimes confusing to tell which parts are the actual "polymer" part. In Dart-land it's only things in the polymer package, mostly the Polymer class, everything else is in packages like observe, template_binding, or already integrated into dart:html, like Shadow DOM.
Once you implement a custom element in Polymer, users of the element don't need to be aware of Polymer at all, it's an implementation detail. They might need to know about custom element upgrading or Node.bind(), but not Polymer. In fact, Polymer is so focused on elements, that there isn't really such a thing as a "Polymer app", there's just an app built out of custom elements, which happen to be implemented with Polymer, but they could just as easily be implemented with Mozilla's X-Tags library[2]
Angular is definitely more full featured and what I would call an "application framework", rather than a custom element framework. It provides directives (mixin behaviors for nodes), dependency injection, all kinds of services like http and routing, and has this whole mutable inherited scope idea that permeates the app, and has global state, among other things I'm probably missing. Angular currently won't help you build custom elements, instead you create Angular components that work in Angular apps.
An Angular app can use Polymer elements, since Polymer elements are just elements. One way data-binding should[3] just work, while two-way data binding will require either a custom directive (to use Object.observe or Node.bind to listen to property changes), or for Angular to add support for Node.bind(), which would allow Angular to generically two-way-bind to any element, from s to Polymer elements, to X-Tag elements.
In the end, I don't think there is a fair apples-to-apple comparison between the two, and the overlap is smaller that it might appear on the surface, because people seem to either over-estimate how big Polymer is or how under-estimate how big Angular is, or maybe they aren't aware of the differences in philosophy. I fully expect more Angular-like frameworks to appear in the future that build on top of custom elements that will be more comparable to Angular than Polymer is, and Polymer will still be a nice way, among other options, to implement the elements.
SOURCE
I worked a lot with Polymer (https://github.com/ErikGrimes/polymer_elements, https://github.com/ErikGrimes/polymer_ui_elements) and worked on a webapp based on Polymer.
I like building apps out of components a lot.
Recently I immersed into AngularDart.
Angular allows to create components too.
At the current state I would say that I find Angular more lightweight.
Not everything has to be a component, there are more lightweight constructs (direcitve, controller)
The hierarchical scope easily allows to connect everything.
I have yet to do more advanced things (like I already did with Polymer) to learn the limitations of Angular and be able to do a fair comparsion.
Both have still some glitches and limitations and are still pre 1.0
but both already allow building advanced applications
and as #Nidzaaa 's noted, they can be used in combination.

Is there a way to add a Umbraco Custom Data Type that basically was a grouping of existing data types?

On a number of different document types, I have to add the same 3 native Umbraco data types
content picker
TextString
TextString
It was suggested to me to see if there is a way to create a new custom data type that would basically wrap those 3 datatypes into a new datatype.
I looked at nibble.be's site and see there is a couple different ways to go about creating custom data types (using the usercontrol wrapper, or 3 class approach). However, I am not sure that a custom data type for grouping existing datatypes would be the correct route.
For one thing, we are using MVC along side Umbraco with a heavy use of Razor views. Since the document type property alias is used to acquire values from Umbraco from the content page, I don't see how this would still be possible or how you would go about getting the property value of a custom datatype that has embedded datatypes.
Would there be a working way or a better way to accomplish this solution for having to add the same fields on any document type that they are needed? I though about hierarchical approach with a document type parent with only these 3 data types (content picker and 2 textstrings), but that would mean having to put any document type that a page would need under this parent document type simply for the fact to inherit these group of properties.
If you're looking to embed multiple properties into a single datatype:
There are a number of embedded datatypes available; DataType Grid, Embedded Content, and Repeatable Custom Content are the three I know of. All three store their information as xml which allows easy access via both xslt and razor.
The DataType Grid is part of uComponents and is therefore actively developed. It is also open source and therefore contributions are encouraged. Embedded Content and Repeatable Custom Content, while still useful, don't appear to have any current support and therefore no plans for improvement. I think they are licensed as open source, but the source isn't publicly available as far as I can tell.
I don't think you can set a limit on the number of rows/items stored in the DataType Grid, like you can in Embedded Content (perhaps a feature request).
Take a look at some of these solutions before you plan on rolling your own. But if you still feel the urge to code out your own data type, I'd recommend Tim Geyssens' articles on created custom datatypes using the user control wrapper, with data editor settings, and serializing the data as xml. His "Master of Datatypes" video is also really helpful and covers those topics as well.
If you're looking to organize your properties into groups:
Tom Fulton published a new package/data type recently called Document Type Fieldsets that may fit your needs. It allows you to group fields together in a fieldset. Here's a screen shot:
I realize this is an old question, so I'm just adding this for anyone searching for this functionality in the future: This is almost exactly what we use Widget Builder for in Umbraco 6.
Widget Builder is the predecessor to Umbraco 7's Archetype which is being pushed by the core team for near universal use. I believe it's going to become a part of the core.
Internally, WidgetBuilder and Archetype store their data as JSON and make it very easy to copy a custom data type from one project to another with an import/export feature.
I used to work with Archetype for some time until I discovered Nested Content which does the same thing but much easier to work with because it nests Document Types instead of Data Types which is much easier to work with, especially for Content Editors. Plus the resulting Data Types is normal built-in Umbraco ones, not Archetype Objects which add a new layer of Entity Mapping in your views.

Struts2 dynamic form elements

I would like to create little higer-level framework on top of Struts2 which can take form element description from Action and render a complete form, in order to avoid having a separate JSP files with hardcoded form elements for every form in a large web application (so if I manage to do this I will have just a few generic JSPs for data form and few for layout). Application is extremely data-driven.
My idea is to create form description using custom objects in the Action (i.e. Button, TextInput etc.) and then to create a single JSP page that will render eveything out.
What is the best way of doing this? Can you propose some concrete way to do this?
I don't want to write something if I can reuse the existing code with some effort.
Any ideas are appreciated.
Kind regards,
Bozo
It seems to me you are trying to build a web framework on top of another, I doubt Struts2 is appropiate for that.
If you have a data-driven web app for which you dont want to write many similar JSP (or whatever view lang) pages, perhaps you'd better look at some frameworks with scaffolding abilities , eg Grails http://www.grails.org/Scaffolding
I did what I asked in the question myself - I have created a few generic JSP templates (list, edit etc.) which take application parameters and create output grids and forms using the struts2 and simple HTML tags. Using this method generic tiles definitions can also be created and used. So at the end using simple definition in the struts2 action, the grid and form is generated.

Resources