Liferay: get attribute in processAction which is set during rendering phase in portletRequest - liferay-6

Liferay: how to get attribute in processAction which is set during rendering phase in portletRequest?
Edited:
What I'm trying to do -
Rendering phase : I'm building a list of element and populating it to PortletAttributes through setAttribute(key, value) method.
Now I'm able to see my data at jsp in tabular form and I do some changes on jsp. On page submission, I'm having call in my custom processAction menthod ->> Now what I want to see modified list on jsp in my action.
Thanks

If you want to access attributes in the action phase, I think the easiest solution would be to use the portlet session. In rendering phase :
renderRequest.getPortletSession().setAttribute("attr", objects, PortletSession.PORTLET_SCOPE);
In your action :
actionRequest.getPortletSession().getAttribute("attr", PortletSession.PORTLET_SCOPE);

Related

In AEM SiteAdmin, how can I use 'name' instead of 'title' in the left navigation pane?

From the SiteAdmin view, the "Websites" tab in the left-hand navigation pane displays the "Title" attribute from nodes, but sorts according to the "name" attribute. Which file(s) would need to be edited to output the "name" value in that pane instead of "title"?
The script responsible for rendering siteadmin is - /libs/cq/ui/widgets/source/widgets/wcm/SiteAdmin.js
If you look at line number 340, it has configuration like -
The call /bin/wcm/siteadmin/tree.json is handled by SiteAdminTreeServlet which generates the JSON used in rendering the tree (and sorting it). You could overlay this to use your own Servlet that gives the result in the sorted order of field you need (not recommended unless you know the nitty–gritty of this servlet).
If you still want to proceed with the changes you need to do two things -
Add configurations to disable SiteAdminTreeServlet, use OSGI component disable logic to achieve this or you could refer to AEM ACS Commons here
Provide your own implementation as Servlet to handle the requests to the path /bin/wcm/siteadmin/tree and handle json extension explicitly (path based servlet will ignore extensions).
You can try invoking this servlet as http://localhost:4502/bin/wcm/siteadmin/tree.json?path=/content
In CQ/AEM /libs/cq/ui/widgets/source/ext/override/widgets/tree/TreeNodeUI.js script renders the left hand side of siteadmin. You can directly make a minor change in this script to display page name instead of page title in the CQ siteadmin.
Click here to look at the code
CQ.shared.XSS.getXSSValue(n.text.replace(/</g, "<")) should be changed to CQ.shared.XSS.getXSSValue(n.attributes.name.replace(/</g, "<")) at line number 71 in /libs/cq/ui/widgets/source/ext/override/widgets/tree/TreeNodeUI.js and it works great

Reusing the CQ5 Form into the mywebsite components is not showing up the End of the Form section

I am trying to reuse the Form into my project components.
I have copy pasted the entire form folder from "/libs/foundation/components/form" to my project "/apps/mywebsite/components/form".
But when i am trying to use the form from mywebsite in the parsys the from shows only Start of the from.
Where as when i tried to use the form from the foundation in the same page parsys it shows both Start and End of the form.
Observation:
From the content, when i am using the foundation form the in the page content i can see the start and end nodes. where as when i am using the mywebsite form start node alone is created.
The form end is added/deleted by the fixStructure() method of the FormParagraphPostProcessor class. This post processor listens for creation and deletion of form start and form end paragraph and creates/removes the other paragraphs accordingly.
if ( ResourceUtil.isA(res, FormsConstants.RT_FORM_BEGIN)
|| ResourceUtil.isA(res, FormsConstants.RT_FORM_END)) {
if ( FormsHelper.checkFormStructure(res) != null ) {
logger.debug("Fixed forms structure at {}", contentResource.getPath());
}
}else {
fixStructure(res);
}
This class depends on the FormConstants.java where the form start(RT_FORM_BEGIN) and the form end(RT_FORM_END) are defined as "foundation/components/form/start" and "foundation/components/form/end" respectively. Due to this the post processor doesn't process the form start / end that is present within your project.
To make your custom form component working you may consider one of the following possible options:
Add the sling:resourceSuperType property for your project form start as "foundation/components/form/start". This would create a form end, but it would be of type foundation/components/form/end and not your project form end.
In case you do not want the default form end but your custom form end, then you may need to create a custom post processor which listens to your form start and end and fix the structure accordingly. This requires modifying few other java classes like FormsHelper.java etc, as they are also dependent on the FormConstants.java. Also make sure that the imports in the start.jsp are changed accordingly.
Finally, if you do not want to create custom classes, you can copy the default form start to "/apps/foundation/components/form/start" and make your modifications on top of it. But you need to be careful while using this approach as this is a global change and would affect the other projects that are using the default foundation form start.

Zend: Form Validation After AJAX

I have a form done with Zend. I load it with ajax in a dialog. It has 2 selects. Depending on what is selected in the first select, it loads the content of the second one. However, when I submit the form I get a validation error because the options of the second form weren't there at the time of creating it.
Is there a way to fix this "issue"? It does what it needs to do but I don't want it to verify that field anymore. Any way to specify that I don't want that?
You can disable the inArray validator. When constructing the form's select element, set
'registerInArrayValidator' => false
Also, a different solution would be to overload the isValid method, inspect the selected option for the first select element and then populate the options for the second element. Then call parent::isValid to check if the form is in fact valid or not.

ExtJS 4 - How to load grid store with its params carrying latest values from a form?

I have a window with a search form at the top and grid at the bottom.
User can enter values in the search form and click button - Get Records.
At the click of this button, I load the store of the grid by passing the values in form fields as parameters in following way:
store.load({
params:{
key1:Ext.getCmp('field1').getValue();
}
});
I tried giving parameters in the store proxy itself, but it unfortunately always takes up initial values (values when the form is rendered) and not the latest one entered by the users in the form fields. Following is the method I used for assigning values to params while creating the store:
extraParams:{
key1:Ext.getCmp('field1').getValue();
}
I wanted to seek guidance at two things:
a. While defining a store, can I ensure that store takes latest/current values from the form fields before querying server, so that I don't have to provide these values while calling load function?
This becomes more necessary as I have a paging toolbar at the bottom which carries a refresh button (along with next, last, previous, first icons for navigation).
Now, whenever user clicks at refresh (or any navigation icon), the store gets loaded without the query parameters.
Thus the second thing is:
b. If the answer of 'a' is that - Pass the latest values to parameters manually when calling load function - then how can I write the handler for 'refresh' button and navigation icons (that is, next, last, previous and first) in the paging toolbar, so that I can pass the latest form values to load function.
Thanks for any help in advance.
PS: I am using ExtJS 4.
yourStore.on('beforeload',function(store, operation,eOpts){
operation.params={
status:cmbStatus.getValue(),
value:txtBuscarPor.getValue(),
empresa:'saasd',
app:'dsads'
};
},this);
Related to your question (b) (and because you especially asked for this in the comments section):
I see only one standard way to hook into the PagingToolbar button handlers which is very limited.
Ext.toolbar.Paging fires a 'beforechange' event before it actually changes the current page. See API docs. A listener that returns false will stop the page change.
All other methods require extending Ext classes which wouldn't be a problem if the ComboBox would make it easier to use your own implementation of BoundList (which is the class that renders the dropdown) or pass through config parameters to BoundList resp. the paging toolbar.
I tried to bring this lack of flexibility up on the Ext message board once but was pretty much ignored.
A possible solution for this is to use 'beforeload' event of the store and provide the list of parameters in it. This way, whenever the store is loaded, then its beforeload event is fired and the values picked up are always the latest. Hope this helps someone looking for something similar.

Populating some fields after selecting the element using Struts2-Dojo autocompleter

I am using sx tag i.e. struts-dojo-tag of struts 2 to autosuggest one field on one page. It is working fine. Now I want to populate other fields on the same page based on the selection of autosuggest field. I tried calling javascript on the above field on various events like onselect, onchange,etc with no success.
JSP code :
<sx:autocompleter autoComplete="true" listKey="id" listValue="brandName" name="brand.brandName" id="brandName" cssClass="textfield" list="brandList" onchange="populateInfo(this.value);"></sx:autocompleter>
here I want to autosuggest brandNames available and on selecting the brand, I want to populate data regarding the brand in some others fields. I tried calling java script function populateInfo(), but the function is not getting called.
Can you please help me out?
I think this problem can be solved by using select tag of struts2-jquery.
You can have a look in these showcase