dynamic struts <html:option> - html

How to write dynamic struts <html:option>, I'm doing as below
<logic:iterate id="data" name="sendEmailForm" property="eventList">
<html:option value="<bean:write name="data" property="eventId"/>"/>
<bean:write name="data" property="title"/>
</html:option>
</logic:iterate>
but getting following error:
JSPG0069E: Unmatched end tag found while parsing jsp. Expecting
logic:iterate found html:option at [87,130]
is there another way to do so?
Thanks in advance.

<html:option property="title">
<html:optionsCollection name="sendEmailForm" label="title" value="eventId" />
<html:option>
html:option tag
property="?" whatever you want to set like if attribute is title and corresponding method (getTitle(), setTitle(String title) ) then property= "title"
html:optionsCollection tag
name = "?" whatever you have put in your request/session attribute
like (request Or session).setAttribute("sendEmailForm", ListArr);
then name="sendEamilForm"
listArr is array of object of bean ( may be formbean or simple pojofile/bean).
label ="?" what ever you want to show like if you have attribute 'title' and
corresponding setter(setTitle(String title)) and getter(getTitle()) method then
label="title"
value ="?" what ever you want to put as value in option. you call your getter method
corresponding attribute like if you have attribute eventId and method (
setEventId(String eventId) , getEventId() ) then value="eventId"

ok finally i found below for solution
<html:optionsCollection name="sendEmailForm" property="eventList" label="title" value="eventId" />

Related

How to fix the Angular syntax parser error within a Struts 2 <s:checkbox> tag?

I have encountered a strange error using AngularJS + Struts 2.
I have a Java object form with a boolean attribute named paid.
When I write:
<div class="col-sm-10 form-checkbox">
<s:checkbox name="xxxxx" ng-model="model"
ng-init="model = <s:property value = '%{form.paid}' />"
theme="simple" />
</div>
I get FireBug complaining about AngularJS syntax parser error which directs me to this page:
syntax error page
suggesting expression error.
And if I write:
<div class="col-sm-10 form-checkbox">
<s:checkbox name="xxxxx" ng-model="model"
ng-init="%{form.paid}"
theme="simple" />
</div>
No error is reported. I guess it is because Struts tags begin with <, which is not welcomed in Angular.
But, with this line no error is reported:
<select ng-model="estadoId"
ng-init="estadoId=<s:property value='%{form.estadoId}'/>"
name="form.estadoId" id="form.estadoId"
value="<s:property value='%{form.estadoId}' />" >
So, AngularJS is complaining about <> in Struts 2? Or, I am nor permitted to use <s:...> inside another <s:...>? If the latter is the case, why is complaning Angular not Struts 2??
In the first snippet, you are nesting Struts tags, that is a syntax error:
<s:checkbox name="xxxxx"
ng-model="model"
ng-init="model = <s:property value = '%{form.paid}' />"
theme="simple" />
In the second one, you are doing it right with OGNL, but you omitted the model = part:
<s:checkbox name="xxxxx"
ng-model="model"
ng-init="%{form.paid}"
theme="simple" />
The right version is the mix of the two:
<s:checkbox name="xxxxx"
ng-model="model"
ng-init="model = %{form.paid}"
theme="simple" />
Otherwise you could use a raw HTML tag (as in your <select> example, that is a standard HTML tag and not an <s:select>, hence no tags nesting is happening):
<input type="check" name="xxxxx"
ng-model="model"
ng-init="model = %{form.paid}" />
Note: in that case, you should create an hidden parameter under each checkbox to emulate the <s:checkbox> tag behavior and make the Checkbox Interceptor happy.

Iterate with index using thymeleaf

I am new to thymeleaf and am converting all my jsp code to thymeleaf.I don't know how to convert this below code to thymeleaf.Do anyone know how to convert the below code to thymeleaf?
<logic:iterate id="id" property="idList" name="sampleForm" indexId="i">
<label for="id<%=i%>">
<bean:write name="id" property="id" />
</label>
</logic:iterate>
Please tell me how to initialize the index value in thymeleaf to be used in some values??
<label th:each="id,status : ${idList}" th:for="|id${status.index}|" th:text="${id.id}"></label>
th:each will iterate over the idList, assign each item to id and create a label for each item. The status of the item can be assigned by adding an extra name, separated by a comma (status in this example).
th:for will set the for attribute of the label. The pipes (|) are used for easy string concatenation.
th:text will set the inner text of the label to the ID.
You can also use it like this:
<label th:each="id : ${idList}" th:for="${'id' + idStat.index}" th:text="{id.id}">
This starts the index from 0
If you want to start the index from 1 use this
<label th:each="id : ${idList}" th:for="${'id' + idStat.count}" th:text="{id.id}">
Check out the Thymeleaf documentation

Dynamically Creating list in Struts2 using tags

ArrayList<Integer> list = new ArrayList<Integer>();
list.add(2012);
list.add(2013);
list.add(2014);
list.add(2015);
can we do same as above using struts2 tags. may be by using
<s:set name="myList" value={somedynamic values} />
actually I want to create a list of number of 10 years on JSP page using Struts2 tags.
Regarding to your question answer is yes,but that is not an good idea to create number of 10 years in jsp page.
However, this is using arrylist in dynamic way
     
<s:select label="Years" headerKey="-1" headerValue="Select Years" list="list" name="your desire name" />
in the place of list property you have to give arrayList variable in your case it is list
means,
<s:select ---- list="your array list variable" --------- />
     and you have to define this action name in struts.xml
   eg:
<action name="yourarrylistvariable" class="your class" method="your method">
<result name="success">your jsp page</result>
</action>
    
     This is using arrylist in static way here you have to change the list value 
<s:select label="Years" headerKey="-1" headerValue="Select Years"
list="#{'2000':'2000', '2013':'2013',.....}" name="your desire name" />
For More Info You can refer this link struts2 select
Sure you can, thanks to the OGNL you can create lists like so:
<s:set var="myList" value="{2012,2013,2014,2015}" />
See this link.

Passing a url in a form from page to servlet drops part of query string

If I have a form on a JSP like this:
<form action = "/myApp/myServlet?rssFeedURL=${rssFeedURL}' />" method = "post">
<input type = "button" value = "See data for this RSS feed."/>
</form>
What I find is that if the variable ${rssFeedURL} has no query string, then the server receives it properly, e.g.:
http://feeds.bbci.co.uk/news/rss.xml
But if a query string exists, e.g.:
http://news.google.com/news?ned=us&topic=m&output=rss
I expect that it is to do with the encoding of the '&' character. Can anyone advise?
The server receives only:
http://news.google.com/news?ned=us
My pages are charset=UTF-8 encoded.
You need to URL-encode request parameters. Otherwise they will be interpreted as part of the initial request URL.
JSTL offers you the <c:url> for this.
<c:url var="formActionURL" value="/myApp/myServlet">
<c:param name="rssFeedURL" value="${rssFeedURL}" />
</c:url>
<form action= "${formActionURL}" method="post">
...
An alternative is to create an EL function which delegates to URLEncoder#encode().

Struts 1 bean tag inside HTML quotes

Here is my code:
<html:text name="rptData" property="emailAddress" onblur="checkIfEmpty('<bean:write name="rptData" property="status" />' , this.id)" />
This is nested inside a logic:iterate tag. What i need to do, is to pass value of 'status' to the javascript checkIfEmpty method. But i guess there is some error in the quotes. It is not working properly. Please anyone guide me. Thanks.
You can't nest custom tags like that, period, and it's unfortunate most of the answers imply you can, because that represents a fundamental misunderstanding of JSP.
Ideally, you wouldn't use the <logic:iterate> tag, as its use is not recommended when you have JSTL available: when JSTL and Struts 1 tag functionality overlaps, use the JSTL option. Then use standard JSP EL to access the variable.
<c:forEach items="listOfThings" var="current">
...
<html:text ... onblur="checkIfEmpty('${rptData.status}', ${current.id})" ...
...
In this example I also assumed that this was supposed to refer to the current iteration object, defined in the <c:forEach> tag.
ok after doing some research i found out the answer.
if i have some code like this:
<html:text styleId="emailAddress+<%=statusC.toString() %>" name="rptData" property="emailAddress" />
its output is as follows:
<input type="text" name="emailAddress" value="abc#gmail.com" id="emailAddress+<%=statusC.toString() %>" />
but if i use
<html:text styleId="<%=statusC.toString() %>" name="rptData" property="emailAddress" />
the output is:
<input type="text" name="emailAddress" value="abc#gmail.com" id="Approved" />
That means without string concatenation the output is correct. i.e. only using
styleId="<%=statusC.toString() %>"
rather then
styleId="emailAddress + <%=statusC.toString() %>"
or even
styleId="emailAddress" + <%=statusC.toString() %> - This results in an error, though
yeilds correct output.
So the workaround is to first intialize a complete java String in a scriplet then use it inside the styleId tag.
<% String emailId = "emailAddress" + statusC.toString() ;%>
<html:text styleId="<%=emailId%>" name="rptData" property="newEmailAddress" />
It will work fine. Cheers !
You might want to try adding some escape characters while using double quotes inside double quotes like in your case it would be some like:
onblur="checkIfEmpty('<bean:write name=\"rptData\" property=\"status\" />' , this.id)"
Try this:
<html:text name="rptData" property="emailAddress" onblur="checkIfEmpty('<bean:write name=\'rptData\' property=\'status\' />' , this.id)" />