Why is there a difference between those two JSP files? - java

I have the following JSP.
<s:form id="cursorWait" theme="vs" action="list" method="get" acceptcharset="utf-8">
<div class="chckbox">
<s:checkbox id="as" name="as" />
<quartzi:text name="ts" />
</div>
<div class="chckbox">
<s:checkbox id="aec" name="aec" />
<quartzi:text name="tec" />
</div>
<div class="chckbox">
<s:checkbox id="aua" name="aua" />
<quartzi:text name="tua" />
<br/>
<br/>
</div>
<s:select name="seekRA" list="listeChoixRA" value="%{seekRA}" emptyOption="true"/>
<s:textfield id="numAff" name="seekCode" key="numeroaffaire" />
<s:textfield id="libAff" name="seekLibelleText" key="libelle" />
<s:a href="#" cssClass="action_effacer_sans_label" title="%{getText('effacer')}" onClick="gomme()"></s:a>
<s:hidden name="firstSearch" value="done" />
<s:submit id="recherche" key="rechercher" cssClass="wait"/>
</s:form>
<jsp:include page="inc_complex_search.jsp"/>
The three div checkbox are redundant to other files, so I decided to put them in a JSP file that I include. My page becomes:
<s:form id="cursorWait" theme="vs" action="list" method="get" acceptcharset="utf-8">
<jsp:include page="inc_checkbox_entity.jsp"/>
<s:select name="seekRA" list="listeChoixRA" value="%{seekRA}" emptyOption="true"/>
<s:textfield id="numAff" name="seekCode" key="numeroaffaire" />
<s:textfield id="libAff" name="seekLibelleText" key="libelle" />
<s:a href="#" cssClass="action_effacer_sans_label" title="%{getText('effacer')}" onClick="gomme()"></s:a>
<s:hidden name="firstSearch" value="done" />
<s:submit id="recherche" key="rechercher" cssClass="wait"/>
</s:form>
<jsp:include page="inc_complex_search.jsp"/>
with inc_checkbox_entity.jsp being:
<%# taglib prefix="s" uri="/struts-tags"%>
<%# taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%# taglib prefix="q" uri="/WEB-INF/tlds/q.tld"%>
<div class="chckbox">
<s:checkbox id="as" name="as" />
<q:text name="toutessocietes" />
</div>
<div class="chckbox">
<s:checkbox id="aec" name="aec" />
<quartzi:text name="tec" />
</div>
<div class="chckbox">
<s:checkbox id="aua" name="aua" />
<quartzi:text name="tua" />
</div>
And the result is... different...
and I don't understand why.
Shouldn't those two pieces of code produce the same exact page? What makes them different?
Here is a screenshot:
If I have the code in the main JSP, rather than using an include, then the search entities are under the block "société .. Unités analytiques" and aligned with it.
PS:
I have tried to use
<c:import url="inc_checkbox_entity.jsp"/>
but in this case the part between:
<s:select...
and <s:submit...
doesn't appear anymore.

If you use <jsp:include> there should be a jsp fragment to be included. But your custom tags didn't like to be included. Thus you might want to modify a jsp fragment so you can use <jsp:include> tag.
<%# taglib prefix="q" uri="/WEB-INF/tlds/q.tld"%>
<div class="chckbox">
<input type="checkbox" id="as" name="as" value="${as}"/>
<q:text name="toutessocietes" />
</div>
<div class="chckbox">
<input type="checkbox" id="aec" name="aec" value="${aec}"/>
<quartzi:text name="tec" />
</div>
<div class="chckbox">
<input type="checkbox" id="aua" name="aua" value="${aua}"/>
<quartzi:text name="tua" />
</div>
Some custom tags might also not work, better remove/replace them with JSP content if possible.

Related

Missing end tag for "form:input"

I have error in first line of following jsp page
<%#taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%#taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=ISO-8859-
1">
<link rel="stylesheet"
href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/boo
tstrap.min.css">
<title>Products</title>
</head>
<body>
<section>
<div class="jumbotron">
<div class="container">
<h1>Products</h1>
<p>Add products</p>
</div>
</div>
</section>
<section class="container">
<form:form modelAttribute="newProduct" class="form-horizontal">
<fieldset>
<legend>Add new product</legend>
<div class="form-group">
<label class="control-label col-lg-2 col-lg-2" for="productId">Product
Id</label>
<div class="col-lg-10">
<form:input id="productId" path="productId" type="text"
class="form:input-large" />
</div>
</div>
<!-- Similarly bind <form:input> tag for
name,unitPrice,manufacturer,category,unitsInStock and unitsInOrder
fields-->
<div class="form-group">
<label class="control-label col-lg-2" for="description">Description</label>
<div class="col-lg-10">form:textarea id="description"
path="description" rows = "2"/></div>
</div>
<div class="form-group">
<label class="control-label col-lg-2" for="discontinued">Discontinued</label>
<div class="col-lg-10">
<form:checkbox id="discontinued" path="discontinued" />
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-2" for="condition">Condition</label>
<div class="col-lg-10">
<form:radiobutton path="condition" value="New" />
New
<form:radiobutton path="condition" value="Old" />
Old
<form:radiobutton path="condition" value="Refurbished" />
Refurbished
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<input type="submit" id="btnAdd" class="btn btn-primary"
value="Add" />
</div>
</div>
</fieldset>
</form:form>
</section>
</body>
</html>
while doing this jsp i got error, I am new to view part and have little to none knowledge of Jstl el but while learning spring I got stuck in this error which says
Multiple annotations found at this line:
> - Missing end tag for
> "form:input"
>- Missing end tag for
> "form:input"
Am I missing something, how to solve this? even a small hint is welcomed too
Thanks
el will also evaluate expressions in comments, so you have to make the tags in comments as it is in "normal" page
Change
<!-- Similarly bind <form:input> tag for
name,unitPrice,manufacturer,category,unitsInStock and unitsInOrder
fields-->
to
<!-- Similarly bind <form:input/> tag for
name,unitPrice,manufacturer,category,unitsInStock and unitsInOrder
fields-->

How to apply struts2 tags on existing jsp file without affecting its css and js

I was given a HTML page I changed it's extension .jsp. I want to make dynamic web application using struts. My Html page code is like this..
<div id="content">
<div class="subpage-border-top">
<div class="subpage-border-bottom">
<div class="subpage-border-mid">
<div class="loginpage-bottom">
<h2>Login</h2>
<div class="loginpage-mid">
<span>Enter your email address and password to login</span>
<ul>
<li><label>Email</label>
<div class="right_input">
<input type="text" value=""
onblur="if(this.value=='')this.value=this.defaultValue;"
onfocus="if(this.value==this.defaultValue)this.value='';"
class="o-que email-text" />
<!-- <strong> dshmbf,sdmhfdi</strong>-->
</div></li>
<li><label>Password</label>
<div class="right_input">
<input type="password" value=""
onblur="if(this.value=='')this.value=this.defaultValue;"
onfocus="if(this.value==this.defaultValue)this.value='';"
class="o-que email-text" />
</div> <a href="#" class="forget-password">(Forget Your
Password)</a></li>
<li>
<div class="remember">
<input type="checkbox" name="" />Remember Me
</div>
<div class="login-button">
<div>
<input type="submit" value="Login" />
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
So it's layout looks like this..
And according to a tutorial I want to use struts tags..
<s:form action="User_login">
<s:textfield label="User Name" key="userName"/>
<s:textfield label="Password" key="password"/>
<s:submit/>
</s:form>
But what should I replace with these struts tags,so my struts can work and my layout(css,java script) remain intact..Please help.
Your CSS will break because your HTML will change.
Struts2 uses Themes to generate the HTML for each tag; the default theme is XHTML.
Just use SIMPLE theme, that will generate ONLY the tag without any side data (<label> for example).
It can be applied to a single tag, to a form, or globally at application level.
Then try
<s:form action="User_login" theme="simple">`
; if you are satisfied with the result, set it globally in struts.xml with
<constant name="struts.ui.theme" value="simple" />

JSTL formatNumber show empty string

In jsp I'm have this:
<h3>Order total: <fmt:formatNumber type="NUMBER" value="${order.total}"/></h3>
In html when open page:
<h3>Order total: <fmt:formatNumber value="20.0" type="NUMBER"/></h3>
But I'm don't see number, see only Order total:
full jsp:
<html xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:spring="http://www.springframework.org/tags"
xmlns:form="http://www.springframework.org/tags/form"
xmlns:fmt="http://java.sun.com/jstl/format">
<jsp:output omit-xml-declaration="yes"/>
<jsp:directive.page contentType="text/html;charset=UTF-8" />
<head><title>Spizza</title></head>
<body>
<h2>Your order</h2>
<h3>Deliver to:</h3>
<b>${order.customer.name}</b><br/>
<b>${order.customer.address}</b><br/>
<b>${order.customer.city}, ${order.customer.state}
${order.customer.zipCode}</b><br/>
<b>${order.customer.phoneNumber}</b><br/>
<hr/>
<h3>Order total: <fmt:formatNumber type="NUMBER"
value="${order.total}"/></h3>
<hr/>
<h3>Pizzas:</h3>
<c:if test="${fn:length(order.pizzas) eq 0}">
<b>No pizzas in this order.</b>
</c:if>
<br/>
<c:forEach items="${order.pizzas}" var="pizza">
<li>${pizza.size} :
<c:forEach items="${pizza.toppings}" var="topping">
<c:out value="${topping}" />,
</c:forEach>
</li>
</c:forEach>
<form:form>
<input type="hidden" name="_flowExecutionKey"
value="${flowExecutionKey}"/>
<input type="submit" name="_eventId_createPizza"
value="Create Pizza" />
<c:if test="${fn:length(order.pizzas) gt 0}">
<input type="submit" name="_eventId_checkout"
value="Checkout" />
</c:if>
<input type="submit" name="_eventId_cancel"
value="Cancel" />
</form:form>
</body>
</html>
The documentation says:
Standard Syntax:
<%# taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
XML Syntax:
<anyxmlelement xmlns:fmt="http://java.sun.com/jsp/jstl/fmt" />

How to fully convert JSP scriptlet into JSTL?

I am new to JSTL, could someone please tell me how to convert below JSP and HTML code to full JSTL with no scriptlet in the page?
I'd also be grateful for suggestions about some good resources to learn JSTL and advanced JSP concepts such as JSF and spring with CRUD example.
This is curd example taken from http://javaknowledge.info/?p=478. I took this example because I thought it is 100% JSTL implementation but I was wrong.
My IDE is NetBeans.
<form method="POST" action='UserController' name="frmAddUser">
<% String action = request.getParameter("action");
System.out.println(action);
%>
<% if (action.equalsIgnoreCase("edit")) {%>
User Name : <input type="text" name="uname"
value="<c:out value="${user.uname}" />" readonly="readonly"/> (You Can't Change this)<br />
<%} else {%>
User Name : <input type="text" name="uname"
value="<c:out value="${user.uname}" />" /> <br />
<%}%>
Password : <input
type="password" name="pass"
value="<c:out value="${user.password}" />" /> <br />
Email : <input
type="text" name="email"
value="<c:out value="${user.email}" />" /> <br />
<% if (action.equalsIgnoreCase("edit")) {%>
Registration : <input
type="text" name="dob"
value="<fmt:formatDate pattern="yyyy/MM/dd" value="${user.registeredon}" />" readonly="readonly"/>(You Can't Change this) <br />
<%} else {%>
Registration : <input
type="text" name="dob"
value="<fmt:formatDate pattern="yyyy/MM/dd" value="${user.registeredon}" />" />(yyyy/MM/dd) <br />
<%}%>
<input type="submit" value="Submit" />
</form>
There are only two types of scriptles:
print the current action into system's out - there is no JSTL alternative
if-else statement can be rewritten using
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%# taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:choose>
<c:when test='${ fn:toLowerCase(param.action) eq "edit" }'>
...
</c:when>
<c:otherwise>
...
</c:otherwise>
</c:choose>
Years ago i learnd alot from this videos:
https://www.youtube.com/user/3n3xus/videos
Too bad, its in German and eclipse.
You learn
how to write your own JSTL-Framework.
how to write and navigate in jsf
work with richfaces.
how to work with facelets.

create two button in one line in struts2

I have a form that have 2 buttons. one form register and another for cancel form. I create them with following code:
<s:submit name="cancel" key="project.button.cancel" />
<s:submit name="login" key="form.register.registerBtn" />
but I have a problem with its view. I will to command in one row. but it create two buttons in two row. you can see its picture in the following image:
how can I resolve this problem?
thanks.
update 2013/9/21 :
it is full jsp page code:
<%#taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath}/resources/css/form.css" />
<title>Insert title here</title>
</head>
<body>
<div style="padding-top: 20px;"></div>
<div style="width: 600px; margin: 0 auto;">
<div style="float: left; padding: 20px; padding-top: 0px;">
<img alt=""
src="${pageContext.request.contextPath}/resources/img/register.png">
</div>
<div class="box" style="width: 300px; float: left;" id="col">
<h1>
<span class="title"><s:text name="form.register.title" /></span>
</h1>
<hr />
<form action="login" method="post" namespace="/">
<span class="text"><s:text name="user.nickname" /></span>
<s:textfield name="nickname" />
<hr />
<span class="text"><s:text name="user.username" /></span>
<s:textfield name="username" />
<span class="text"><s:text name="user.password" /></span>
<s:password name="password" />
<span class="text"><s:text name="user.validation" /></span>
<s:password name="validation" />
<s:checkbox name="recoverable" key="user.recoverable" />
<hr />
<span class="text"><s:text name="user.email" /></span>
<s:textfield name="validation" />
<div style="display: inline-block; white-space: no-wrap;">
<s:submit name="cancel" key="project.button.cancel"
cssClass="button-red" />
<s:submit name="login" key="form.register.registerBtn"
cssClass="button-green" />
</div>
</form>
</div>
</div>
The possible solution to wrap them in one div tag and apply CSS
<s:form action="login" method="post" namespace="/" theme="simple">
....
<div style="display:inline-block;white-space:nowrap;">
<s:submit name="cancel" key="project.button.cancel" />
<s:submit name="login" key="form.register.registerBtn" />
</div>
</s:form>

Categories