Struts tag inside display tag - struts2

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}"

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>

<pe:keyFilter> tag not working

This is not working in my application. It still accept numbers also.
<p:inputText id="Name" value="#{dependbean.name}" maxlength="30">
<pe:keyFilter mask="alpha"></pe:keyFilter>
</p:inputText>
Move the <pe:keyFilter> outside of the <p:inputText> and use the for attribute to point which component is the filter defined for.
<p:inputText id="Name" value="#{dependbean.name}" maxlength="30" />
<pe:keyFilter mask="alpha" for="Name" />
Try
<p:inputText id="Name" value="#{dependbean.name}" maxlength="30">
<pe:keyFilter regex="/[ABC]/i"></pe:keyFilter>
</p:inputText>
Make sure the you have the element added in the beginning of the file
<html ...
xmlns:pe="http://primefaces.org/ui/extensions">
if still doesn't work, make sure the pom.xml file has the dependencies from primefaces extensions.
If not, add this to the pom between tags:
<!-- https://mvnrepository.com/artifact/org.primefaces.extensions/primefaces-extensions -->
<dependency>
<groupId>org.primefaces.extensions</groupId>
<artifactId>primefaces-extensions</artifactId>
<version>6.0.0</version>
</dependency>

How to pass a value of a column as a parameter from another column in displaytag using 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.

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..

how to validate a field of object in Action using Struts 2 Validator

for example, EditAction has the Object proposal, how to user Struts validation framework to validate the fields of proposal. Annotation or XML configuration?
<s:form action="/process/sample/Edit" >
<s:select name="proposal.study" label="Study" list="#attr.studyTypeListKey" multiple="true" size="3" required="true" />
<s:textfield name="proposal.familyNumber" label="Family Number" maxlength="20" required="true"/>
<s:textfield name="proposal.individualNumber" label="Individual Number" maxlength="10" required="true"/>
<s:textfield name="proposal.alpha" label="Alpha" maxlength="30" required="true"/>
<s:submit value="Modify"/>
</s:form>
Please try this code . It may be Work .
Please Check your xwork jar version and Struts-core jar . It should be same .
Field name and Textbox name should be same .

Resources