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}"/>
Related
I am new to Struts and I Don't Understand Struts Action Parameters, specifcally: Name,Validate,Input and Redirect="true"
Example:
*#struts.action name="activation" path="/activation" validate="false" parameter="activation"
*#struts.action-forward name="activationStart" path="/activation.html" redirect="true"
Please try to answer me in terms of above example.
So basically you refuse to read the Struts 1 documentation?
name
The name of the ActionForm bean for this action.
validate
Should validation run?
input
The input page for the form, usually used to return to the form on a validation error.
redirect
When this forward is returned should it be a redirect or a forward?
Name
Name is the name of the formbean which is associated with you JSP. In your struts-config you will have something like this
<form-beans>
<form-bean
name="activation">
<form-property name="name" type="java.lang.String"/>
</form-bean>
</form-beans>
validate
You have validator framework which has some validations in place, like checking the name field for null value and so. You tell your struts whether the validator should work or not. If validation=false, then validation is not performed in your current jsp
input
input is the input jsp. If there are any validation errors, the execute method of the action will not get called; instead the control will go back to that ***.jsp. But you have not specified any input in your example
redirect
Whether to redirect or just forward
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.
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.
I have a jsp page with the tags:
<logic:iterate id="var" ...
....
<bean:write name="var" property="p1" ...
etc.
And I need, on each iteration, to generate a href composed from the various bean's properties. I even need to URLEncode some of them so the link works.
Something like
<logic:iterate id="var" ...
....
<html:link action="otheraction.do?_X_
<bean:write name="var" property="p1" ...
etc
where X is generated by collecting the bean's properties; something like
String X="p1="+URLEncode(p1)+"&p2="+SimpleDateFormatof(p2)+"&p3="+p3;
How can I do that ?
Thanks in advance.
Better to make one POJO class.
1. Assign all your values to the object in Action which is being called before your jsp page comes in the picture.
2. Keep the object of POJO to request attribute.
3. Get the value from request attribtue on JSP using <bean:write> tag.
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.