Liferay 6.2 polls results restrictions to Admin Users - liferay

I m using Liferay 6.2. in Polls Display Portlet after question is answered the polls result is displayed for all users . can we restrict the polls results to only admin users.
i m aware that some minor customization is required in \html\portlet\polls_display\view.jsp file at line 94 in this line <%# include file="/html/portlet/polls/view_question_results.jspf" %>. but not sure how to achieve the expected results. so, can anybody please help me how to achieve this.
thanks in advance

With the below code, one can restrict the Polls results to admin users only:
<c:choose>
<c:when test="<%= PollsQuestionPermission.contains(permissionChecker, question, ActionKeys.UPDATE) %>">
<%# include file="/html/portlet/polls/view_question_results.jspf"%>
</c:when>
<c:otherwise>
<br />
<div>
<b><i>Thank You For Your Response</i></b>
</div>
</c:otherwise>
</c:choose>

Related

JSF too many commandLinks (h:form) lead to ViewExpiredException

I am having a JSF application which creates and presents about 50 reports. These reports are rendered PNGs and under the pictures a table is displayed.
This table uses a RichFaces 4 togglePanel with switchType="client". The togglePanel is just for collapsing and expanding the table.
<h:form>
<rich:togglePanel id="#{param.reportWrapper}_togglePanel"
stateOrder="opened,closed" activeItem="opened" switchType="client">
<rich:togglePanelItem name="closed">
<h:panelGroup>
<div class="myclass">
<ul class="container-icons">
<li>
<h:commandLink styleClass="container-max" value="maximieren">
<rich:toggleControl targetPanel="#{param.reportWrapper}_togglePanel" targetItem="#next" />
</h:commandLink>
</li>
</ul>
<h3>My Heading</h3>
</div>
</h:panelGroup>
</rich:togglePanelItem>
<rich:togglePanelItem name="opened">
<h:panelGroup>
<div class="myclass">
<ul class="container-icons">
<li>
<h:commandLink styleClass="container-min" value="minimieren">
<rich:toggleControl targetPanel="#{param.reportWrapper}_togglePanel" targetItem="#prev" />
</h:commandLink>
</li>
</ul>
<h3>Another Heading</h3>
<div class="scrolling-table-content">
<rich:dataTable>
// ...
</rich:dataTable>
</div>
</div>
</h:panelGroup>
</rich:togglePanelItem>
</rich:togglePanel>
</h:form>
The problem is, that I sometimes get a ViewExpiredExceptions when the reports are loaded. My numberOfLogicalViews and numberOfViewsInSession is 14. I dont want to set it to 50, because of memory issues and because it should not be necessary as only one report is really shown at the same time.
I tried to remove the h:form tags, which are seen as logicalView. In my opinion the togglePanel is not the item, which needs the form because it's switch type is client (not server and ajax, which need form tags). But the command link does need the form tag, because if I remove it, an error occurs saying "this link is disabled as it is not nested within a jsf form".
So I tried to replace the commandLink with a commandButton. This worked fine first and the form wasnt necessary anymore. But somehow the behaviour is completely random now. Sometimes the tables can be expanded, sometimes nothing happens when i click the expand button. When i add form tags again, it works fine, but doesnt solve my ViewExpiredException.
Hope, somebody can help me out here...
Thanks for your help!
Buntspecht
If you only need to switch the panel you can use <a4j:commandLink> that lets you limit the execution scope (so it won't submit the whole form). Or you can remove the command components altogether and just use JavaScript API of the togglePanel:
<a onclick="#{rich:component('panelId')}.switchToItem(#{rich:component('panelId')}.nextItem())">Next</a>
Thank you very much for your help Makhiel. I finally managed to solve the problem with the commandButtons solution. I can't explain why, but the IDs of my togglePanelItems got duplicated in the different reports.
Giving every togglePanelItem a unique ID like
<rich:togglePanelItem name="closed" id="#{param.reportWrapper}_opened">
and
<rich:togglePanelItem name="opened" id="#{param.reportWrapper}_closed">
solved the problem...
So now we got rid of all the h:form tags and thus have about 50 logical views less! :)

Disabling items in JavaServer Faces

I’m new in JavaServer Faces.
I have a simply form:
<div id="respond" class="comment-respond">
<h3 id="reply-title" class="comment-reply-title">#{msgs.leavereply}</h3>
<h1>#{!forumsBean.activeWithProject}</h1>
<h:form>
<h:inputTextarea value="#{forumpostsBean.text}" style="resize:none"/>
<h:commandButton value="#{msgs.add}" action="#{forumpostsBean.addForumpost}"/>
</h:form>
</div>
By clicking command button all it’s fine, executes method forumpostsBean.addForumpost.
But when I modify code to this:
<div id="respond" class="comment-respond">
<h3 id="reply-title" class="comment-reply-title">#{msgs.leavereply}</h3>
<h1>#{!forumsBean.activeWithProject}</h1>
<h:form>
<h:inputTextarea value="#{forumpostsBean.text}" style="resize:none" disabled="#{not forumsBean.active}"/>
<h:commandButton value="#{msgs.add}" action="#{forumpostsBean.addForumpost}" disabled="#{not forumsBean.active}"/>
</h:form>
</div>
When items not disabled, current page only have refreshed, but method forumpostsBean.addForumpost don’t executes.
In both variants, <h1>#{!forumsBean.activeWithProject}</h1> shows correct value.
You have 2 beans? one called forumpostsBean and another just forumsBean? I can't see if you've got them both but maybe its the main error? as the comment above says, maybe your logic is out of place.
You may want to use rendered="" on the button rather that just disabling it so its not part of the dom at all upon page load and then use an ajax call when you type data in your input field to do partial ajax render the div again and show it. good for testing.

How can I get the values submitted from a JSP in Liferay?

I am using Liferay Portal 6 version.
How can I get the UserName and Password values with in the same page?
<%# taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%#page import="javax.portlet.RenderRequest"%>
<portlet:defineObjects />
This is the <b>Kiran</b> portlet.
<form>
<p><b>UserName:</b> <input type="text" name="UserName" size="10"></p>
<p><b>Password:</b> <input type="Password" name="Password"
size="10"></p>
<p><input type="submit" value="Submit" name="submit"><input type=
"reset" value="Reset" name="reset"></p><hr><hr>
</form>
<%
// here
%>
I'm not sure if its submitting the values correctly as your form has no target and is not refering to a portlet action url.
This tutorial shows some basic usage and parameter retrieval. Check the JSP portlet section. You should be able to access the request object in your jsp as well.
I wouldn't start writing JSP portlets. Its quite outdated nowadays. Check Spring Portlet MVC or even consider JSF.
In a portal/portlet all identifiers must be properly namespaced - you never know what other content ends up on the same html document with you. Thus a form control should rather read:
<input type="text" name="<portlet:namespace/>user" .../>
in order to be able to retrieve the parameter as "user" from the request.
If, in Liferay 6, you use the AlloyUI taglibs, a lot of this namespacing is done automatically for you.
Also, you should add the portlet action URL as Udo Held suggests:
<form action="<portlet:actionURL/>">
What are you trying to get ? Do you want to get the username and password in some other .java file or .jsp file ?? Or do you want to get the username and password once a user logs in ?
If you are trying to get user details set in present jsp page in some other .java or .jsp, then simply use the PortletSession.
Eg: From jsp
PortletSession portletSession = actionRequest.getPortletSession();
portletSession.setAttribute("liferayUserMap", liferayUserMap,PortletSession.APPLICATION_SCOPE);
From .java/.jsp
PortletSession portletSession = actionRequest.getPortletSession();
portletSession.getAttribute("liferayUserMap",PortletSession.APPLICATION_SCOPE);
By doing so, you can share the data among different files in different portlets too.
For case 2: If you are trying to get the user details, simply do the following:
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
themeDisplay.getUser();
I hope you are following the portlet structures while coding, otherwise the above mentioned code wouldn't work. Since you have to point to some action class, in the 'struts-config' and 'tiles-def'

JSF navigate to external url using image button

Simple question (using JSF 2.0 and primefaces 2.2.1):
I need to create a button or link that will take me to an external url (i.e. www.facebook.com) and I need that button to look like the facebook icon instead of having the literal word. How can I do this? Thank you.
You basically want to end up with the following in the JSF-generated HTML code:
<a><img /></a>
There are several ways how to achieve this in JSF.
Just do it:
<a href="http://www.facebook.com">
<img src="#{request.contextPath}/resources/images/facebook.png" />
</a>
Use <h:graphicImage>:
<a href="http://www.facebook.com">
<h:graphicImage name="images/facebook.png" />
</a>
Eventually, with <h:outputLink>:
<h:outputLink value="http://www.facebook.com">
<h:graphicImage name="images/facebook.png" />
</h:outputLink>
What way to choose depends on whether you really need it to be a JSF component. E.g. in order to be able to grab/manupulate it in backing bean, and/or to re-render by ajax, etc.

The <t:message> doesn't display properly when using <t:inputFileUpload> inside <t:PanelTabbedPane>

In a JSP page, I created a <h:form enctype="multipart/form-data"> with some elements: <t:inputText>, <t:inputDate>, etc. Also, I added some <t:message for="someElement"> And I wanted to allow the user upload several files (one at a time) within the form (using <t:inputFileUpload> ) At this point my code works fine.
The headache comes when I try to put the form inside a <t:panelTabbedPane serverSideTabSwitch="false"> (and thus of course, inside a <t:panelTab> )
I copied the structure shown in the source code for TabbedPane example from Tomahawk's examples, by using the <f:subview> tag and putting the panelTab tag inside a new jsp page (using <jsp:include page="somePage.jsp"> directive)
First at all, the <t:inputFileUpload> fails to load the file at the value assigned in the Managed Bean UploadedFile attribute #{myBean.upFile}
Then, googling for a clue, I knew that <t:panelTabbedPane> generates a form called "autoform", so I was getting nested forms. Ok, I fixed that creating the <h:form> out of the <t:panelTabbedPane> and eureka! file input worked again! (the autoform doesn't generate)
But, oh surprise! oh terrible Murphy law! All my <h:message> begins to fail. The Eclipse console's output show me that all <t:message> are looking for nonexistents elements ID's (who have their ID's in part equals to they are looking for, but at the end of the ID's their names change)
At this point, I put a <t:mesagges> tag (note the "s" at the end) to show me all validation errors at once at the beginning of the Panel, and it works fine. So, validation errors exists and they show properly at the beginning of the Panel.
All validation error messages generated in this page are the JSF built-in validation messages. The backing bean at this moment doesn't have any validators defined.
¿How can I get the <t:message for="xyz"> working properly?
I'm using Tomahawk-1.1.6 with myFaces-impl-1.2.3 in a eclipse Ganymede project with Geronimo as Application Server (Geronimo gives me the myFaces jar implementation while I put the tomahawk jar in the WEB-INF/lib folder of application)
"SOLVED": This problem is an issue reported to myFaces forum.
Thanks to Kyle Renfro for the soon response and information. (Good job Kyle!)
See the issue
EDIT 1
1.- Thanks to Kyle Renfro for his soon response. The forceID attribute used inside the input element doesn't works at first time, but doing some very tricky tweaks I could make the <t:message for="xyz"> tags work.
What I did was:
1. Having my tag <inputText id="name" forceId="true" required="true"> The <t:message> doesn't work.
2. Then, after looking the error messages on eclipse console, I renamed my "id" attribute to this: <inputText id="namej_id_1" forceId="true" required="true">
3. Then the <t:message> worked!! but after pressing the "Submit" button of the form the second time. ¡The second time! (I suspect that something is going on at the JSF lifecycle)
4. This implies that the user have to press 2 times the submit button to get the error messages on the page.
5. And using the "j_id_1" phrase at the end of IDs is very weird.
EDIT 2
Ok, here comes the code, hope it not be annoying.
1.- mainPage.jsp (here is the <t:panelTabbedPane> and <f:subview> tags)
<%# taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%# taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%# taglib prefix="t" uri="http://myfaces.apache.org/tomahawk"%>
<html>
<body>
<f:view>
<h:form enctype="multipart/form-data">
<t:panelTabbedPane serverSideTabSwitch="false" >
<f:subview id="subview_tab_detail">
<jsp:include page="detail.jsp"/>
</f:subview>
</t:panelTabbedPane>
</h:form>
</f:view>
</body>
</html>
2.- detail.jsp (here is the <t:panelTab> tag)
<%# taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%# taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%# taglib prefix="t" uri="http://myfaces.apache.org/tomahawk"%>
<t:panelTab label="TAB_1">
<t:panelGrid columns="3">
<f:facet name="header">
<h:outputText value="CREATING A TICKET" />
</f:facet>
<t:outputLabel for="ticket_id" value="TICKET ID" />
<t:inputText id="ticket_id" value="#{myBean.ticketId}" required="true" />
<t:message for="ticket_id" />
<t:outputLabel for="description" value="DESCRIPTION" />
<t:inputText id="description" value="#{myBean.ticketDescription}" required="true" />
<t:message for="description" />
<t:outputLabel for="attachment" value="ATTACHMENTS" />
<t:panelGroup>
<!-- This is for listing multiple file uploads -->
<!-- The panelGrid binding make attachment list grow as the user inputs several files (one at a time) -->
<t:panelGrid columns="3" binding="#{myBean.panelUpload}" />
<t:inputFileUpload id="attachment" value="#{myBean.upFile}" storage="file" />
<t:commandButton value="ADD FILE" action="#{myBean.upload}" />
</t:panelGroup>
<t:message for="attachment" />
<t:commandButton action="#{myBean.create}" value="CREATE TICKET" />
</t:panelGrid>
</t:panelTab>
EDIT 3
On response to Kyle Renfro follow-up:
Kyle says:
"At the first view of the page, if you press the "CREATE TICKET" button with nothing in any of the inputTexts and no files uploaded, do the message tags work for the inputTexts? (ie. required = true) I'm just curious if the messages for the inputTexts are working but the message for the inputFileUpload is not."
Here is the behavior found:
1.- There is no validation error messages shown at all (the message tags don't work) Even when I try to test only one validation error message (for example, testing the message for the first input text) none of them shows up.
2.- The eclipse console shows me these internal errors:
ERROR [HtmlMessageRendererBase] Could not render Message. Unable to find component 'ticket_id' (calling findComponent on component 'j_id_jsp_1383779881_1:subview_tab_detail:j_id_jsp_1716158401_0j_id_1:j_id_jsp_1716158401_5j_id_1'). If the provided id was correct, wrap the message and its component into an h:panelGroup or h:panelGrid.
ERROR [HtmlMessageRendererBase] Could not render Message. Unable to find component 'description' (calling findComponent on component 'j_id_jsp_1383779881_1:subview_tab_detail:j_id_jsp_1716158401_0j_id_1:j_id_jsp_1716158401_8j_id_1'). If the provided id was correct, wrap the message and its component into an h:panelGroup or h:panelGrid.
ERROR [HtmlMessageRendererBase] Could not render Message. Unable to find component 'attachment' (calling findComponent on component 'j_id_jsp_1383779881_1:subview_tab_detail:j_id_jsp_1716158401_0j_id_1:j_id_jsp_1716158401_14j_id_1'). If the provided id was correct, wrap the message and its component into an h:panelGroup or h:panelGrid.
Here is when I saw the "j_id_1" word at the generated IDs, for example, for the id "ticket_id":
j_id_jsp_1383779881_1:subview_tab_detail:j_id_jsp_1716158401_0j_id_1:j_id_jsp_1716158401_5j_id_1
And, viewing the resulting HTML generated page, I saw that the IDs names are like this (whitout using "ForceId" atribute):
<input id="j_id_jsp_1383779881_1:subview_tab_detail:j_id_jsp_1716158401_0j_id_1:ticket_idj_id_1" name="j_id_jsp_1383779881_1:subview_tab_detail:j_id_jsp_1716158401_0j_id_1:ticket_idj_id_1">
The forceId attribute of the tomahawk components should solve this problem.
something like:
<t:outputText id="xyz" forceId="true" value="#{mybean.stuff}"/>
At the first view of the page, if you press the "CREATE TICKET" button with nothing in any of the inputTexts and no files uploaded, do the message tags work for the inputTexts? (ie. required = true) I'm just curious if the messages for the inputTexts are working but the message for the inputFileUpload is not.
Looks like it may be related a bug in myfaces. There is a newer version of myfaces and tomahawk that you might try. I would remove the subview functionality as a quick test - copy the detail.jsp page back into the main page.
https://issues.apache.org/jira/browse/MYFACES-1807?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12567158#action_12567158

Resources