mailto: struts2 - struts2

I am using struts2 and i have property and want to make it a
mailto link.
Can anybody help me how to get it.
thanks

Assuming an action such as:
class SomeAction {
private String email;
// ...
public String getEmail() {
return email;
}
}
You can access it in the JSP using the following:
Struts 2 Tag: <s:property value="email"/>
JSP EL: ${action.email}

Related

Access application.properties value in thymeleaf template

I have one of my spring boot application and inside my application.properties there is one of the property is url=myurl.net.
In the same application I have one thyme leaf html template. I wanted to get the url value into that template. I am using the following code inside the thymeleaf html template <font face=arial size=2 > access the url : </font> ${environment.getProperty(‘url’)}
Output I am getting :
access the url : $(environment.getProperty(‘url’)}
Output I am expecting:
access the url : myurl.net
Instead of actual value I am getting the same text. Can someone please help me on this. Appreciate your help.
You have to use
${#environment.getProperty('css.specific.name')} this will fetch css.specific.name property from the application.properties file.
Map your prop value in your controller, and call it directly from Thymeleaf template.
#Controller
public class XController {
#Value("${pcn.app.url}")
private String url; // Directly instead of using envireonment
#RequestMapping(value = "form-show", method = RequestMethod.GET)
public ModelAndView showForm() {
ModelAndView model = new ModelAndView();
model.setViewName("your-view");
// The key which will look in your HTML with.
model.addObject("urlValue", url);
return model;
}
}
In your html normally call it like this
<html>
<body>
<span th:text="#{urlValue}"></span>
</body>
</html>
Alternatively you define settings as data strucutres, and access them through bean scopes
application.properties
foo.bar=something
Foo.java
#Configuration
#EnableConfigurationProperties(Foo.class)
#ConfigurationProperties("foo")
public class Foo {
private String bar;
public void setBar(String bar) { this.bar = bar; }
public String getBar() { return bar; }
}
sometemplate.html
...
<span th:text="#foo.getBar()"></span>
...
I am using like below
#Service("mapService")
public class MapService {
#Value("${maps.google.api.key}")
private String googleMapApiKey;
#RequestMapping(value = "/google/key", method = RequestMethod.GET)
public String getGoogleMapApiKey() {
return googleMapApiKey;
}
}
<script th:src="#{'https://maps.googleapis.com/maps/api/js?'+'key='+${#mapService.getGoogleMapApiKey()}+'&libraries=places&callback=initAutocomplete'}"></script>

Struts 2 <s:if> tag issue

I have a pojo class as below:
public class HelpBean {
private String title;
public String getTitle(){
return title;
}
public void setTitle(String title){
this.title = title;
}
}
An action class as follows:
public class MyAction implements Action {
private HelpBean bean;
//other fields
public HelpBean getBean() {
return bean;
}
public void setBean(HelpBean bean) {
this.bean = bean;
}
}
In my jsp page, I am trying to check for below condition:
<s:if test=%{!bean.getTitle().trim().contains("bad_title")}>
//execute good code
</s:if>
I also tried below, but this one also doesn't work:
<s:if test=%{bean.getTitle().trim().contains("bad_title") == false}>
//execute good code
</s:if>
Not sharing the xml, as routing and everything works fine. I only have problem checking if my title does not contains "bad_title".
There are many different titles so I can't compare for contains() here, hence checking for !contains()
What am I missing here? Can someone pls point out. Before down voting, please explain if something is missed.
IMO the check should be
<s:if test="%{!bean.getTitle().trim().contains('bad_title')}">

struts 2 checkboxlist doesn't save values

jsp content:
<s:checkboxlist list="list" name="values"/>
action content:
public List<Foo> getList() {
return list;
}
public String[] getValues() {
return values;
}
public void setValues(String[] values) {
this.values = values;
}
class Foo:
private String code;
public String getCode() {
return code;
}
public String toString() {
return code;
}
When I put breakpoint at getValues() method, I clearly see it's being called with some values there. But that values don't appear to be selected on a page.
What am I missing here?
I found a solution. I've added
<s:checkboxlist list="list" name="values" listKey="code" listValue="code />
to jsp and it all started working after that. It generates the same html, but it seems that despite rendering correctly, that properties are required by struts to check what values should be set. And there is no emphasis on that in struts docs.
EDIT:
It seems that only this is actually requited for this thing to work:
<s:checkboxlist list="list" name="values" listKey="code"/>

JSF Navigation outcome constants

I wonder if i can replace "success" with a Constants value from a JSF library.
Backing Bean Method:
#Override
public String save() {
LOG.info("Called");
return "success";
}
For your issue, you'll find Omnifaces' <o:importConstants /> so useful (that's what I use in my own projects). That way you can import your constants file in your JSF page (I use my master page template for that).
<o:importConstants
type="com.mycompany.NavigationResults" />
This way you can access your NavigationResults values both from Java code and JSF tags (EL scope).
public abstract class NavigationResults {
public static final String SUCCESS = "success";
public static final String HOME = "home";
}
Use it in your managed beans:
public String save() {
LOG.info("Called");
return NavigationResults.SUCCESS;
}
In your buttons or links:
<h:button value="Go home" outcome="#{NavigationResults.HOME}" />

Struts 2 How to pass parameter to action

I use Struts 2 Framework and i want to pass a parameter in my action like this localhost:8080/MyApp/ModifierMessage.action?id=9. In my jsp page i have the following text with the action:
Modifier
Someone could help me to add dynamic id to my action ?
Use <s:url> and <s:a> tags. For example is your dynamic id is called dynamic_id:
<s:url var="myUrl" action="ModifierMessage.action" namespace="/OCC">
<s:param name="id">%{dynamic_id}</s:param>
</s:url>
<%-- The link --%>
<s:a href=%{#myUrl}>Modifier</s:a>
public class MyAction extends ActionSupport {
private int id;
public String execute() {
...
this.id = 123;
return SUCCESS;
}
public int getId() { return this.id; }
public void setId(int id) { this.id = id; }
...
}
In the above code if it returns SUCCESS then the browser will be forwarded to
/<app-prefix>/myNamespace/otherAction.action?id=123

Resources