So far JasperReports has been an excellent tool.
I'm interested in finding out if it is possible to use LoggedInUser within a Single Select Query input control.
Please see the attached image, this may give you an idea of what I'm trying to accomplish.
Thanks in advance,
Ben
Post edited by: bpienig, at: 2007/10/01 15:34
17 Answers:
Here's the file, that I was trying to attach. [file name=loggedinuser.jpg size=51669]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/log...
Regards,
Lucian
Regards,
Lucian
Thanks for the info Lucian.
Ben
lucianc wrote:
I see now that there already exists a feature request for this (see [url=http://jasperforge.org/sf/go/artf2176?nav=1]artf2176). Regards, Lucian |
I have created a patchy implementation for this feature with no needs for recompiling the code - just modifying DefaultParametersForm.jsp file.
Let me post my approach for those interested...
Step 1: Create a non-visible inputControl (SingleValue - string) called USER.
Step 2: Add reference to acegi taglib at the beginning of DefaultParametersForm.jsp file.
<%@ taglib uri="http://acegisecurity.org/authz" prefix="authz"%>
Step 3: Search this file for this code...
<c:if test="${!control.visible}">
<input type="hidden" name="${inputName}" value="${wrapper.formattedValue}"/>
</c:if>
...and substitute it with this fragment...
<c:if test="${!control.visible}">
<c:choose>
<c:when test="${control.name=='USER'}">
<input type="hidden" name="${inputName}" value="<authz:authentication operation="username"/>"/>
</c:when>
<c:otherwise>
<input type="hidden" name="${inputName}" value="${wrapper.formattedValue}"/>
</c:otherwise>
</c:choose>
</c:if>
I hope this is useful for those in a hurry...
It would be great to have an official implementation for this feature in the future.
Best regards,
P.S.- I'll be out of office for two weeks. Read you in September.
I have created a patchy implementation for this feature with no needs for recompiling the code - just modifying DefaultParametersForm.jsp file. |
Hey sergio,
That's not quite what I was looking for, I'm looking at being able to use the LoggedInUser in the SQL of the multiple-input control.
If you want to use the LoggedInUser in the report, just take a look at the SalesByMonth sample report. It uses the LoggedInUser as a parameter.
Thanks,
Ben
It involved editing the EngineServiceImpl.java file.
Previous Code
Code: |
public OrderedMap executeQuery(ExecutionContext context, <br /> ResourceReference queryReference, String keyColumn, String[] resultColumns, <br /> ResourceReference defaultDataSourceReference) {<br /> Query query = (Query) getFinalResource(context, queryReference);<br /> <br /> ResourceReference dataSourceReference = query.getDataSource();<br /> if (dataSourceReference == null) {<br /> dataSourceReference = defaultDataSourceReference;<br /> }</td></tr></tbody></table><br /> <br /> <br /> Edited Code<br /> <br /> <table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"><tbody><tr><td><b>Code:</b></td></tr><tr><td><pre> public OrderedMap executeQuery(ExecutionContext context, <br /> ResourceReference queryReference, String keyColumn, String[] resultColumns, <br /> ResourceReference defaultDataSourceReference) {<br /> Query query = (Query) getFinalResource(context, queryReference);<br /> <br /> String userName = getSecurityContextProvider().getContextUser().getUsername();<br /> String queryStr = query.getSql().replace("$P{LoggedInUsername}",userName);<br /> query.setSql( queryStr );<br /> <br /> ResourceReference dataSourceReference = query.getDataSource();<br /> if (dataSourceReference == null) {<br /> dataSourceReference = defaultDataSourceReference;<br /> }</td></tr></tbody></table><br /> <br /> If you add $P{LoggedInUsername} to an input control query, it will replace it with the current logged in user name.<br /> <br /> It's a hack, but at least it works for now.<br>Post edited by: bpienig, at: 2007/09/27 22:42 |
lucianc
Wrote:
I see now that there already exists a feature request for this (see [url=http://jasperforge.org/sf/go/artf2176?nav=1]artf2176). Regards, Lucian |
The link you gave seems to be broken. Can you provide the working link that would point to the feature request? Thanks!
The updated link is http://jasperforge.org/tracker/index.php?func=detail&aid=1315&group_id=112&atid=376&action=edit.
This has not been implemented in 3.1, but we plan to include in the next release.
Regards,
Lucian
I wonder if I someone could give me the resulting compiled .jar file and then I could just drop it into my server lib files - I'm having no luck whatsoever in building jasperserver after making the changes to the java file. Maven2 , POMs, repos, getting that all to work will take (me) weeks.
Thanks in advance.
And, why not just add it to the next release - the workaround seems quite useful and its only a few lines. Why has this request been sitting there so long (since 3.1?)
$P{LoggedInUsername} can be used in input control queries starting with JasperServer 3.5.
Regards,
Lucian
PS: Please post any further queries related to JasperServer on the JasperServer forum.