request.getParameter is undefined in Application Display Termplate? - liferay

I am using Liferay 6.2 and I am trying to read request parameters in my Application Display Template (freemarker) like this:
<#assign myvalue = request.getParameter("param")/>
But all I get is:
Error on line 5, column 1 in 10154#10194#11902
request.getParameter("param") is undefined.
It cannot be assigned to myvalue.
Does anyone know how to solve this ? The built-in editor itself and its code completion told me everything is fine ;)

Pankaj Kathiriya was right :)
The answer is :
<#if (request.getParameter("param")?has_content && request.getParameter("param")?lower_case?matches("true"))>
<#assign useServer = "http://bing.com">
<#else>
<#assign useServer = "http://google.com">

Related

Row data var not found if view has no document

I have a view panel where I want to style the color the of text in the row based on a value in the document.
<xp:viewPanel id="dataView1" var="rowData" rows="5"
rowClasses="#{javascript:rowData.getColumnValue('objectStatus') == 'Inactive' ? 'status-inactive' : ''}">
This works perfectly fine if the view has at least one document, but if the view is empty I get the following error:
com.ibm.xsp.exception.EvaluationExceptionEx: Error while executing JavaScript computed expression
Error while executing JavaScript computed expression
Script interpreter error, line=1, col=10: [ReferenceError] 'rowData' not found
I'm guessing it has something to do with rowData not being created unless a document exist, but I can't figure out how to check for it.
I tried if (rowData != null) and !#IsNull(rowData) but I still get the same error.
How do I solve this problem?
(Note that I am late to the XPages game.)
EDIT:
Thanks to all for the input but I was able to solve the issue by simply checking the view count:
if (getComponent('dataView1').getRowCount() > 0) {
'Inactive'.equals(rowData.getColumnValue('objectStatus')) ? 'status-inactive' : ''
}
EDIT 2:
Knut has a slightly quicker solution so I gave him credit.
You can test it with if (typeof rowData !== 'undefined') ....
If the view is empty then rowData is 'undefined'.
<xp:viewPanel id="viewPanel1" var="rowData" rows="5"
rowClasses="#{javascript:
if (typeof rowData !== 'undefined')
rowData.getColumnValue('objectStatus') == 'Inactive' ? 'status-inactive' : ''
}">
(This solution is probably some ms faster than .getRowCount() :-) )
Knut correctly explains the solution to what you're trying to do. The answer to why it doesn't work is slightly different. rowData was an apt name to choose, it's going to be the current row's data. But you're setting a property for the DataView as a whole. What is the current row for the whole DataView? The answer is, there isn't one because you're not dealing with an individual row.

Default Date set to yesterday in DATE prompt in COGNOS 11.0.6

I have tried the below java script code but it's not working in COGNOS 11.
<script language="javascript">
var dDate = new Date();
dDate.setDate(dDate.getDate()-1);
pickerControlName.setValue(getFormatDate(dDate, 0 , 'YMD'));
</script>
Is there any other way I can set it to default ??
You are not using the Cognos Prompt API. You can see a tutorial on how to do what you want with the API here: Setting Prompt Defaults Dynamically
I have tried achieving this with JS however I would recommend using the base cognos filter screen.Try the following.
1) Assign a parameter name to the date prompt 'DATE_FILTER'. So on Query explorer-Detail Filters you would do cast(YOUR_DATE_FIELD,date) = ?DATE_FILTER?.
NOTE - Make Usage optional.
2) Now create 2 data item named 'START_DATE' AND 'END_DATE'.
START_DATE expression :
case when #prompt('DATE_FILTER','date','null')# = null then cast(_add_days(current_date,-1),date) else cast(_add_days(current_date,-30000),date) end
END_DATE expression :
case when #prompt('DATE_FILTER','date','null')# = null then cast(_add_days(current_date,-1),date) else cast(_add_days(current_date,30000),date) end
3) Then add below to Summary filter expression :
cast([YOUR_DATE_FIELD],date) between [START_DATE] and [END_DATE]
This should create effect similar to GROUP BY YOUR_DATE_FIELD HAVING TRUNC(YOUR_DATE_FIELD) = SYSDATE-1 when parameter 'DATE_FILTER' is null.
You could also achieve this by directly inserting #prompt()# clause into the Manual SQL.
I am new to Cognos javascript and needed to dynamically set a Date prompt. I found a way to do it.
If you change your code to look something like this:
var dDate = new Date();
dDate.setDate(dDate.getDate()-1);
var pickerControlObject = oPage.getControlByName( "pickerControlName" );
pickerControlObject.setValues([{use: dDate.toISOString().slice(0,10)}]);
This worked for me in Cognos 11. I was using the '.js module' method not the 'HTML item' method

How to Assign Null or "Empty" Values to Freemarker Time Variables?

I'm using Freemarker to build a Liferay Application Display Template. The Template uses a loop to iterate over a Set of Entities (Journal Articles). The Template uses several Variables of Type Date and Time. How may I reset these Variables or check for "empty" in each Iteration of the Loop?
Let's say we have this Code inside the Loop, and it's possible that "starthour" may be empty in some Interations of the Loop:
<#assign xPathSelector = saxReaderUtil.createXPath("dynamic-element[#name='start_hour']") />
<#assign starthour = xPathSelector.selectSingleNode(rootElement).getStringValue()?trim />
<#assign xPathSelector = saxReaderUtil.createXPath("dynamic-element[#name='start_minutes']") />
<#assign startminutes = xPathSelector.selectSingleNode(rootElement).getStringValue()?trim />
<#if starthour!="">
<#assign startTimeString= starthour +":"+startminutes>
<#assign starttime = startTimeString?time["HH:mm"]>
<#else>
<#assign starttime = 0>
</#if>
In this Example I've set starttime to 0, but I've also tried to set it as empty String when starthour is empty.
I already tried these Methods to check for the "empty" Variable:
<#if (starttime >0) >
<#if starttime.has_content>
<#if starttime!="">
I can't check
<#if starttime??>
after the Variable has once been set in my Loop. Whatever I try I always get Errors like this one, when I use my Script in Liferay:
The only legal comparisons are between two numbers, two strings, or two dates.
Left hand operand is a freemarker.template.SimpleDate
Right hand operand is a freemarker.template.SimpleNumber
So how do I "reset" a Time Variable or set an "empty" Value for it, and how to check for an empty (but not Null) Time Value?
You can't unset values (and if you could, reading it would fall back to the higher scope, which can later lead to bugs if such variable appears in the data-model). So you either has to introduce a boolean startTimeSet variable, or you have to chose a special empty value. As there's no "natural" empty value for time values, you could just use "" and then before doing anything with it, check the value with ?has_content.

Show custom message without time prefix in <p:schedule>?

I would like to show a custom message in <p:schedule>. It shows the message with time prefix, e.g. "12a CycDemo".
How can I show only "CycDemo" without time prefix? I'm adding it as follows:
model.addEvent(new DefaultScheduleEvent("CycDemo", fromDate, toDate));
I get one solution. It will not be good solution because of I still cannot find another way.
When I debug the html content on the browser by the developer tool, I found the following code.
....
<span class="fc-event-time">12a</span>
<span class=".....">CycDemo</span>
...
That's why, I solve it by CSS display:none.
.fc-event-time {
display: none;
}
Now, I can only see my expected message without time prefix :)
You have to add an empty timeFormat attribute in <p:schedule> then the prefix will disappear.
<p:schedule id="schedule" value="#{scheduleView.eventModel}" widgetVar="myschedule" timeFormat="">
Set AllDay to true of DefaultScheduleEvent
DefaultScheduleEvent d = new DefaultScheduleEvent();
d.setAllDay(true);
eventModel.addEvent(d)

Magento - Change attribute select to dropdown list in Adv Search

I've been trying to find a way of forcing an attribute to show as a dropdown rather than a block of options but had no luck. The code current looks like this:
case 'select': ?>
<div class="input-box"> <?php echo $this->getAttributeSelectElement($_attribute) ?> </div>
<?php endswitch; ?>
Does anyone know how to make this look like a dropdown list instead?
Thanks in advance
I had the same problem earlier today and the strangest thing was that I had the attributes (drop down) with the same properties but one displaying a drop down menu and the other a multi select menu in the advanced search.
I did some testing with different settings and it turned out that in the advanced search every attribute that is a list (drop down and multi-select) and it has more than 2 options is displayed as multi-select.
I had a look at Mage_CatalogSearch_Block_Advanced_Form stored in /app/code/core/Mage/CatalogSearch/Block/Advanced/Form.php and I saw where this condition of 2 is checked. The magento core team made it like this to make sure that the 'yesno' or boolean list are displayed as dropdown.
In the above mentioned file, starting from line 173 (on the current version of magento)
is the following code:
public function getAttributeSelectElement($attribute)
{
$extra = '';
$options = $attribute->getSource()->getAllOptions(false);
$name = $attribute->getAttributeCode();
// 2 - avoid yes/no selects to be multiselects
if (is_array($options) && count($options)>2) {
. . .
If you change the number two on the last line with the number 5, advanced search will display drop down menu on every attribute that has less than 6 options.
What I did for myself is I added a new method, getAttributeDropDownElement(), bellow getAttributeSelectElement() that looks like this:
public function getAttributeDropDownElement($attribute)
{
$extra = '';
$options = $attribute->getSource()->getAllOptions(false);
$name = $attribute->getAttributeCode();
// The condition check bellow is what will make sure that every
// attribute will be displayed as dropdown
if (is_array($options)) {
array_unshift($options, array('value'=>'', 'label'=>Mage::helper('catalogsearch')->__('All')));
}
return $this->_getSelectBlock()
->setName($name)
->setId($attribute->getAttributeCode())
->setTitle($this->getAttributeLabel($attribute))
->setExtraParams($extra)
->setValue($this->getAttributeValue($attribute))
->setOptions($options)
->setClass('multiselect')
->getHtml();
}
The next thing you need to do is a small if statement within the switch of the form (see bellow) that will check the name of the attribute and base on that to call either getAttributeSelectElement() or our new method getAttributeDropDownElement(). I leave this job to you :)
case 'select': ?>
<div class="input-box"> <?php echo $this->getAttributeSelectElement($_attribute) ?> </div>
<?php endswitch; ?>
Sorry for my English...i'm french ;-)
In your admin panel, you can choose the type of your Attributes
Make sure that your attribute is declared as a list. In my Magento version, it's the third information in the attribute admin panel after code and scope.
PoyPoy
Magento has a class for generating selects available as a Mage_Core_Block_Html_Select class (/app/code/core/Mage/Core/Block/Html/Select.php).
On your design template directory template/catalogsearch/advanced/form.phtml, replace
echo $this->getAttributeSelectElement($_attribute);
With
echo $this->getLayout()->createBlock('core/html_select')
->setOptions( $_attribute->getSource()->getAllOptions(true))
->setName($_attribute->getAttributeCode())
->setClass('select')
->setId($_attribute->getAttributeCode())
->setTitle($this->getAttributeLabel($_attribute))
->getHtml();

Resources