I have this project with Liferay where I manage courses for a training center. So I'll have a bunch of portlets for creating courses, a year schedule, teachers, etc.
And then I have a series of screens & portlets where you can manage and monitor the evolution of a specific course. So basically I have like two hierarchical sections of a website where you can create the entities in one, and manage a specific entity in other.
What I want to have is these two sections clearly separated, this way:
So in the course section all my portlets and the navigation menu are dependant of a "global" parameter which is the selected course identifier.
But I am new at Liferay and I am struggling with something that I'm sure it's fairly easy -- how can I pass this courseId parameter through all my dependant portlets? Sort of like a global variable for that context only?
In a normal website I would just append the parameter in the URL and I'll be fine but having many portlets in this section I'm sure there's gotta be a better way than passing the parameter to every single one of them.
Well, a few ways to do this are mentioned in the wiki here.
This basically shows 3 ways of doing it.
Using Session
Using Events
Using Cookies
Kindly go through the wiki link, it should equip you with the right ways to do that.
HTH
There is another possibility: jsr168 specified that you can have multiple public render parameter.
They are mapped into portlet.xml and if you use them you will receive values specified in url transparently.
You will find usage of these parameters into asset publisher portlet, for example, where public render parameter are used to listen user choice in category or tags navigation portlet.
Check out the jsr168/jsr286 portlet specification to find a way to manage them! ;)
Related
I'm creating mvc portlet to collect some data and have some trouble with implementing dynamic checkboxlist.
Is there any standard control for liferay or example how to implement such a feature?
Ideally if the control would allow hierarchical data (treeview) and possibly dynamic loading of sub-trees...
Thanks for help,
If i get you correctly Robert, You want to get dynamically get your checkboxlist data right?
There are no specific controls ( at least none that i know of) in Liferay for this. However, since it is an MVC portlet, it basically behaves like your traditional/conventional JSP(all permissible verisons) and as such your can design your protlet like you would any other JSP based application.
So typically if you have a check box list you would use the <portlet:namespace/> tag to name the checkbox element and also define an actionURL for the form data.
In the defined action use ParamUtil.getParameterValues(actionRequest,elementName,null) to retrieve an array of all checkbox list values.
*Note: Use as is appropriate for Single or Multi-Select checkboxes
For more information on how to handle form data in Liferay MVC portlet check out this url http://www.liferaysavvy.com/2014/05/liferay-mvc-portlet-form-submission.html
Hope this helps!
To get google tag manager data we need to add code provided by google into each and every page.
I dont want to manually add the code to each and every page component in CQ,as numerous templates can be created and it becomes manual job.
Instead i want to add the HTML code into my page on every page load.
Can i achieve this using service component(java class).
If not please, provide any alternative to achieve this.
Accounting for recent posts, your requirement, if I may paraphrase, says, "I want Google Tag Manager code included in all pages automatically, except on the pages where the author doesn't want it." In that case, your option is some form of component instance on every page, where the component's dialog.xml has a simple include GTM/don't include GTM checkbox. Alternatively, you could use a page property or a CQ5 tag. In any case, the author has to check the box or not.
you should use inheritance to achive this.
usually we got a so called "abstract" or "base" template which is more or less extending the foundtion page template were every other template can get kind of global code snipplets from.
You can put this "global" code into a seperate jsp within the abstract-template too and let people overwrite/disable that functionality in some of the extending templates (in case it is not needed in 100% of them) optionally too.
use this template in a way you would normally use the foundation components in every other template you are creating as resourceSuperType and there you go :-)
As suggested by chrysler you can use inheritance for this. Alternatively if you are very sure that you will need this google tag manager code in pretty much all the pages put the code in header/footer components assuming here that you are using header/footer in all the templates.
thanks for your reply. i am aware of this form of implementation wherein you create a parent page template and then refer to it via sling:resourceSuperType in all the child templates.
But what i wanted to know is if there is any other alternative wherein i dont have to host this code on the template's component, and the user can decide which page he wants to get tracked or not, who might not have coding knowledge.
Im working on a project in which I have to do the following.
I have a form that has some properties like address, personal information.
I want to use the few of the properties in the previous page to show in the other page as per few validations. I can show the properties of one page into other page by using tapestry(though I'm new to it).
I want to know if we can do the validations on the Java side in the service class, and if it is possible, how.
You can pass data between pages by multiple ways, most commonly used way is to use #Persist scoped #Property
here is a complete example of it
for validation there is a method that gets called before action phase, this document describes it well
I want to do something like this: index.xhtml -> createPerson.xhtml -> addAddress.xhtml -> index.xhtml.
In Managed-Bean CreatePerson a new Person-Object will be created, filled and saved, in Managed-Bean AddAddress I need the Person-Object in order to add an address to this person and after this, it should navigate back to the starting point. I think, the Managed-Bean CreatePerson should be #SessionScoped, because I have to inject the Person-Object into AddAdress (here #ViewScoped).
I want to have a loop or rather the possibility to create more than one person, but how can I do this if I have a SessionScoped-Bean, that lives longer than I need it? Is there any command or annotation to destroy it? How do you handle such workflows related to the scopes?
I know about MyFaces Orchestra with conversation-scope, but I will, if possible, do it only with Eclipse/Tomcat (7.0.11)/Mojarra (2.0.3).
Use a single view and make use of the rendered attribute to show/hide included views with "subforms" depending on each other. This way you can go with a #ViewScoped bean.
Alternatively, just save the Person in the DB after create and pass its id as request parameter to the next view and let it load from the DB again.
If you only want (or can) use Tomcat and Mojarra then both solutions mentioned by BalusC work perfectly, although with the limitations that you have to stay on a single page or redo queries between page navigation. Your use case is exactly what the conversation scope in Java EE 6 (through CDI) is made for. You can add this too to Tomcat via the Weld reference implementation.
When using the method BalusC outlined for staying on a single page, to give the user a tiny bit the impression of dealing with separate pages, it might be an option to display the rendered parts of the page using 'dialogs' (floating, css, ...). If using a third party component library is an option for you, you could add RichFaces or PrimeFaces that both contain ready to use dialog components.
My Java application is not very big, but I would like to do it the "right way". Looking for suggestions to not make a big mess...
I am using Swing, the Swing Application Framework and H2 database.
It is a single frame application with different tabs. Most tabs will reflect some aspects of the data in the database. Some of them will be able to change it. Some tabs will have buttons or actions that will redirect to another tab... that's basically it.
I would like to keep things clean, rather portable and flexible (can enable disable some tabs for example or add some easily).
Here are the questions :
1) How to have tabs "refreshed" when the database content changes ? Implement some Listener interface ? Should I define that interface or there is something already existing I can reuse ?
2) How to "link" the different tabs together so that it is easy to jump from one to another (and may have to carry some argument to setup the destination tab to the right "view")
3) If I set some preference with some filters in another part of the application, how do I share such settings with the whole application ?
And when I ask "how to", I really mean "what is the best way"... I can get that working already... just looking for the right tool to use, design pattern or such.
There are different strategies of gui application building. Here some article about.
If using swing, you can use tabbed pane to have a tabular layout.
Implement a listener (as you are planning). Have a look at observable interface in Java.
You can implement a singleton(eg PreferenceManager class) to hold the preference and access it across the application to access properties.
Do you really want a push model where the server has to maintain a connection to every client and then update them all when anything changes? This is feasible with a handful of clients, but quickly becomes problematic. It's probably better to use a pull model, where the client manually (periodically?) asks for updates. This is also a good way to use optimistic locking with a last_modified field in the DB. Attempt an update, if it's changed since you last reloaded, warn the user and allow them to overwrite / merge.
As for Swing in general, best practice is to factor everything out that's not GUI related into core classes ('business logic') that fire off events. Register all your Swing classes as the appropriate event listener and update the gui appropriately (SwingUtilities.invokeLater() is your friend here).