I have form on a porlet, after submission of that form, page is redirecting to another portlet for that i am using actionResponse.sendRedirect("/abc/bcd/newWebPage")
and i am landing on to different page. One that page the same potlet is added with different screen, Now i want to display a success message on next page.
for that i am using portlet session and passing parameter to jsp.
PortletSession session = actionRequest.getPortletSession();
session.setAttribute("SUCCESSA", "Successfully",PortletSession.APPLICATION_SCOPE);
But its not working.
Any help how to achieve that?
When you say One that page the same potlet is added with different screen, I understand that you have another instance of the same portlet in different page. By the way, you haven't explained what is not working for you. I assume you are wondering how to read in the JSP page. It's pretty straight forward:
In Controller:
PortletUtils.setSessionAttribute(request, "SUCCESSA", "Successfully", PortletSession.APPLICATION_SCOPE);
In JSP:
pageContext.setAttribute("succcessa", PortletUtils.getSessionAttribute(renderRequest, "SUCCESSA", PortletSession.APPLICATION_SCOPE));
The PortletUtils does the same as setting the attribute using the PortletRequest object but its preferrable.
To remove the session attribute:
PortletUtils.setSessionAttribute(request, "SUCCESSA", null, PortletSession.APPLICATION_SCOPE);
The implementation of PortletUtils is that it removes the session attribute if value is null, if a session existed at all.
Related
I would like to know the different kind of redirections in the portets and how to realize them. How to go from one view (jsp file) to another in the same portlet, how to go from one page to another from a portlet. It is for the purpose of making a form so I would like to do this in a processAction.
Your answer is not clear.
However, in Liferay, you can route your application using urls.
For example, you can create a portlet action url on your own.
You can try something like this:
HttpServletRequest request = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(actionRequest));
PortletURL oPortletURL = PortletURLFactoryUtil.create(request, <portletName> , <plid>, <portletPhase>);
oPortletURL.setParameter("myParameter1", "parameter1");
String portletURL = oPortletURL.toString();
Where:
<portletName> is the javax.portlet.name of your portlet
<plid> is the ID of a page where is located an instance of your <portletName> portlet (try to check Layout and LayoutFriendlyUrl tables)
<portletPhase> is the phase you need, for example PortletRequest.ACTION_PHASE
Finally, you can use setParameter() method to pass parameters in query string.
On the jsp for a single portlet: If you use Liferay's MVCPortlet, you can just add the mvcPath parameter with the name of the JSP, to make sure your portlet renders with this JSP. Nothing else.
Pages have a URL. If you want to redirect to another page, you'll have to configure the page's URL somewhere. However, that's rarely done unless you're implementing a Navigation portlet. Your question sounds more like you have a multi-page portlet.
Our project uses a Web Application developed using JSF, primefaces, xhtml. Currently user can login and navigate through pages sequentially by clicking on 'action' links, like:-
index.xhtml --> login.xhtml --> classes.xhtml --> students.xhtml --> student_info.xhtml
i.e. first login --> shows the list of classes --> user selects a class --> shows the list of students in that class --> user selects a student --> shows the student info.
Each of the pages has its own 'backing bean' classes. They are instantiated as and when the user clicks through the pages.
Also, user can navigate back via certain links on each page-- say, from 'student_info' page, he/she can go back to the 'students' page.
Now requirement is: user can directly go to an inner page, say, student_info page by typing an 'url' with additional parameters, ?user=alice,?passwd=xyz, ?class=5, ?studentRollNo=15.
Also, the user should still be able to navigate back to other pages (i.e. once the page is opened, their should be no behavior difference whether the user navigated normally to student_info page or, whether he directly provided url with parameters).
My questions are:-
How to read url parameters in JSF?
Which page (or backing bean) should handle the parameters? Should it be done centrally, or, in each page (backing bean) ?
In case each page handles its relevant parameters only -- is there way to redirect remaining parameters to the next page ?
What are the best practices used in such implementations?
Note:
Actual web application is much more complex, tried to provide a simpler picture which pinpoints my problem.
new to JSF, Web App etc. Don't know if there are some JSF terminologies to describe above issues.
you can pass it by url request, and each BackingBean handle it
ex:
mypage.xhtml?myparam=test
and inject the HttpServletRequest in your BackingBean (if you are using CDI)
#Inject
HttpServletRequest request;
and get the param
#PostConstruct
public void init() {
String myparam = request.getParameter("myParam");
}
for redirect to other page you can use
public String redirect() {
return "otherPage.xhtml?faces-redirect=true&otherParam=test";
}
For a Seam application, I am trying to pass page parameters after encountering a ViewExpiredException in pages.xml (session time out) on the redirect view but they get dropped when the browser redirects to the view.
<exception class="javax.faces.application.ViewExpiredException">
<redirect view-id='/accessExpired.xhtml'>
<param name="hiddenRoleTag" value="BORROWER" />
</redirect>
</exception>
the page parameter would actually be dynamic and the page would display text based on the page parameter but for simplicity I have kept the param as static (for now).
Any way around this?
In 2.2.0, Seam ignores any <param/> nodes within an <exception/> navigation definition. Note that the exception handler is created when the application is initialized, not dynamically when the error happens. Also, note that when your session expires, so does the data that the session held (including conversation data), so you will not be able to use any of that data when this specific error happens.
The view-id value, on the other hand, is a ValueExpression, so you can use expressions directly in the view id.
Im having a question regarding retrieving the view state of a JSF page.
I have an application in which the user is able to search for persons in a
list and when the user press "show" button the same JSF page will be filled
with a list of the various persons.
Now when I choose one of the persons , another JSF page will show up with more
in-depth and detailed information about that person. Now in that page there is a
"cancel/abort" button displayed. What I want to accomplish is that when I press
that specific "cancel/abort" button the page should be redirected and navigate
back to the JSF page with the list as it was shown, so in some way the "view state"
should be stored (I assume only) but I dont know how it could be done...
I just wanted to check if anyone has been able to solve this kind of issue
in some manner.. ? (The JSF search page as mentioned above is declared as a viewscoped as
an additional information)
Thanks for all help..
You could make the bean #SessionScoped. That means that only one instance will be created by browser session, so when you get back you get the last state.
Of course, session scoped means that when you get back to the view even if it is not a "back" navigation, that info will still be there.
I'm trying to get some data from a datatable in rich:modal panel
The whole flow is as follows
When clicking on search button on main page, a modal panel pops up with appropriate data & check box
Till this point the application is working fine
After clicking on ok button, selected data should be populated into main page. This is where the code fails
I tried stuff like getRowData, getValues, etc. but in vain. This could be done by keeping the bean in session scope but I have to keep this bean in request scope using Apache MyFaces JSF 1.2
Two ways comes to mind:
Pass an extra request parameter (the search string and the page number?) so that the bean knows which data to preload.
Make use of MyFaces Orchestra to create a conversation scope which lies in between request and session scope and is exactly the scope you're looking for this particular functional requirement.