Property value in <s:textfield> struts2 - 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.

Related

JSTL c:set and Struts s:set are undesirably formatting numbers

<c:set var="xmlDocumentId" value="${id}" scope="request" />
<s:set var="xmlDocumentId" value="%{id}" scope="request" />
are formatting id based on locale, setting xmlDocumentId to "12,345" while:
<c:out value="${id}" />
<s:property value="%{id}" />
are outputting "12345".
Any ideas how to break this behavior?
Because you are getting value with getText or <s:text> tag your long value gets formatted according to locale. To prevent this from happening convert your long to string.
With <s:set> tag you can call toString() method directly in value attribute.
<s:set var="xmlDocumentId" value="id.toString()" scope="request" />
For the concrete formatting algorithm take a look at java.text.MessageFormat class and its subformat method.
Once you know how to format numbers in Java, in Struts2 <s:property/> tag you can use getText() to format your number in the desired way, for example :
<s:property value="getText('{0,number,#,##0}',{id})"/>
Try this
<s:text name="id" > <s:param name="value" value="id"/> </s:text>

How to change a f:field (textField) by a textArea using Grails Fields Plugin

In the documentation changelog of the plugin, at Version 1.1, we can read:
Support `widget:'textarea'` constraint.
Grails has a textArea field. This is the example of the grails documentation:
<g:textArea name="myField" value="myValue" rows="5" cols="40"/>
But, if we are using Grails Fields Plugin, and we have a code like:
<f:field bean="popularExpressionsInstance" property="omg" />
How could we convert it to textArea to allow to type several lines of text?
In your popularExpressions domain class, add the following constraint for omg
static constraints = {
...
omg widget: 'textarea'
}
Note: if you need to control style of textarea, you'll need to include it in the body of the f:field tag, for example
<f:field bean="popularExpressionsInstance" property="omg">
<g:textArea name="omg" cols="40" rows="5" maxlength="40" value="some default text"/>
</f:field>
You can override body of tag directly in GSP, as #user2264997 mentioned, but use ${ property } and ${it.value} variables:
<f:field property="description" widget="textarea">
<g:textArea name="${ property }" cols="40" rows="5"
value="${it.value}" />
</f:field>

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.

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 .

Highlighting entire table row if validation fails

I am working on JSF2.0 and Richfaces. I am having an requirement where I need to change the style of the form field(entire row) if the validation fails. I am using the following code to display field label and text box.
<h:panelGrid columns="2">
<h:outputLabel value="#{uit.firstname}:">
<span class="required"><strong>*</strong> </span>
</h:outputLabel>
<h:inputText value="#{editUserProfileBean.firstName}" type="text"
id="firstname" styleClass="basicFormTextBox" size="30"
required="true" requiredMessage="#{uitkem.valueRequired}"
validatorMessage="#{prod.firstNameValidator}">
<f:validateLength maximum="#{prodConf.MaxLengthForFirstName}"
minimum="#{prodConf.MinLengthForFirstName}" />
<f:validator validatorId="trimSpaces" />
</h:inputText>
</h:panelGrid>
Suppose if the validation fails, I need to hightlight the row(both label and textbox).
I can use the following code to hightlight the textbox if the validation fails. But I want to hightlight the entire row, that is not possible using the following code.
<h:inputText value="#{editUserProfileBean.firstName}" required="true" styleClass="#{not component.valid ? 'newStyleClass' : ''}" />
Can anyone help me on this?
Thanks in advance.
You could just write a tiny JS script with jQuery, or use <rich:jQuery> for that.

Resources