I am working on the Struts2 framework with JSP.
In my samplePrj.properties file, in that
com.samplePrj.Successmessage = Saved Successful
is an attribute. I need to use this value in my JSP page, using Struts2.
so how can I get the value of "com.samplePrj.Successmessage" in my JSP page.
Use the text tag
<s:i18n name="samplePrj">
<s:text name="com.samplePrj.Successmessage" />
</s:i18n>
it will load the bundle using i18n tag from samplePrj.properties and print the value from key com.samplePrj.Successmessage in it.
or you can use it with getText() but your action class should extend ActionSupport.
<s:property value="getText('com.samplePrj.Successmessage')"/>
You can use getText() method to read from properties files.
<s:set var="variable" value="getText('com.samplePrj.Successmessage')"/>
<s:if test="myVariable == #variable">
//do what u want
</s:if>
Related
I'm trying access some value from my jsp file in Spring controller. All examples that I've found was with <input> or <form> code, but I want to pass "clear" value (just String), for example <c:set var="name" value="Ololo"/>or smth like this and print it in Conroller.
You can't. Data can flow only in one direction, from controller to view (jsp). If you have to send information back to the controller then you should make http request. That's the reason you only see <form> and <input> in examples
I'm trying to use Struts framework in my project. I want to use the html:button to send parameter in the link but I don't understand how to make it.
In other words, I want to translate this line:
<input type="button" onClick="window.location.href='resum.do?action=ViewMessage&&id_message=<%= id_msg %>'" value="View"/>
to Struts taglib, something like this:
<html:button property="" onclick="window.location.href='resum.do?action=ViewMessage&&id_message=<%= id_msg %>'" value="View"></html:button>
But it didn't work.
The html:button tag is used only inside the form tag. See the docs
This tag is only valid when nested inside a form tag body.
Also set the property attribute.
I have the below Struts 2 tag, I need to check if property value="#attr.row.Commentaire is not empty and if it's not, display a small icon where the user can click it and consult the contents of the property value="#attr.row.Commentaire.
How can I use the <s:if> tag of Struts 2 efficiently to do that?
<display:column title="Commentaire" sortable="true" sortProperty="Commentaire"
class="alerte_td_commentaire">
<s:property value="#attr.row.Commentaire"/>
Use the following code
<s:if test="#attr.row.Commentaire != null && #attr.row.Commentaire != ''">
The if tag uses the test attribute to evaluate OGNL expression to a boolean value.
You may also want to use an a tag which renders a HTML anchor tag that could be used combined with the if tag to
consult the contents of the property
There's also a debug tag that could be used to wrap other tags to show you a link that will render a debug data.
<s:debug>
<s:property value="%{#attr.row.Commentaire}"/>
</s:debug>
How to send value using anchor tag in Struts2 please give me an example and I know we can achieve this using url tag, but I want it using anchor tag.
Create it like any other parameterized link.
Personally, I prefer to use JSP EL:
${subject}
But if you insist on tags:
<a href="displayMails?foo=<s:property value='%{someActionProperty}'/>">
<s:property value="%{subject}"/>
</a>
... To use the S2 action name in the HREF.
${subject}
At this point we're back to having no idea why the S2 tag isn't what you actually want.
The anchor <s:a> tag in Struts2 as well as the other tags could be parametrized with the <s:param> tag. Just place param tag in the body of the anchor tag. For example
<s:a action="myaction"><s:param name="myparam" value="%{property}"/></s:a>
In one of our challenging application, I am generating few struts tag dynamically in Action class
Once I generated the struts tag, I want it to get it parsed through s:property
in my JSP:
<s:property value='generateElement("ABC")' escape='false' />
in my Java Action
public String generateElement(String element){
return "<s:select id='aaaa' list=\"{'1':'1','2':'2'}\" >";
}
in the end I want to generate Selection box.
How do I achieve this.
You can't execute JSP code after the JSP has been compiled. So there's no use in returning a JSP tag in your method. Instead, generateElement should return the objects that you need in your select, and then reference that property in a <s:select> tag that is already in your JSP.