I am working on a display table version 1.2 on Struts 2 application. I am having problem with fetching value for "titleKey" in my display table column.
<display:column property="propertyName" titleKey="common.property" />
But here Title key is not able to display the value from properties file.
common.property is available in application resources and if I do
<s:text name="common.property"/>
It properly displays the value.
You can use EL expression for the title of the column. Before that the text for the title could be set to the value stack. EL expressions in Struts2 have access to the value stack when searching for variables.
<s:set var="commonProperty" value="%{getText('common.property')}"/>
<display:column property="propertyName" title="${commonProperty}" />
Related
In Struts 1 the <bean:message> tag is usually used with the key attribute in order to get the message from the properties file by specifying the message-key in the key attribute.
And in struts 2 we do that by using either <s:text> or <s:property> tags.
Consider the below example:
In struts 1,
<bean:message key="user.name.required"/>
The equivalent in Struts 2 is,
<s:text name="user.name.required" /> or
<s:property value="getText('user.name.required')"/> where,
user.name.required = Name is required
is the content of the properties file.
But I'm confused with a different scenario.
<bean:message name="user" property="label" />
for this, I tried <s:property value="getText('label')"/>
but the value returned is the string "label" instead of the message string "User data is missing"
and I also tried <s:property value="label"/>
But the value returned is message key i.e. "user.data.missing" instead of the message string "User data is missing"
<bean:message name="user" property="label" /> in Struts 1 returns the message User data is missing.
where,
user.data.missing=User data is missing
is the content of the properties file.
My question is how do I achieve this in Struts 2?
Try the following code
<s:property value="getText(label)"/>
where label is a variable in the value stack which contains a message key i.e. "user.data.missing" .
I am loading java list values in my drop down box.Now i just want to auto select one value from the list by default.we may introduce logic for this either in java side or jsp side.
Here is my JSP part..
<label class="labelStyles" for="planAction">Plan Action:</label>
<html:select styleId="planAction" name="PAMaintenanceProblemProgramForm"
property="planAction">
<html:options collection="validPlanAction" property="code" labelProperty="desc"/>
</html:select>
Java Code is
session.setAttribute("validPlanAction",delegate.getPlanActionList());
How do i make this as auto select by default?
I want to hide a table on load of a page and hide it on click of a button on that page.I have created a property of type String in Action class named as "displayTablle" and assigned it a value "none" by default.So that when this page is opened by calling action,this property will be none and following code used in table tag should hide the table:
<table border="true" id="dataTable" style="display:"<s:hidden id="disTable" name = "displayTable" value="%{displayTable}"/>;">
<s:submit value="Fetch Data" align="center" action="displayDataAction" />
Then on click of Fetch Data button, I am setting value of this property to blank string i.e " ", so that table will be displayed, But I am stuck with the syntax and <s:hidden> is not getting bound properly, as when I open the page, last part of the table tag's code i.e ;"> is getting printed as is.
Can anybody suggest, what should be the right syntax to bind s:hidden in html table tag? Can we do it like this?
The property tag is used to write text to the JSP page. It has also option for unescaping that text, but it's not required in your case.
<table border="true" id="dataTable" style="display:<s:property value='%{displayTable}'/>;">
I would like to have the value of my multibox to be set dynamically from the form. I'm using a <display:table /> tag to show a list in my form in a table however, I have checboxes on every row on the table which I would like the value and disabled attributes set depending on the object in the list that corresponds with that row in the table. This is what I'm currently doing.
<display:table name="sessionScope.SearchForm.companyDevices" requestURI="my/action.jspa">
<display:column>
<html:multibox property="selectedDevices"
value="${macAddress}" <!-- HERE -->
disabled="${isAssigned}"/> <!-- AND HERE -->
</display:column>
<display:column property="macAddress" title="Mac Address" />
<display:column property="vendor" title="Vendor"/>
<display:column property="model" title="Model"/>
<display:column property="deviceStatus" title="Device Status" />
</display:table>
As you can see a column property uses the same macAddress bean value and it displays the macAddress there successfully, however in the multibox it doesn't set the value to the macAddress for some reason. Same goes for the disabled attribute.
I can't seem to identify what is wrong. How do I set dynamic values for multiboxes in a display:table?
I figured out a way. I replaced the multibox tag above with
<display:table name="sessionScope.SearchForm.companyDevices" requestURI="my/action.jspa" id="device"> <!-- ID ATTRIBUTE ADDED -->
<html:multibox property="selectedDevices"><bean:write name="searchForm" property="companyDevices[${row_rowNum - 1}].macAddress" /></html:multibox>
rowNum is an implicitly created variable in struts and to retrieve the row Number for a particular row. To identify a row an Id needs to be assigned. By setting the id to 'device' in the display:table I use device_rowNum (the implicitly created variable from the combination of my the id attribute and rowNum) get a row's particular number which is associated with its position in the list to be able to retrieve the value that I want.
I am working on a display table version 1.2 on Struts 2 application. I am having problem with fetching value for "titleKey" in my diplay table column.
<display:column titleKey="title.key" >
I am kinda sure that I do not have configuration problem. I tried fetching the same value outside the table as :
<s:text name="title.key"/>
I am successful in doing that.
What could be the issue?
I don't know of any reason why DisplayTag would know about the S2 I18N mechanisms.
Either use DisplayTag's I18N support or by not using keys (e.g., the "title" attribute) and using values exposed by normal S2 mechanisms.