get current page address with query string - jsf

I know that current URI of page I can get by
#{request.requestURI}
it is in EL also available as follows:
String uri = ((HttpServletRequest) externalContext.getRequest()).getRequestURI();
Can i get current page address with query string at JSF page? How can i do this ?
For example for page with address in browser /pages/work/myPage.xhtml?id=43&idLast=21
I want to get String with /pages/work/myPage.xhtml?id=43&idLast=21

You can do it via HttpServletRequest methods HttpServletRequest#getRequestURI() and HttpServletRequest#getQueryString():
In EL that'd be:
#{request.requestURI}#{not empty request.queryString ? '?' : ''}#{request.queryString}"

Related

Is asp mvc 5 Html Action method Post or Get request?

What method the Html.Action use for rendering a partial views ?
Example 1 (with parameters):
#Html.Action("_PartialGetMemo", "Memos", new { id = 0 })
Example 2 (without parameters):
#Html.Action("_PartialGetMemo", "Memos")
Can somone explain how this works please ?
This Html.Action renders partial view as an HTML string so we can store it in another string variable. It is string return type method so first it returns result as a string then renders result to response.

Kentico Document Get Page Meta Data Custom Page Type

When trying to retrieve DocumentPageTitle and DocumentPageDescription using GetStringValue() on a custom page type TreeNode, the result is always coming back as the default value (in this case an empty string) passed into the method.
I'm able to successfully retrieve other column values as well as standard document properties such as DocumentName, DocumentID and AbsoluteURL, but not the document meta properties.
The respective fields in the Meta tab of document/page do have values and are being successfully rendered in the by default such as <meta name="description" content=".." />
// returns empty string
string documentPageDescription = DocumentContext.CurrentDocument.GetString("DocumentPageDescription", string.Empty);
// returns empty string
TreeNode document = parameters[0] as TreeNode;
string documentPageDescription = document.GetStringValue("DocumentPageDescription", string.Empty);
I've tried setting option Inherits fields from page type to "Page (menu item)", but that did not help.
Does the custom page type need to inherit from something specifically or have a specific setting activated to access these values? Or if what I think is a TreeNode in fact isn't, how could I get the TreeNode from this object that has the properties listed before available?
Thank you for any help you can provide.
ValidationHelper.GetString(CMS.DocumentEngine.DocumentContext.CurrentDocument.GetValue("DocumentPageDescription"), string.Empty)
Two things to check, one, are you sure the meta data is available on the page you are pulling? Two, is your API actually pulling all the data for that page?
I've used these in my test and both returned the metadata.
var page = DocumentHelper.GetDocuments().Path("/Articles/Coffee-Beverages-Explained").FirstObject;
Response.Write(page.GetStringValue("DocumentPageDescription", string.Empty));
TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);
TreeNode tn = tree.SelectNodes().OnCurrentSite().Path("/Articles/Coffee-Beverages-Explained").FirstObject;
Response.Write(tn.GetStringValue("DocumentPageDescription", string.Empty));
The DocumentPageTitle and DocumentPageDescription were coming back as null when the custom page type document/page was inheriting from parent/global values.
I was able to use the following to get the properties when not inheriting, while falling back to the parent value when inheriting was taking place:
string documentPageTitle = document.GetStringValue("DocumentPageTitle", DocumentContext.CurrentTitle);
This approach came from the following issue on Kentico DevNet.
Thank you for your help and suggestions, it's appreciated.

how do we add url parameters? (EJS + Node + Express)

I understood how we parse the url parameters in express routes, as in the example
How to get GET (query string) variables in Express.js on Node.js?
But where do the url parameters come from in the first place?
EDIT:
Apparently, I can build such a query with jquery (i.e $.get). I can append params to this query object. It s cool, but still i m trying to understand how we achieve this in the query that renders the page as a whole.
An example : when i choose the oldest tab below, how does SO add ?answertab=oldest to the url so it becomes :
https://stackoverflow.com/questions/30516497/how-do-we-add-url-parameters-ejs-node-express?answertab=oldest#tab-top
The string you're looking at is a serialization of the values of a form, or some other such method of inputing data. To get a sense of this, have a look at jQuery's built in .serialize() method.
You can construct that string manually as well, and that's pretty straight forward as well. The format is just ?var1=data1&var2=data2 etc. If you have a JSON object {"name": "Tim", "age": 22} then you could write a very simple function to serialize this object:
function serializeObject(obj) {
var str = "?";
for(var i = 0; i < Object.keys(obj).length; i++) {
key = Object.keys(obj)[i];
if (i === Object.keys(obj).length - 1)
str += encodeURIComponent(key) + "=" + encodeURIComponent(obj[key]);
else
str += encodeURIComponent(key) + "=" + encodeURIComponent(obj[key]) + "&";
}
return str;
}
Running seralizeObject({"name": "Tim", "age": 22}) will output '?name=Tim&age=22'. This could be used to generate a link or whatnot.
The page author writes them so. This is how they "come in the first place". The authors of an HTML page decide (or are told by website designers) where to take the user when he clicks on a particular anchor element on it. If they want users to GET a page with some query parameters (which their server handles), they simply add query string of their choice to the link's href attribute.
Take a look at the href attribute of the oldest tab you clicked:
<a
class="youarehere"
href="/questions/30516497/how-do-we-add-url-parameters-ejs-node-express?answertab=oldest#tab-top"
title="Answers in the order they were provided"
>
oldest
</a>
When you clicked it, the browser simply took you to path indicated in href attribute /questions/30516497/how-do-we-add-url-parameters-ejs-node-express?answertab=oldest#tab-top relative to the base URL http://stackoverflow.com. So the address bar changed.
stackoverflow.com may have its own system of generating dynamic HTML pages. Their administrators and page authors have configured their server to handle particular query parameters and have put in place their own methods to make sure that links on their pages point to the URL(including query string) they wish.
You need to provide URIs with query strings of your choice (you can build them using url.format and querystring.stringify) to your template system to render. Then make your express routes process them and generate pages depending on their value.

JSF URL Routing

Hi is there option in JSF to generate link like that:
localhost:8080/something/:myParamHere
Closest thing I've achieved with this was URL like:
localhost:8080/something?id=55
but I need:
localhost:8080/something/55
You can rewrite request parameters to nearly any URL with Pretty Faces (http://ocpsoft.org/prettyfaces/).
Example:
#URLMapping(id = "process", pattern = "/process/#{processId}", viewId = "/faces/page/process.xhtml")

SharePoint URL retrieval for SPListItem

When I try to retrieve a column which is a hyperlink I get two items that are comma delimited instead of one.
When I pull item["ColumnName"] I get its value:
http://www.google.com/article/583,%20title%20gets%20stars
Why is it showing the link, and title?
You can extract the actual Url and the Description from the column value this way:
SPFieldUrlValue fieldValue = new SPFieldUrlValue(myItem["URL"].ToString());
string linkTitle = fieldValue.Description;
string linkUrl = fieldValue.Url;
Because at the lowest level, all Sharepoint fields are stored as strings. The GetFieldValue method of an SPField accepts a string, and it is up to the logic of that field class to read that string and convert it into a meaningful value object.
item["FieldName"] returns a generic object that represents the field value. By itself the object is usually useless, except as the raw string representation of the data.
If you use the GetFieldValueAsHtml() method, it will return title:
//if field is of type Hyperlink, returns title
item.Fields["FieldName"].GetFieldValueAsHtml(item["FieldName"])
Or
//if field is of type Hyperlink, returns Url, Title
item.Fields["FieldName"].GetFieldValueAsText(item["FieldName"])
Or
//if field is of type Hyperlink, returns Url
item.Fields["FieldName"].GetValidatedString(item["FieldName"])
The SPListItem URL property does return the URL for the SPListItem including the List/Documetn Library name, but it doesn't return the full URL including the server and site names.
To get the full URL, you can either concatenate the SPLIstItem.Web.Url and the SPListItem.URL, or extract the full URL from the SPListItem.XML data like this:
foreach (SPListItem item in list.Items)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(item.Xml);
XmlNamespaceManager nsm = new XmlNamespaceManager(xmlDoc.NameTable);
nsm.AddNamespace("z", "#RowsetSchema");
string fullURL = xmlDoc.SelectSingleNode("z:row", nsm).Attributes["ows_EncodedAbsUrl"].Value;
}
http://insomniacgeek.com/code/how-to-get-the-full-url-from-splistitem-in-sharepoint/
That is how SharePoint stores links. First the URL and then the Title that's actually shown on the page.
From the SharePoint documentation:
"The URL field uniquely consists of two strings separated by a comma and space. One string contains the URL path and the other contains the description used as hyperlinked text."
You have to split the string to get two parts.
string url = field["URL"].Split(',')[0];
string title = field["URL"].Split(',')[1];
Code is not optimal, but just to show you exactly what I mean.
Oliver, you didn't specify SharePoint version. My answer is for 2003 version. If you have MOSS, take a look at SPFieldUrl and SPFieldUrlValue classes.

Resources