How to pass a value of a column as a parameter from another column in displaytag using struts2 - struts2

In the below code, I am trying to pass 2 parameters from <display:column> tag. I have to pass code and level properties to an action(as shown below). I am not able to pass value of another column as parameter from a column. Here I am not getting value of level property in code property.
<s:form action="levelHierarchy">
<display:table id="searchList" name="searchList" pagesize="8"
export="false" requestURI="/getComponentDetails" sort="list">
<display:column property="code" title="Code" sortable="true" paramId="levelId" href="levelHierarchy.action?level=${searchList.level}"></display:column>
<display:column property="description" title="Description" sortable="true" />
<display:column property="level" title="Level" sortable="true" />
<display:setProperty name="paging.banner.placement" value="bottom" />
</display:table>
</s:form>

Inside the form you don't have any fields to submit. You should define at least hidden fields to the columns that contains the values you want to pass to the action. You also need the use of uid attribute of the <display:table tag to access the row values.
<display:table uid="row" id="searchList" name="searchList" pagesize="8" export="false" requestURI="/getComponentDetails" sort="list" >
<display:column property="code" title="Code" sortable="true" paramId="levelId" href="levelHierarchy.action?level=${searchList.level}">
<s:hidden name="submitList[%{#attr.row_rowNum - 1}]" value="%{#attr.row.code}"/>
</display:column>
<%-- Other columns like that --%>
</display:table>
in the action you should create the property placeholder for the submitted values.

Related

Populate list of list using displaytag

I am using struts2 and display tag to show results in a grid format. All the information present in the list is populated. However when I need to populate data from the Arraylist present inside original list, I fail to populate and gives error Unknown property.
For example:
<display:table id="txt" name="resourceList" requestURI="" pagesize="10" cellpadding="50px;" cellspacing="100px;" style="margin-left:10px;margin-top:50px;" export="true">
<display:column property="resource_Code" title="Code"></display:column>
<display:column property="resource_Fname" title="First Name"></display:column>
<display:column property="resource_LName" title="Last Name"></display:column>
<display:column property="resource_RJILEmpCode" title="RJIL Emp Code"></display:column>
<display:column property="customerPO" title="PartnerPO End Date"></display:column>
</display:table>
When I want to print list"customerPO" inside the "resourceList" I get error as unknown property "code". Here code is an attribute present inside the "customerPO" and this customerPO is a list.Please advice me how to print the nested list using display tag
<display:table id="txt" name="resourceList" requestURI="" pagesize="10" cellpadding="50px;" cellspacing="100px;" style="margin-left:10px;margin-top:50px;" export="true">
<display:column property="resource_Code" title="Code"></display:column>
<display:column property="resource_Fname" title="First Name"></display:column>
<display:column property="resource_LName" title="Last Name"></display:column>
<display:column property="resource_RJILEmpCode" title="RJIL Emp Code"></display:column>
<display:column property="customerPO.code" title="PartnerPO code"></display:column>
<display:column property="customerPO.name" title="PartnerPO Name"></display:column>
</display:table>

Export a nested displaytag table in excel

I have displayed a nested table using display tag .
The code of my nested table is:
<display:table export="true" name="detailsList" id="parent" requestURI="" pagesize="1">
<display:column property="testcaseName" />
<display:column property="subject" />
<display:column property="description" title="Comments" />
<c:set var="nestedName"
value="detailsList[${parent_rowNum -1}].testList" />
<display:column title="TestCase Details" >
<display:table name="${nestedName}" id="child${parent_rowNum}"
class="SimpleSublist">
<display:column property="stepName" />
<display:column property="description" />
<display:column property="inputField" />
<display:column property="inputData" />
<display:column property="expectedResult" />
<display:column property="remarks" />
</display:table>
</display:column>
</display:table>
I wanted to have the export option for the same...
But I am not able to figure out how to do it..
Is there any workaround as the inbuilt export does not work here..
Which in-built export are you talking about? If you want to export something to excel, you will have to do it programatically using libs like apache poi [I have used it and found it great] and its examples.
UPDATE:
I googled and found this display tag link which says that nested tables cannot be exported by display tag :( (check the last line of limitations)
So the solution suggested above will work for you..

dynamic data reload to struts2 jquery grid on form submit

I have a grid which load data on page load.
I also have a form that on submit calls an action correctly, but it doesn't load new data on my grid.
List is correctly geting and also correctly setting in my grid model From my Action class but while on return SUCCESS it simply returns data in this form(see below output)...
{"authFirstname":null,"authLastname":null,"bookDetailsobj":null,"bookTitile":null,"get":{"authFirstname":null,"authLastname":null,"bookTitile":null,"coverId":null,"createdDate":null,"createrId":null,"description":null,"editionId":null,"editionYear":null,"id":null,"img1":null,"img2":null,"isbn":null,"languageId":null,"locationId":null,"price":null,"publisherName":null,"quantity":null,"remarks":null,"subjectId":null,"updateId":null,"updatedDate":null,"videoUrl":null},"gridModel":[{"authFirstname":"234234","authLastname":"2323423","bookTitile":"23324234234","coverId":"soft cover","description":"243234","editionId":"General Edition","editionYear":"234234","id":42,"img1":"","img2":"","isbn":"324234","languageId":"English","locationId":"as","price":2.34234E7,"publisherName":"234234","quantity":234234,"remarks":"","subjectId":"General Fiction","videoUrl":""},{"authFirstname":"2423","authLastname":"23423","bookTitile":"asdfsdaf","coverId":"soft cover","description":"","editionId":"General Edition","editionYear":"2","id":39,"img1":"","img2":"","isbn":"2","languageId":"English","locationId":"as","price":234.0,"publisherName":"2","quantity":2,"remarks":"","subjectId":"General Fiction","videoUrl":""},{"authFirstname":"3","authLastname":"3","bookTitile":"232","coverId":"soft cover","description":"","editionId":"General"}
My jsp code:
<sjg:grid
id="getLogs"
dataType="json"
href="%{getCurrentDateLogs}"
gridModel="listOfLogs"
onSelectRowTopics="rowselect"
loadonce="true"
reloadTopics="reloadGrid"
formIds="form2"
>
<sjg:gridColumn name="userid" index="userid" title="User ID" sortable="true" align="center"/>
<sjg:gridColumn name="username" index="username" title="Username" sortable="true"/>
<sjg:gridColumn name="logaction" index="logaction" width="600" title="Action" sortable="true"/>
<sjg:gridColumn name="date" index="date" title="Date" sortable="true" sorttype="date" align="center"/>
<sjg:gridColumn name="time" index="time" title="Time" sortable="true" sorttype="time" align="center"/>
</sjg:grid>
<s:form action="getLogsByDates" id="form2" theme="simple" cssClass="yform">
<table class="">
<tr><td>from:</td>
<td><sj:datepicker value="yesterday" id="from" name="startDate" displayFormat="dd/mm/yy" label="from" /></td>
</tr>
<tr><td>to:</td>
<td><sj:datepicker value="today" id="to" name="endDate" displayFormat="dd/mm/yy" label="to" /></td>
</tr>
<tr><td colspan="2">
<sj:submit
value="Search"
button="true"
onClickTopics="reloadGrid"
indicator="indicator"
/>
</td></tr>
</table>
</s:form>
struts.xml
<action name="getLogsByDates" class="v.esoft.actions.bookdetails.BookdetailsAction" >
<result name="success" type="json"/>
<result name="login" type="redirect"> /index.jsp </result>
</action>
**
I don't know why my output is not showing in my jquery grid. Please help me**
I guess this is what you require :
Instead of using a sj:submit tag, use a sj:a tag with onClickTopics pointing to GridReloadTopics.
Then when sj:a is clicked, the grid get's reloaded, submitting the form to action defined in href attribute of grid.
This action must result a JSON which will populate the grid.
You haven't shown the action "getCurrentDateLogs" in the question. So this is the action that must return the json result populating the grid.
Also you must be thinking that how the grid-data gets affected by the form fields, so it's easy
The grid submits all the form fields to the action mentioned in href, so you must be having a getter & setter for every form field on that action.
Along with other normal grid attributes, now you'll receive the additional form attributes, based on the value of which you'll fill up the gridModel.
Please let me know if you still didnt' understood.
It doesn't work this way. try do the following things:
make an action retuen a page, not json
<result name="success">page_with_the_grid.jsp</result>
on the page page_with_the_grid.jsp, use s:url tag to map your json result:
<s:url var="jsonUrl" action="jsonAction"/>
in your sj:grid, use href="%{jsonUrl}" to fill your data to the grid.
if you directly call the action, which returns JSON, you will sure get a json result, which is your "Strange" output.
I have find Two grid after submit the form one is old one and second one my search grid it also include whole page
<sj:a href="%{form}" targets="result" indicator="indicator" button="true" buttonIcon="ui-icon-refresh"/>

Property value in <s:textfield> struts2

How to set propety value in <s:textfield>
I tried <s:textfield name="customerName" label="Customer Name" value='<s:property value="userInfo.customerName"' /> but it didn't work.
Please help
You can not use a tag inside of a tag. Use OGNL instead!
<s:textfield name = "customerName"
label = "Customer Name"
value = "%{userInfo.customerName}"/>
Use OGNL (Object Graph Navigation Language) to get value in any kind of field of struts. If you will not get value please check setter and getter of the variable.
<s:textfield name="transValueChange" id="transValueChange"
value ="%{transValue}" theme="simple" maxLength="30"
onkeypress="return isNumberKey(event)">
</s:textfield>
OR
<s:select name="propCode" id="propCode" list="propClassMasMap" theme="simple"
value="%{propCode}" onchange="" cssClass="text">
</s:select>
I used this:
<table>
<s:label>User Name:</s:label>
<s:textfield name="user.userid" cssClass="tb5" type="text" placeholder="User Name" value="%{#session.userid}" disabled="true" />
</table>
The disabled attribute is not mandatory, I used it to disable the textfield that way the values will be retrieved from the DB and will be disable for the user to make changes on it.

Struts tag inside display tag

I am getting error when i refer display tag reference from struts tag.
<display:table name="lstEntities" uid="prty">
<display:column property="propertyType.propertyTypeName"
titleKey="common.propertytype" />
<display:column property="propertyName" titleKey="common.property" />
<display:column titleKey="common.concern" >
<s:select list="${prty.propertyConcern}" listKey="prtyCrnId" listValue="concern.concernText"></s:select>
</display:column>
</display:table>
Error:
Custom tag attribute list cannot be runtime expression. value: "[${prty.propertyConcern}]"
Please help me. how to resolve this.
Such expressions were allowed in earlier releases of Struts2, but were turned off after struts 2.0.10 to resolve a security issue.
You should be able to access the "prty" object in struts tags using this alternative syntax:
<s:select list="#attr.prty.propertyConcern" listKey="prtyCrnId" listValue="concern.concernText"></s:select>
Modifying fieldValue="#attr.resultTable1.id" to fieldValue="%{#attr.resultTable1.id}" resolved my problem.
i.e.:
<display:table name="libraryList" requestURI="showCopyTravelType.action" sort="external"
defaultsort="1" pagesize="10" uid="resultTable1" partialList="true" size="totalRecordCount">
<display:column title="Select">
<s:checkbox id="copiedFlag" name="copiedFlag" fieldValue="%{#attr.resultTable1.id}" />
</display:column>
<display:column property="code"/>
<display:column property="name" />
<display:column property="description" />
<display:footer>
<s:submit action="copyTravelType" />
<s:submit action="searchTravelType"/>
</display:footer>
</display:table>
<s:select list="#attr.prty.propertyConcern" listKey="prtyCrnId" listValue="concern.concernText"></s:select>
If we want a list then the parameter should passed like:
list="%{#attr.prty.propertyConcern}"

Resources