Transform WSDLtoJava in Spring boot and JSP - java

I have a JSP page and a Spring boot controller, in the jsp i have a form with a select and options when i choose the option i need to pass that value to a java code to transform WSDL to java classes. How can i do it?
<form id="form" action="genclasses" method="post">
<select name="WSDLcat" class="custom-select ml-2" id="inputGroupSelect04">
<%
ServiceClass[] services = (ServiceClass[]) request.getAttribute("services");
%>
<c:forEach items="${services}" var="service">
<option id="WSDL" value="${service.getWsdl()}">
${service.getNombre()}</option>
</c:forEach>
</select>
<input class="btn btn-outline-secondary align-right" id="genclases" type="submit" onclick="generarClases()" value="Generar Clases">
</form>
String[] params= {"-d","./src/main/resources/generatedFiles","HERE I NEED THE VALUE OF THE OPTION"};
WSDLToJava.main(params);
ZipUtil.pack(new File("./src/main/resources/generatedFiles"), new File("./src/main/resources/generated.zip"));
I cannot do it in java inserted in jsp becasuse i need to use different libraries and i do not know how to pass it to the controller or do it in the same page. Any help?

Related

How to combine AngularJS and Thymeleaf templates

I am converting a web page currently using Thymeleaf to instead use AngularJS.
I want to convert the follow block containing Thymeleaf
<form th:action="#{?deleteLog}" th:object="${log}" method="post" class="in-line">
<input type="hidden" th:value="${log.vid_id}" name="vid_id" />
<input type="hidden" th:value="${log.id}" name="id" />
<button type="submit" class="btn btn-danger">Delete</button>
</form>
These th:value variables are being passed to a #PostMapping method in my controller class that then uses those variables to delete an entry from my database.
How can I achieve this using AngularJS? Taking the same approach I have
<form th:action="#{?deleteLog}" method="post" class="in-line">
<input type="hidden" th:value="{{x.vid_id}}" name="vid_id" />
<input type="hidden" th:value="{{x.id}}" name="id" />
<input type="button" value="Remove" class="btn btn-danger" ng-click="removeRow(tableList.id)" />
</form>
The removeRow() function successfully removes the row from the table in the UI, I just need to send the {{x.vid_id}} and {{x.id}} values to the method in my controller class.
I am obviously not using correct syntax because I am getting parsing errors for the th:value="{{x.id}}" thymeleaf variables when I try to use Angular. I've also tried th:value="${{x.id}}"' and th:value="${{{x.id}}}".
I haven't been able to find anything online regarding passing an Angular variable. Is this even possible?
You shouldn't mix AngularJS (SPA framework for client-side HTML templating) with Thymeleaf (library for server side HTML templating). You should choose to do templating on server or client and stick with it.
Combining these two doesn't make sense at all.

Append to JSP view using Java

I have a form in my JSP which has a list box.
I want on submit of the form, I do some server side validation on and then duplicate the list box and append it to jsp again?
Can someone help me know how we can achieve this ?
Jsp :
<form:form commandName="user">
<div id="primaryList">
<select name="data" size="5" id="s">
<option value=""></option>
</select>
</div>
</form:form>
I know we can do it using javascript, but I need validation done on server side before duplicating.

Use common JSP with a custom Servlet and Struts 2

(Oups.. Sorry for my english :) )
In my web application, Struts2 is used as the main Servlet dispatcher and filter. But For some reasons, i have a custom filter and a custom servlet used for a specific url "/book".
But I have some commons jsp... i had some issues when the custom Servlet should display my request attributes in the JSP because of the struts tags (implemented before). So i changed these tag by the jstl taglibs and it works now.
But... In one JSP, the main (lol)... I have a search form.. This JSP is included in several JSPs and could be called by Struts and the custom Servlet..
With only Struts the tag was "< s:form>.." and when the form was submitted, all sended values was kept in the input... But now, because of the custom Servlet i use a simple html form which is calling the struts action "search.do".
As source code is below:
<form method="post" action="<c:out value="${contextPath}"/>/search.do" name="search" id="search">
<input type="text" id="search_searchWord" value="" maxlength="200" size="100" name="searchWord">
<div align="right">
<input type="submit" value="Ok" name="searchButton" id="search">
</div>
<select id="search_searchCrit" name="searchCrit">
<option value="0">Crit1</option>
<option value="1">Crit2</option>
<option value="2">Crit3</option>
</select>
</form>
My problem is the search word and the selected option are refreshed after the submit. I need to keep them !
Is there a way to use the struts taglibs with a Standard Servlet ?
Or Do you have another solution to keep the submitted information ?
Thanks all !
take each field value from the input field and write js function to fill each field in jsp source code of your page.
function selectedValue(){
var value =<%=request.getParameter("searchCrit")%>;
if(value !=null)
{
document.getElementById('search_searchCrit').innerHTML=value;
}
}
I found a solution with the help of #java_seeker.
In my Struts action, i got the request through this way :
HttpServletRequest request = ServletActionContext.getRequest();
request.setAttribute("searchWord", this.getSearchWord());
There is two different way to do this, see: http://www.mkyong.com/struts2/how-to-get-the-httpservletrequest-in-struts-2/
The attribute is setted in each method (in the action) that could refresh the page.
Then, i just recovered and set the attribute from the request as a variable with a jstl tag and display it as the value of my html input:
<c:set var="searchWord" value='<%=request.getAttribute("searchWord") %>' />
<input type="text" id="search_searchWor" value='<c:out value="${searchWord}" />' name="searchWord">
For the , i just used an <c:choose><c:when test=""></c:when><c:otherwise><c:otherwise></c:choose> to set the selected choice.
Now all value are always displayed. Maybe it's not the very good way to display share the same JSP between a standard servlet and a Struts action, but it works. I'm open to try a better solution if you have one! Thanks all!

Need to use html form select input on other html pages within the site

The index page of the site will ask user to select a stage area. I want to pass their selection from page to page until they log out or return to this selection.
I have searched long and hard but just don't know how to phrase that question to a web search. Just need a little push in the right direction. Form code below and thanks in advance.
<form name="pick" method="POST" action="http://wavepick.htm">
<table border="0">
<tr VALIGN="TOP">
<td width="177">
<select id="stageChoice" name="stageArea">
<option selected value=" ">(Select Staging Area)</option>
<option value="A">A </option>
<option value="B">B </option>
</select>
</div>
<input type="submit" name="Submit" value="Stage" name="B1">
<input type="hidden" name="request_id" value="wavepick">
</form>
You can store the selected value between pages in a session variable.
If you want to do this only with HMTL/Javascript, you have to submit this form via "GET" (instead "POST"), and at each page you need to send again "stageArea" to the another page, so:
Page1.html?stageArea=B
Page2.html?stageArea=B
Page3.html?stageArea=B
That's how you read GET parameters via Javascript: How can I get query string values in JavaScript?
Ya, it's very arduous just with HTML/Javscript.
But you have mentioned "log out", do you have back-end (like PHP, ASP.NET,etc..)? With back-end language it'll be much more easier, you could store stageArea on session once, and just read it at each page.
If you are using a backend language such as PHP you can store that value in a $_SESSION variable. and access it wherever you need during that session.
Here is the documentation for the session variables:
PHP Session
If not, let me know and i'll figure out a different method for you.

Pass Two different values on a form to a servlet?

Given the following HTML:
<form action="" name="<%=rs.getString(1)%>" method="post">
<select name="opcao">
<option value="Did not like">Did not like</option>
<option value="Ok">Ok</option>
<option value="Liked" selected="selected">Liked</option>
<option value="Loved!">Loved!</option>
</select>
</form>
Is it possible to get the name of the form and from the select tag to the same servlet as different parameters?
HTML form name is NOT submitted as part of the request. Although if you want, you can pass as form hidden field as below:
<form name="myForm" action="/my_servlet">
<input type="hidden" name="htmlFormName" value="myForm"/>
....
However if you have two form fields, then they are passed to servlet and can be accessed using request.getParameter("fieldName") method inside the servlet..

Categories