how to assign value to radio button from <s:property> in struts 2 - radio-button

Please tell me how we can assign a value to radio button from property tag in struts 2.
I'm using this code -
<s:radio name="id" list="{<s:property value='"client_id"'/>}" ></s:radio>
I'm getting this exception -
org.apache.jasper.JasperException: /user.jsp(165,68) equal symbol expected

no need to use property tag inside another struts 2 tag. directly use the value like this
<s:radio name="id" list="%{client_id}" ></s:radio>
but note that client_id should be a collection

Related

how to combine html:text and bean:write

I am using <bean:write/> tag in my struts program to catch my data into text field but I want to update/edit those data which is coming by this tag so I want to use <html:text/> tag with <bean:write/>, is it possible?
is there any other option to update <bean:write/> tag's data.
I am using this tag like -
<bean:write name="Customer" property="lastname"/>
It's not entirely clear to me what you want to update, and under what circumstances.
If you're saying to want to have the customer's last name be an editable text field, then initialize the ActionForm with the appropriate values before displaying it to the user; you don't need the <bean:write> tag at all if you're just trying to initialize/show a form field.

how to work with rows in struts using display tag....?

In jsp I'm using Display tag to print a table.
I want to display multiple properties in a single row.
Suppose I want to show some information about the particular content of that row.
ex
row1
title:-How to display an image in html ?
started by:-mohit on:-21.10.11
row2
title:-How to display an image in html ?
started by:-mohit on:-21.10.11
row3
title:-How to display an image in html ?
started by:-mohit on:-21.10.11
row4
title:-How to display an image in html ?
started by:-mohit on:-21.10.11
Please help me guy's I have to submit my project after 4 to 5 days.
It is recommended to set the values (to be displayed in displayTag) in the Action class.
It would be even better if you can create a bean class (holding title, startedBy etc. as a properties).
Then retrieve the data from the database and for each row creates an object of your bean class (by setting the values in the properties) and store this object in an ArrayList. When you finished retrieving the data, set this ArrayList as an attribute in either request or session scope.
Suppose you have set the attribute with the name "tableData" in session scope.
Then, in your Jsp you can provide
<display:table id="data" name="sessionScope.tableData">
<display:column> <bean:write name="data" property="title" /> </display:column>
</display:table>
I hope this will help you to understand the scenario.

Variable in an attribute in Struts custom tag

I am trying to use a variable inside a custom Struts tag something like follows -
for(String currentMacro : (List<String>)(request.getAttribute("individualMacros"))) {
name = currentMacro.<some-operation>
<html:mce name = "hmtl_<%= name %>" />
Something like this. But <%=name%> is not replaced with the variable value. It works when I am using the variable with a pure HTML tags.
Is there any any way to accomplish this in this case?
Thanks.
Use JSP EL (assuming JSP 2.0, and you put "name" into scope). You could also check to the if the TLD allows rtexprs.
<html:mce name="html_${name}"/>
But why use scriptlets? There's rarely (ever?) a good reason.
Since we are taking about a custom tag, my guess is that in the TLD file there isn't the rtexprvalue option set to true for that particular tag attribute:
<attribute>
<name>name</name>
<rtexprvalue>true</rtexprvalue>
.......
</attribute>
The rtexprvalue specifies that the attribute value may be dynamically evaluated at runtime.
If set to "false" it means that the attribute has a static value which is evaluated at translation; if set to "true" it means the value can be determined dynamically at runtime. Default is "false".
If the scriptlet does not work, it most likely means rtexprvalue is false. If you don't have the liberty to change that, then expressions won't work on that particular attribute.

struts form and JSTL

How to access a form variable using JSTL ?
e.g.
<html:text property="abc" ... />
<c:out value="${abc}"/>
abc is always blank, even though I have value set by action sending to this page.
If you refer with ActionForm, you can retrieve the value. "abc" is one of the property of ActionForm(you created) which will be available in request scope as it has been set in ActionServlet during processing request.
So get the value like this, suppose your ActionForm is 'TestForm', then retrieve as ${TestForm.abc} or <c:out value="${TestForm.abc}"/>

How to display data in a textarea using struts application

How do you display data in a 'textarea' using struts application,
This is my code:
<html:textarea property="comments" </html:textarea>
<bean:write name="FormBean" property="comments"/>
where FormBean is my beanclass and comment is a property in beanclass.
But I cannot get it too work.
Thanks in advance for your help.
If you use Struts action forms and you have the html:textarea tag inside your html:form tag (this tag is only valid when nested inside a form tag body) then the following code is all you need:
<html:textarea property="comments" />
Don't know what you are trying to do with bean:write but if you want to display that inside your html:textarea I'm not sure you can. The property attribute is mandatory for the html:textarea tag and will use that as the content.