Not much to say, my <s:a href="xxx">blablabla</s:a> is aways resolved to empty and invisible
I also tried s:a attributes like label, title, name, etc.
The proper notation is
<s:a value="http://www.stackoverflow.com">Go to link</s:a>
And also make sure you got this at the top of your jsp.
<%# taglib prefix="s" uri="/struts-tags" %>
Related
I have a JSP page,In that page,I am trying to use the page scope attributes using jstl and struts2 tags.
The following piece of code is,
<%# taglib uri="/struts-tags" prefix="s" %>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="test" value="ramesh"/>
<c:set var="test1" value="${test}"/>
<s:set var="test2" value="${test}" />
the <s:set> tag yields the following exception " According to TLD or attribute directive in tag file, attribute value does not accept any expressions".
I have two questions.
1)${test} works when it is used in <c:set> tag.
2)${test} does not works when it is used in <s:set> tag. Why?
EL and JSTL are now in Java EE standards, so they can cooperate well, I think.
However, when in struts 2 tags, because struts 2 have their expression language - OGNL,
so I think they prefer to use OGNL to EL in their tags, and that is the reason why they do not support EL. These are my guess.
From Apache link
From Apache FAQ link
As of Struts version 2.0.9 the JSTL/JSP expression language (EL) has been disabled for Struts tag attributes which evaluate OGNL. This is a precaution against security vulnerabilities that can result from the double-evaluation that occurs when an attribute is first processed as a JSTL/JSP EL expression and then the result is processed as an OGNL expression. The solution is to express all dynamic attribute values in Struts tags using OGNL expressions directly.
I'm trying to avoid using a gem because of the simplicity of my question.
My website has the following ?params=
"type" just filters by type. if this isnt specified they're all lumped together
"sort" sorts by date/whats hot/latest
"view" changes compact view/list view
"scroll" isnt even used yet, its for infinite scroll on or off which i havent put in yet
"reset" is a link when you click the logo (not the home link) that resets all session params to "all" and "whats hot" (the default)
"page" is the pagination which i think is the only really important one
After getting some help, I was informed ?page= is the only really important one, as all my content can be access without any query params, EXCEPT pagination.
So now i have this:
<link rel="canonical" href="<%= "http://#{request.host + request.fullpath}" %>">
So my question is how do i modify this so it only puts the URL, and also puts ?page= if its present but ignores all the other params?
This seems to wrok
<link rel="canonical" href="<%= "http://#{request.host + url_for(:page => params[:page]) }" %>">
It's 2017, I know, you could also use Rails Auto Discovery Link.
<head>
<%= auto_discovery_link_tag(:atom, your_path('your-params'), { rel: "canonical" }) %>
</head>
In simplest cases that should work:
<link rel="canonical" href="<%= "#{request.protocol}#{request.host}#{request.path}" %>">
If you're using protocol or want to use GET params in canonical url, don't forget to add it.
I am passing param value in include tag in jsp page like below
<s:include value="../../commonjspf/status.jspf">
<s:param name="mystatus" value="%{status}">
</s:param>
</s:include>
where status variable come from action class .
I want to access that mystatus param in status.jspf page in struts if tag to compare with my default values.
<s:if test ="">
</s:if>
or
<s:set name="" value =""/>
any of above tags.
how can i access ?
please suggest me .
Thanks.
Use the ${param.ParamName} notation to access them, as mentioned in the reference below:
http://struts.apache.org/2.0.14/docs/include.html
A sample code:
Page 1:
<s:include value="testPage.jsp">
<s:param name="mystatus">TestThis</s:param>
</s:include>
Page 2:
<%# taglib prefix="s" uri="/struts-tags"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="mystatus" value="${param.mystatus}" scope="page"/>
<s:if test='%{#attr.mystatus == "TestThis"}'>
This is what we want
</s:if>
<s:else>
This is not what we want
</s:else>
Any additional params supplied to the included page are not accessible within the rendered page through the tag since no valuestack will be created.
refer to the Struts2 documentation for details.
Struts2 Include tag
You can, however, access them in a servlet via the HttpServletRequest object or from a JSP page via a scriptlet.something like
${param.ParamName}
I would just like to throw this in as an alternative to using the struts include tag.
You can instead use the jsp:include tag and use the struts s:push tag to push parameters onto the stack and make them available in the included page, it adds an couple of extra lines into the jsp but is much more flexible as you can pass objects rather than just strings into the included JSP.
The nature of the push tag means once your done the parameters are poped from the stack again.
Primary JSP
<s:push value="#{'someStringParam':'some string', 'someObjectParam': someObject}">
<jsp:include page="../includes/user-tabs.jsp" />
</s:push>
Included JSP
<s:property value="someStringParam" />
<s:if test="someObjectParam.someValue > 10">
Result!
</s:else>
Building from James' answer, this helped me on my Page 2:
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%# page isELIgnored="false" %>
<c:set var="mystatus" value="${param.mystatus}" scope="page"/>
<c:if test="${empty mystatus}">
<c:set var="mystatus" value="default status here" />
</c:if>
If you are passing a value from one page to another (as below) be careful about the syntax. You need to put single quotes around the name text you are passing, otherwise it's considered the name of a variable.
<s:include value="other.jsp">
<s:param name="thevar" value="'text i want to see'" />
</s:include>
Then in the "other.jsp" page you will see the "text i want to see" if you do as follows:
${param.thevar}
If, instead you do NOT place the single quotes in the param value attribute, you see nothing in the other.jsp page.
I only mention it as I've seen this a lot of times.
Is it possible to add ajax to the struts2 tags ,textfield or checkbox in jsp page using DOJO ? if yes how ?
Or if not what library should i use to apply ajax to single textField ?
Thanks
Take a look at the Struts2 jQuery Plugin.
This contains an AJAX Textfield Tag for Struts2.
To use DOJO, First of all add the DOJO tag directive like this
<%# taglib prefix="sx" uri="/struts-dojo-tags"%>
and then add the following line in the head part of your JSP
<sx:head debug="false" cache="false" compressed="true" />
Then listen the event from the struts tag on which you want to apply the ajax as follows
<s:radio label="Radio" name="rad" list="list2"
onchange="show_details();" ></s:radio>
catch this event in javascript and publish the topic as follows
<script>
function show_details() {
dojo.event.topic.publish("show_detail");
}
</script>
And listen the published topic on the same JSP by struts div tag
<sx:div showLoadingText="false" id="details" href="DetailAction" theme="ajax"
listenTopics="show_detail" formId="frm_demo"></sx:div>
The argument "show_detail" in the script call and div tag's listenTopics attribute should match exactally. That div will listen the topic and pick up the href attribute and matches with the action in struts.xml
<action name="DetailAction" class="ajaxdemo.action.DetailAction">
<result>/Detail.jsp</result>
</action>
It will call your action class ajaxdemo.action.DetailAction
and selects the values according to the value given by radio button and renders the following JSP Detail.jsp
<%# taglib prefix="s" uri="/struts-tags"%>
<s:if test="lstList != null">
<s:select list="lstList"></s:select>
</s:if>
and places the out put where you have defined your div tag in your main JSP
You can also view the detail example on java-tale.blogspot.com
I am using .NET MVC, and within view pages I set a contentplaceholder that contains an ID to be used on the master page like so:
View page:
<asp:Content ID="CDomBodyId" ContentPlaceHolderID="DomBodyId" runat="server">LmpDemoRequests</asp:Content>
Master page:
<body id='<asp:ContentPlaceHolder ID="DomBodyId" runat="server"></asp:ContentPlaceHolder>'>
So in this particular case, the body tag would render like this on the final HTML page:
<body id='LmpDemoRequests'>
I would like to have double quotes around the body id tag, but inverting the quotes like the following makes intellisense unable to find the contentplaceholder, giving me a lot of warnings when I compile.
<body id="<asp:ContentPlaceHolder ID='DomBodyId' runat='server'></asp:ContentPlaceHolder>">
Is there any way around this?
This is an issue with ASP.NET editor. It's not specific to MVC. I think the workaround is pretty good and I don't see a specific drawback.
Try declaring BodyID as a property of your MasterPage. Set its value in the View pages. Then you can do something like
<html>
<body='<%= BodyID %>'>
</body
</html>
Not sure if I have misunderstood your question, but you can also add:
<body id="site" runat="server"></body>
And then access it on your page
HtmlControl body = (HtmlControl)Master.FindControl("site");
body.Attributes.Add("class", "LmpDemoRequests");
I hope I understood your correctly.