Creating nested custom tag using jsp2 tag files - jsp-tags

I want to create custom jsp tags.Following is my requirement.
1.The tag I have to create can always be added as a chlild tag for certain tags.So I want to validate the tag to check if it is inside a valid parent tag.
2.I want to access the attributes of the parent tag in the child tag file and vice versa.
3.I also want to set one property for each tag which can be set from the tag file and the user should not be able to set it.
I would like to know if I can accomplish these with tag files or should I go for creating custom tags using java code? If these can be done suing tag files can you please give an example?

Navigating up the tag tree, which is required for the validation in your first point, is only possible inside a custom tag (implementing SimpleTag, and using its getParent method), but not in a custom tag file.
Example for checking the type of parent and setting an attribute:
JspTag jspTag = getParent();
if (jspTag instance MyCustomTag) {
MyCustomTag myCustomTag = (MyCustomTag) jspTag;
myCustomTag.setFoo("bar");
}

Related

Alternate shape for EditorTemplate of Field is not being recognized

I need an alternate for the EditorTemplate of an Enumerator Field that's used when the Field has a particular name (PublishingMethod).
Based on the docs, I created a view with the pattern [ShapeType__FieldName] in the same folder as the original shape:
This is not working and still uses the original. I've thought of changing the Editor method in the Driver, but I think that defeats the purpose of alternates, which is that Orchard automatically detects the correct shape as I understand from the docs:
The Orchard framework automatically creates many alternates that you can use in your application. However, you can create templates for these alternate shapes.
Note: I can't use the Shape Tracing module, it never worked even with a clean Orchard install.
The editors in Orchard work different to how Display works. I guess it is so you get a MVC-style experience. Basically, the actual shape returned is of type EditorTemplate, which then binds your model and prefix then renders a partial view with the template name you gave it. What this means is alternates wont work as expected, or as the docs state. The alternates for your field name are actually added to the EditorTemplate shape. So what you can do is add a view called EditorTemplate-PublishingMethod.cshtml with contents like:
#{
var m = (Orchard.Fields.Fields.EnumerationField)Model.Model;
}
#Html.Partial("PublishingMethodEditor", m, new ViewDataDictionary {
TemplateInfo = new TemplateInfo { HtmlFieldPrefix = Model.Prefix }
})
Then add another view called PublishingMethodEditor.cshtml with the overrides you want for your editor. All these views should go in the root of your Views folder.
Another approach would be to implement the IShapeTableProvider interface and adjust the TemplateName property on a certain condition but, meh, that requires code...
Edit 1
If you have that field name on other content types that you don't want to override you can use the override EditorTemplate-ContentTypeName-PublishingMethod.cshtml

Accessing properties across pages in AEM HTL (Sightly)

I have a carousel component, whose slide content will be the content from another page, accessed via reference component. I want to get some properties authored in the carousel to be accessible inside the referenced page. i.e. I have Page A- with a Carousel accessing PageB through reference component. I want to get proeprties from PageA in PageB. Can this be achieved?
Sure it can, you will need to lookup/query the content and find pages where PageB is included, then get the properties of those pages (there might be more than one) and merge them. It will have to be custom code though as this is not available out-of-the-box as of AEM 6.3.
The solution could be adding a query parameter or setting a request parameter. But then again, this depends on the requirement. For me, this worked!!

Kentico tags with a custom page type

I'm reading through the documentation (https://docs.kentico.com/k9/managing-website-content/configuring-the-environment-for-content-editors/configuring-tags/allowing-users-to-tag-pages-on-the-form-tab) and thought all was good, but when i go to create a new page based on the pate type, my Tag field is greyd out.
At the bottom of documentation page, is states:
If you need to create a custom page type with a tag selector, the tag selector must be bound to a system field
I don't know what this means? I've created a tag group (Global), but I'm stuck.
If your parent page type has the Tag field in it already, the child page type will not allow you to change it, you have to go back to the parent page type to change any attributes about it.
Binding that tag selector to a system field means when you create that field, you need to select system field when you create it vs. a standard field.

Opencart add new custom page to search results

I have been looking through many forums but I was unsuccessful :(
I need to display the content of a OpenCart custom page in the search page.
Ta very much
You just need to execute that custom controller, save its output in the data list of the search page template and display it there where ever you want
(1) Open the file "<OC_ROOT>/catalog/controller/product/search.php", you will find a class named "ControllerProductSearch", we are interested in the function "index()"
(2) Find the statement
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
(3) Add the route of your custom controller in the array $this->children, now OC will automatically evaluate your custom controller and send the HTML in a variable to the template, the variable name will be the last component in the route (e.g if your route is common/my_customer_controller, the name will be $my_custome_controller)
(4) Open the search page template file "<OC_ROOT>/catalog/view/theme/<YOUR_THEME_FOLDER>/template/product/search.tpl", and use the variable there
P.S. Make sure that you define your custom controller in the same way other controllers are defined (file naming style, class name based on the route ...), other wise the above solution won't work

Liferay 6.2 PortletURL.setParameter() prepends underscores to parameter names

I am working on a project using Liferay 6.2 on JBoss ES 6.2. I need to be able to create a action URL inside an action method. The action method is looking up some data, building a JSONArray, and then setting an attribute equal to the resulting JSON string. Part of that JSON data needs an action url to another action within the same portlet.
The problem I am running into is that the generated URL seems to force any parameters I set include two underscores to the parameter name.
For instance:
PortletURL actionUrl = PortletURLFactoryUtil.create(actionRequest, portletId, plid, PortletRequest.ACTION_PHASE);
actionUrl.setPortletMode(LiferayPortletMode.VIEW);
actionUrl.setWindowState(WindowState.NORMAL);
actionUrl.setParameter("guid", guid);
actionUrl.setParameter("javax.portlet.action", "myAction");
Ends up generating something like:
http://localhost:8000/group/mySite/myPortlet?p_auth=fsdweD2&p_p_id=p_p_lifecycle=1&p_p_state=normal&p_p_mode=view&__guid=1234567890&__javax.portlet.action=myAction
Notice the __guid and __javax.portlet.action. As a result, the portlet ends up running the doView() instead of myAction().
I have also tried to create a friendly url to solve the issue, but then I run into the issue of how to generate the friendly url with the proper site context AND the required p_auth value.
URL generated doesn't have portlet ID set properly as I see p_p_id is empty in URL. Please check if you are passing correct portlet ID.

Resources