Load many Divs from a grid + struts2 jquery plugin - json

(JSP - GRID)
I have a grid that load data, i use a formatter="formatLink" in a column for add aspect hyperlink with the respective value of the cell,
<s:url id="remoteurl" action="lisaluXCodYNom" namespace="/"/>
<sjg:grid
id="gridtable"
dataType="json"
href="%{remoteurl}"
pager="true"
gridModel="clientes"
reloadTopics="reloadMyGrid"
rowList="10,15,20"
rowNum="5"
rownumbers="true"
formIds="mcp"
onSelectRowTopics="rowselect"
>
<sjg:gridColumn name="codcli" index="codcli" title="Codigo" sortable="false" formatter="formatLink"/>
<sjg:gridColumn name="nomcom" index="nomcom" title="Alumno" sortable="false" width="300"/>
<sjg:gridColumn name="facultad.desfacres" index="desfacres" title="Facultad" sortable="false"/>
<sjg:gridColumn name="escuela.desesc" index="desesc" title="Escuela" sortable="false"/>
</sjg:grid>
(JAVASCRIPT)
FormatLink, changes the content by hyperlink,
openDialog, executes the action, sending the value of the selected cell in the grid. I capture that value in the object "cliente.getCodcli (cliente.codcli)"
<s:url var="ajax1" action="seleccionarfila" />
function formatLink(cellvalue, options, rowObject) {
return "<a href='#' onClick='javascript:openDialog("+cellvalue+")'>" + cellvalue + "</a>";
}
function openDialog(employee) {
//When I click on any link brings me here
$("#divresult").load("<s:property value="ajax1"/>?cliente.codcli="+employee);
}
(SAME JSP - DIV FOR UPDATE)
I would like this div is upgraded with the information brings back the action on object "cliente.codcli"
<sj:div id="divresult"
dataType = "json" >
</sj:div>
MY STRUTS
As you see i return all object "Cliente", because I need all the attributes in momery to be updated each div with respective atribute.
<action name="seleccionarfila" class="intranet.ConsultarAlumno" method="CargarDatos">
<result type="json">
<param name="root">
cliente
</param>
</result>
</action>
MY METODH "CargarDatos"
This method does what in reality is: Fill a Object with the name "Cliente" that brings its attributes, "name", "surname", "phone", etc etc.. Based on the value of the selected cell (which is really is a code of any client)
public String CargarDatos() {
cliente = new Cliente();
cliente.setCodcli("2008502240");
cliente.setNomcom("ORTIZ");
cliente.set(New Object());
cliente.getObject.setOtherData1("OtherData"));
cliente.getObject.setOtherData2("OtherData2"));
return SUCCESS;
}
So the question goes like this:
Clicking on a row, captured the value of the cell with title "Codigo" then my "seleccionarfila.action " is executed. In the method "CargarDatos" fill an Object with name "Cliente" (filled by hand just for this example, and as can see I have 3 attributes in the Object "Cliente": "codcli", "nomcom" and other object .... "Object" with your attributes)
Well, the upshot of all this is that the div with name "divresult" is updated with all the object "Cliente" and show it with {} and everything else, and only one div is updated.
So, my problem here is:
I need to update many div in the same page.
The divs should are based on a object "Cliente"
The Object "Cliente" should fill based in the click of row the enter
code here enter code here grid
Each attribute of this object 'cliente' respective update a div.
Example:
Div1 = Cliente.codcli
Div2 = Cliente.nomcom
Div3 = Cliente.Object.OtherData1
Div4 = Cliente.Object.OtherData2
etc...
That's what I can do?
chances are that the grid componet let me make an easier way. maybe I'm complicating unnecessarily.

Related

Validation length component depending on chosen h1/h2

Where is a correct place in code to write validation(adding maximum lenght on text field) depending on two diference input's. User can chose an textfield size between h1 or h2. When user chose h1 I want to limit text to 10 elements, when chose h2 limit will be 7 elements. I use AEM 6.2.
I try to Validate an htl file, validate an cq_dialog.When I try to validate an htl file I have an problem with implementation ( it doesn't work), but in cq_dialog.xml file I can only validate an text label once, and I can't change a logic that my validation was change depending which size of text user chose.
This is My cq_dialog code and the most comfortable for me will be adding all logic here but I don't know this is posible?
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
jcr:primaryType="nt:unstructured"
jcr:title="Text"
sling:resourceType="cq/gui/components/authoring/dialog">
<content jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/container">
<items jcr:primaryType="nt:unstructured">
<column jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/foundation/container">
<items jcr:primaryType="nt:unstructured">
<title
jcr:primaryType="nt:unstructured"
name="./title"
fieldLabel="Text"
sling:resourceType="granite/ui/components/foundation/form/textfield"
fieldDescription="Max 10 elements"
/>
<type
sling:resourceType="granite/ui/components/foundation/form/select"
fieldLabel="Type"
name="./type"
jcr:primaryType="nt:unstructured"
>
<items jcr:primaryType="nt:unstructured">
<h1 jcr:primaryType="nt:unstructured" text="H1" value="h1"/>
<h2 jcr:primaryType="nt:unstructured" text="H2" value="h2"/>
</items>
</type>
</items>
</column>
</items>
</content>
You have to create a clientlib and add JS to register a validator for this use case. The clientlib's category must be referenced by the dialog. Using some OOTB category used by the dialog like 'cq.authoring.editor' will make your clientlib work for dialog validation.
Once you have the clientlib set up, register the validator with the granite framework. Refer https://helpx.adobe.com/experience-manager/6-4/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/clientlibs/foundation/js/validation/index.html#validator on how to register the validator.
Here's a sample of how you can do this for your usecase.
var foundationRegistry = $(window).adaptTo("foundation-registry");
foundationRegistry.register("foundation.validation.validator",{
selector: "[name='./title']",
validate: function(el){
var text = el.value;
var type = $("[name='./type']").val();
var limit = type === 'h1' ? 10 : 7;
var numberOfElements = getNumberOfElements(text); //not sure what number of elements means in your context
if(numberOfElements > limit){
return "The input cannot exceed "+limit+ " elements for type "+type;
}
//the field is considered invalid if this method returns a string,
// the string returned is also used as the error message.
}
});
* the code has not been tested
Since the category of the clientlib is generic, this validator will be bound for all dialogs. You can either make the selector of the field more specific or change the clientlib category and explicitly reference it only on this dialog.

Storing the value of selected item from a p:selectOneListbox into a variable on a button click

I am trying to save the value of selected item from p:selectOneListbox on a button click using jquery.
Tried to replicate but it didn't work for me : How to get the value of <p:selectOneMenu> in jquery?
<p:selectManyMenu id="advanced1" widgetVar='commmentWidget'
value="#{decisionTreeBean.option1}" showCheckbox="true" styleClass="XXXX">
<f:selectItems value="#{decisionTreeBean.XXXX}" var="X"
itemLabel="#{X}" itemValue="#{X}" />
</p:selectManyMenu>
Below jquery didn't work (name attribute is the name from the generated HTML)
jQuery(".generateBtn").on("click",function(event){
var $element = jQuery("select[name='A3128:searchForm:basic1_input']option:selected").val();
alert($element);
});
How do I store the text value of the item selected from selectOneListbox into a variable.

insert string array in text box alligned row and column wise in alfresco workflow share form

I am setting array of strings(strings dynamic values)in custom property (text box) at alfresco form share.but I need to allign them in proper rows and columns.How to allign dynamic array values in the proper table(inside text box)
//Task Script :-
xyz.bpmn
var stringcollection = "Column1:"+value1+" "+" :"+Column2+"value1 "+"End Date: "+stopDate+""................ further concatinated strings.
execution.setVariable('abc:def', stringcollection);
I need to sort these collection of strings in rows and columns inside text box in task form(workflow alfresco share).
//Share UI visibility with custom size text box.
sharecustomconfig.xml
<config evaluator="task-type" condition="abc:taskname">
<forms>
<form>
<field-visibility>
<show id="abc:def"/>
<show id="packageItems" />
<show id="bpm:comment" />
</field-visibility>
<appearance>
<field id="abc:def" label="abcdef" read-only="true">
<control template="/org/alfresco/components/form/controls/textarea.ftl">
<control-param name="style">color: black</control-param>
<control-param name="rows">6</control-param>
<control-param name="columns">6</control-param>
</control>
</field>
</appearance>
</form>
</forms>
</config>
Define a property in your model file
In your share-config-custom.xml define form field to render
'" field id="your:prop" set="details" label="details" read-only="true" '"
"control template="org/alfresco/components/form/controls/workflow/custom.ftl" "
Define a property which will show your table Define a custom ftl as form field. And pass your variable to this ftl write your logic to sort list of your string in row and column and you can render it in table in your ftl file

ZK - Invoking ZScript function of an included sub page

Say, I have a zul page (page1.zul) like so:
<zk>
<textbox id="textbox1" ></textbox>
<button label="Display" onClick="display()" ></button>
<include id="include1" ></include>
<zscript>
display() {
include1.setSrc("page2.zul");
java.lang.Class[] argTypes = new java.lang.Class[]{String.class};
org.zkoss.xel.Function fn = include1.getChildPage().getZScriptFunction("doDisplay", argTypes);
fn.invoke(null, textbox1.value);
}
</zscript>
</zk>
But, I get the error - "Attempt to invoke method getZScriptFunction on null value". So, include1.getChildPage() is returning a null value i.e. I am not able to retrieve "page2" using getChildPage() and I am not sure how to go about it.
My second page is shown below:(page2.zul)
<zk>
<label id="label1" ></label>
<zscript>
doDisplay(String value) {
label1.setValue(value);
}
</zscript>
</zk>
If I enter something in the textbox and click the "Display" button, I want to set the value of label in a different page(i.e page2) to the value in the textbox. The idea is to pass value of a component from one page to a zscript function of another included page.
You can do this instead of Passing value.
in Page2.zul
<zk>
<label id="label1" ></label>
<zscript>
doDisplay(String value) {
Textbox textbox=(Textbox)((Include)label1.getSpaceOwner()).getSpaceOwner().getFellowIfAny("textbox1");
label1.setValue(textbox.getValue());
}
</zscript>
</zk>
You can change file1 as follows:
<zk>
<textbox id="textbox1" ></textbox>
<button label="Display" onClick="display()" ></button>
<!-- <include id="include1" ></include> -->
<div id="include"></div>
<zscript>
display() {
include.appendChild(Executions.createComponents("page2.zul", include, null));
}
</zscript>
</zk>
My suggestion is to use EventQueue instead to prevent the coupling of the two zul file.
More details, please reference to the sample code.
http://zkfiddle.org/sample/379s7ev/3-A-sample-for-using-Event-queue-to-talk-with-other-include

RadioButtonGroup with each RadioButton added in components?

Working in Flex 3, I have a series of components being rendered on a canvas, each of which should represent a single potential selection, ideally in a RadioButtonGroup. So in my parent canvas I am defining the RadioButtonGroup, and each component provides a single RadioButton. However, this doesn't seem to work.
Suppose there is a component called aComponent defined as such:
<mx:Canvas ...>
...
<mx:RadioButton id="someButton" groupName="myRadioButtonGroup" ... />
</mx:Canvas>
The outer canvas:
<mx:Canvas id="outerCanvas" ...>
...
<mx:Script>
public function doesSomething():void
{
var myComponent:aComponent = new aComponent();
outerCanvas.addChild(myComponent);
}
</mx:Script>
...
<mx:RadioButtonGroup id="myRadioButtonGroup" />
</mx:Canvas>
So my guess was that at this point if, say, four of these components were added, the radio buttons would behave in mutually exclusive fashion and I'd be able to access myRadioButtonGroup.selectedValue to get the current selection. However, it doesn't seem to work that way.
Is what I'm trying to do even possible, or have I maybe just missed something?
Thanks!
Edit - got to the bottom of it:
The radiobuttongroup isn't available to the component. It's parent has 'myRadioButtonGroup', but not the component.. Pass the 'myRadioButtonGroup' to the constructor and use it..
outerCanvas function:
var myComponent:aComponent = new aComponent(myRadioButtonGroup);
aComponent definition:
private var radioGroup:RadioButtonGroup;
function aComponent(radioGroup:RadioButtonGroup):void {
this.radioGroup = radioGroup;
}
</mx:Script>
<mx:RadioButton id="someButton" groupName="radioGroup" ... />
untested, but hopefully gives you the idea