How to get list/details url in Composite C1? - c1-cms

I build menu links so I need to know where I am.
The list url looks like: http://domain.com/list
The detail page url looks like: http://domain.com/list/detail
I could search for hardcoded /list part but it will be hardcoded.
I use the PathInfo function below and I always use 0 as parameter:
string PathInfo (int segment)
{
string pathInfo = C1PageRoute.GetPathInfo()??string.Empty;
string[] segments = pathInfo.Split('/');
string stringValue;
stringValue = segments.Skip(segment + 1).FirstOrDefault();
return stringValue;
}
...
// register the use of the path info
C1PageRoute.RegisterPathInfoUsage();
string kuruladi = PathInfo(0);
...
#foreach (var kurul in kurullar)
{
string currentpageitem = "";
if (kurul.KurulAdi == kuruladi)
{
currentpageitem = "current_page_item";
}
<li class="page_item page-item-1167 #currentpageitem">
#kurul.KurulAdi
</li>
}
Since I don't know where I am (list or detail) PathInfo(0) cannot help. An incorrect example link: http://domain.com/Sample-Detail-Page It should be http://domain.com/Kurul/Sample-Detail-Page
How can I write a much generic code to extract the exact location and then build the correct link? At least am I in list or detail, so I can use 0 or 1 as parameter.

#CurrentPageNode.Url was the missing part:
<li class="page_item page-item-1167 #currentpageitem">
#kurul.KurulAdi
</li>

Related

Azure Search - querying for ampersand character

I'm trying to find all records which contain & symbol, which is reserved. I'm using search, not $filter.
According to documentation, it can not be escaped with \%, and should be escaped as HTML url part to %26.
Trying SDK and Search explorer to find any options on how to search, but with no succeed:
&
*&*
*%26*
%26
\%26
UPD
Document example:
{
"test": "Hello & World"
Search query: search=%26&searchFields=test&$select=test
UPD 2
public class MyType
{
[System.ComponentModel.DataAnnotations.Key]
[IsFilterable]
public string Id { get; set; }
[IsSearchable, IsSortable]
public string Test { get; set; }
}
class Program
{
private static SearchServiceClient CreateSearchServiceClient()
{
string searchServiceName = "XXXXXX";
string adminApiKey = "XXXXXXX";
var serviceClient = new SearchServiceClient(searchServiceName, new SearchCredentials(adminApiKey));
return serviceClient;
}
static void Main(string[] args)
{
var client = CreateSearchServiceClient();
var def = new Microsoft.Azure.Search.Models.Index
{
Name = "temp-test-reserved1",
Fields = FieldBuilder.BuildForType<MyType>()
};
client.Indexes.Create(def);
var c = client.Indexes.GetClient("temp-test-reserved1");
var actions = new IndexAction<MyType>[]
{
IndexAction.Upload(new MyType{ Id = "1", Test = "Hello & World" }),
IndexAction.Upload(new MyType{ Id = "2", Test = "& test start" }),
IndexAction.Upload(new MyType{ Id = "3", Test = "test end &" })
};
c.Documents.Index(IndexBatch.New(actions));
}
}
search=%26&searchFields=Test&$select=Test
You likely can't find & because it's being removed at indexing and query time, since it's considered to be punctuation by the default analyzer. This article has more details on lexical analysis in Azure Cognitive Search. If you need to preserve ampersands while still tokenizing text on whitespace boundaries, you'll need to create a custom analyzer.
In the search explorer field on the Azure portal try the query &search=%26(as shown below)
In the SDK, only if you have set the UseHttpGetForQueries parameter to true, you would need to think of URL encoding the '&' character. By default, this parameter is set to false in which case you don't need to encode it.
More documentation about escaping/encoding here

TYPO3 returns "Array" to Fluid as String

I try to pass an array within my Viewhelper to the Fluidtemplate.
It always shows the string "Array". If I try to use it as parameter in the f:for each viewhelper, I get an exception because it is a string and not an array.
I used Typo3 6.2 before, now I have Typo3 7 and it stopped working.
public function render($uids) { // $uids='901,902,903'
$uidArray = explode(',', $uids);
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
$repository = $objectManager->get('XXX\\X\\Domain\\Repository\\FooRepository');
$query = $repository->createQuery();
$query->getQuerySettings()->setRespectStoragePage(FALSE);
$query->matching(
$query->in('uid', $uidArray)
);
return $query->execute()->toArray();
}
This is my Fluid template:
{namespace vh=My/Namespace/ViewHelpers}
<f:for each="{vh:GetArray(uids: '901,902,903')}">...</f:for>
You cannot return an array with your viewhelper, because viewhelper always return strings.
You can however introduce a new variable to the current render context and then use this variable inside your viewhelper.
public function render() {
$returnArray = array('a' => 17, 'b' => 42);
$this->templateVariableContainer->add('returnArray', $returnArray);
$output = $this->renderChildren();
$this->templateVariableContainer->remove('returnArray');
return $output;
}
Inside your template you can then run a for loop over {returnArray}.
Try a combination of f:for and f:cycle in your Fluid template. See the f:cycle examples in the Fluid ViewHelper Reference.

How to skip the locator which does not exist in selenium webdriver?

I have around 50 rows in a page. But those items are in sequence.
The problem is when someone entered and deleted that table row. That id would not be there in page..
Example:
User added 1st record: id 101 added.
User added 2nd record: id 102 added
User added 3rd record: id 103 added.
If user deletes 2nd record, then two records would be there on the page but with id 101, 103.
I am trying to write that if that id is present then get the text else leave that in the for loop. I am getting only records till it found if that id is not found getting NoSuchElementException is displayed.
Please correct the code. But i want to the solution that if that id not exist, skip and run the else part.
for (int i = counterstart; i <= counterend; i++) {
if(driver.findElement(By.xpath("//*[#id='" + i + "']/a")).isDisplayed()){
System.out.println(i+" is present");
String Projects = driver.findElement(By.xpath("//*[#id='" + i + "']/a")).getText();
System.out.println(Projects);
} else{
System.out.println(i+" is NOT present");
}
}
The exception that I get:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to find element with xpath == //*[#id='7593']/a (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 503 milliseconds
Try this method isPresent instead of isDisplayed.
public boolean isPresent(WebElement e) {
boolean flag = true;
try {
e.isDisplayed();
flag = true;
}
catch (Exception e) {
flag = false;
}
return flag;
}
How about this:
for (int i = counterstart; i <= counterend; i++) {
WebElement element;
try{
element = driver.findElement(By.xpath("//*[#id='" + i + "']/a"));
}catch(NoSuchElementException n)
{
element = null;
}
if(element !=null){
System.out.println(i+" is present");
String Projects = driver.findElement(By.xpath("//*[#id='" + i + "']/a")).getText();
System.out.println(Projects);
}else{
System.out.println(i+" is NOT present");
}
}
Find all the parent of all the elements you want to get the text from and use it to drill down, this way you won't get the exception
Assuming the html looks like this
<div id="parent">
<div id="11">
<a>text</a>
</div>
<div id="12">
<a>text</a>
</div>
<div id="13">
<a>text</a>
</div>
</div>
You can do this
// get all the elements with id
List<WebElement> ids = driver.findElements(By.cssSelector("#parent > div"));
// get all the texts using the id elements
for (WebElement id :ids) {
String projects = id.findElement(By.tagName("a")).getText();
System.out.println(projects);
}

how can set parameter values for params string[] parameter

I am required to produce the following address
http://example.com/Content/Details?cid=34&query=%D8%AA%D8%AD&positions%5B0%5D=true&positions%5B0%5D=false&positions%5B1%5D=false&positions%5B2%5D=false
this url after decode is :
http://example.com/Content/Details?cid=32&query=تحلیل&positions[0]=true&positions[0]=false&positions[1]=false&positions[2]=false
My action method contains the following parameters
public ActionResult Details(
string cid, string query, int? page, int id = 0, params string[] positions)
{
if(positions != null)
{
ViewBag.Title = positions[0];
ViewBag.Description = positions[1];
ViewBag.KeyWord = positions[2];
}
}
But when I set the parameters required for the positions parameter I get an error :
In fact i cant use positions[0] , positions[1] and positions[2] !!!
my cshtml page :
#{ title
#Html.CheckBox("positions[0]", ViewBag.Title as string)
description
#Html.CheckBox("positions[1]", ViewBag.Description as string)
keyword
#Html.CheckBox("positions[2]", ViewBag.KeyWord as string)
}
#Html.PagedListPager(Model, page => Url.Action("Details", new {cid = ViewBag.currentFilter, query= ViewBag.currentSearchString , positions[0]=ViewBag.title , positions[1]=ViewBag.Description ,position[2]=ViewBag.KeyWord,page }))
how can i set values for positions parameter in cshtml page ?
How can i set position[0] ,positions[2] and positions[3] ... i want know this just
the rest of my code is correct
please help me
You should read them in your controller and set them in ViewBag or ViewData:
ViewData["positons_0"] = Request.QueryString["positions[0]"];
ViewData["positons_1"] = Request.QueryString["positions[1]"];
// etc ...
Then you will be able to use them in your view also.
But I would suggest that you remove the square brackets from your querystring if possible. These are reserverd characters for IP v6 address literals (see here) and this is why you cannot use them in MVC. Your url should be:
http://example.com/Content/Details?cid=32&query=تحلیل&positions=true&positions=false&positions=false&positions=false
In this way you will be able to use it in both your controller:
public ActionResult Details(string cid, string query, int? page, int id = 0, string[] positions)
{
// ....
}
... and view:
#foreach(string position in Model.positions) // example
{
// ....
}

read zip attachment in visualforce page

Hi all I am developing an app on salesforce.
I want to read the content of the file which is inside the zip attachment in visualforce page but without extracting the zip file.
How can I achieve this? Is there any way to do this?
Update for modified question:
Have a look at Handling Office Files and Zip Files in Apex – Part 2 by Andrew Fawcett.
There is a basic Knowledge Article on how to do this with an image that is stored in an Attachment. See How can I Display Base64 Data on page layout?
In this example the AttachmentID is passed via a query string paramemter, but you could look it up however works best for your requirement.
Visualforce page:
<apex:page controller="ViewImage" cache="true">
<img src="data:{!att.ContentType};base64,{!image}" />
</apex:page>
Controller:
public class ViewImage {
public Attachment att {
get {
if (att == null) {
String id = ApexPages.currentPage().getParameters().get('AttachmentID');
att = [SELECT Body, ContentType, Name FROM Attachment WHERE ID = :id];
}
return att;
}
private set;
}
public String image {
get {
return EncodingUtil.Base64Encode(att.body);
}
}
}
Hi all I have achieved this using JSzip library here is my code --
In apex page I have written javascript function --
function viewContent(){
var zip = null;
var zipFileName = null;
var zipFileNames = null;
data = "{!contentAsText}";
zip = new JSZip(data, {base64:true});
zipFileName = 'files.zip';
zipFileNames = [];
for(var zipfileName in zip.files){
zipFileNames.push(zipfileName);
if(zipfileName == 'index.html'){
var file = zip.files[zipfileName];
var data = file.data;
document.getElementById('contentdiv').innerHTML = data;
//var data = JSZipBase64.encode(file.data);
}
}
In controller --
public String contentAsText {get;set;}
List<Attachment> atts = [Select Id, Body from Attachment where name='files.zip' limit 1];
contentAsText = EncodingUtil.base64Encode(atts[0].Body);
This link will help you --
http://andyinthecloud.com/2012/12/09/handling-office-files-and-zip-files-in-apex-part-2/

Resources