<c:catch> does not work with <fmt:parseNumber> JSTL 1.2 - parsing

I'm implementing a simple JSP page using JSTL 1.2 (Apache Taglibs). The page does the following:
<c:catch var="error">
<fmt:parseNumber var="parsedNum" value="${param.num}" />
</c:catch>
The HTML input element looks like this:
<input type="text" name="num" size="3"/>
I'm aware that the input "12a" is permitted due to the way the parsing mechanism works. Nevertheless, I would like to catch completely wrong input, e.g., "aaa". Unfortunately, the thrown exception is not managed by <c:catch>, resulting in Tomcat 7 showing the whole stack trace.
Any advice? Thanks.

Please post a testable page for us. For example, the following page works fine for me.
<%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%# taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:catch var="error">
<fmt:parseNumber var="parsedNum" value="aaa" />
</c:catch>
${parsedNum}
${error}

Related

Microsoft edge v 17.17134 displays a # on postback

I recently stumbled upon a weird problem with the last version of Microsoft Edge (17.17134).
I have a really simple classic asp form that posts data to another asp form. If I post a string which contains
input
and
onclick=""
the receiving page will only display a "#" even if the code behind seems ok(see screenshot)
here's a snippet:
<!doctype html>
<html>
<body>
<form method="POST" action="to.asp">
<input type="text" name="hidInnerHTML" id="hidInnerHTML" style="width:500px;" value="steve would like your input on what to do when you activate the onclick= method" />
<br />
<input type="submit" value="click me"/>
</form>
</body>
</html>
and here is the code at the receiving end:
<!doctype html>
<html>
<body>
<div style="border:1px solid red;"></div>
</body>
</html>
It seems that certain keyword in the post data will trigger this effect. IE, chrome, probably Firefox, previous version of edge - all work correctly.
Any clues or idea what is happening here?
I'll take all the help I can get! :)
After doing a bit more research, i can see that this exact issue has just been raised here...
https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/19045578/
Check out the link for a fuller explanation but the short story is that you either set a "X-XSS-Protection" response header on your site with a value of "0" or you wait for the Windows 10 Insider Preview version (Build 17758) of Edge which includes the fix for this bug.
Microsoft Edge 44.17758.1.0
Microsoft EdgeHTML 18.17758

Datepicker is not showing in Internet explorer 8

I have used used struts-2 for my apllication and for creating datepicker i have used the "struts-jquery-tags"...it works fine in other browser but in Internet explorer, it is not showing at all..My code goes here
<%# taglib prefix="sj" uri="/struts-jquery-tags"%>
<sj:head/>
<sj:datepicker name="dueDate" id="dueDate" displayFormat="mm/dd/yy" label="Due Date" changeMonth="true" changeYear="true" title="Due Date" showButtonPanel="true" maxlength="10" readonly="true" buttonImage="/BPELServiceInvoke/resources/images/calendar_add.png" buttonImageOnly="true" duration="fast" />
This is strictly related to browser compatiblity issues for that plugin.
Best way would be to post here : https://code.google.com/p/struts2-jquery/wiki/DatePickerTag
Meanwhile, just try downgrading the version of plugin you're using. I'm sure the older-versions will be having support for IE8.
Also, look at the change-log for jquery version being used and it's support for IE8 - https://code.google.com/p/struts2-jquery/wiki/Changelog

Request scope issue in IBM portal 8.0

I have a JSR 286 portlet running in a Websphere Portal Server 8.0. There, I do a file upload and after show the results of processing. Initially my managed bean responsible to process this file has a Request Scope (#RequestScoped). When I Click in command button to upload file, the method in MB process correctly and fills a collection of results (dadosCarga attribute in MB below) that must be showed in JSP page. However, when I the page is rederized I got a stacktrace explaining that my Managed Bean class was not found (ClassNotFoundException) and results are not shown. I got the same results using ViewScoped. Just when I changed scope from Request to Session (#SessionScoped), the results are shown.
After I googled for some answer, I found this page explaining about difference between action and render request in Portlets. It was suggested to use JSF Portlet bridge. However, this page is not active anymore. There is a Portlet bridge for Apache Myfaces (IBM portal runs over MyFaces). However, I could not see how use it. Is it just put both jars (api and implementation) in WEB-INF/lib? I tried, but I got a exception when I tried load the pages in application. So I remove them.
Below, I show My Portlet configuration, Managed Bean and JSP page. Is there any alternative, a better Idea about how to deal with this? Or may be a explanation about how to use correclty MyFaces Bridge (I could not found none in its home page).
Thanks,
Rafael Afonso
Portlet configuration:
<portlet>
<portlet-name>CargaUsuarios</portlet-name>
<display-name>CargaUsuarios</display-name>
<portlet-class>com.ibm.faces20.portlet.FacesPortlet</portlet-class>
<init-param>
<name>com.ibm.faces.portlet.page.view</name>
<value>/pages/carga/cargaUsuarios.jsp</value>
</init-param>
<init-param>
<name>wps.markup</name>
<value>html</value>
</init-param>
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
</supports>
<portlet-info>
<title>Carga de Usuarios</title>
<short-title>Carga deUsuarios</short-title>
<keywords>Carga Usuario</keywords>
</portlet-info>
</portlet>
Manged Bean:
#ManagedBean(name = "cargaUsuariosMB")
#RequestScoped
public class CargaUsuariosMB extends AbstractMB {
private String nomeArquivo; // FIle name
private Collection<CargaUsuarioInfoBean> dadosCarga; // processing result.
public String doUploadArquivo() {
this.dadosCarga = ... // process file and receives a collection
this.nomeArquivo = ... // get uploaded file name
return null; // Return to same origin page
}
// Getters...
}
JSP page (cargaUsuarios.jsp):
<%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%#taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%#taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%#taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%#taglib
uri="http://www.ibm.com/xmlns/prod/websphere/portal/v6.1/portlet-client-model"
prefix="portlet-client-model"%>
<%#page language="java" contentType="text/html"
pageEncoding="ISO-8859-1" session="false"%>
<portlet:defineObjects />
<portlet-client-model:init>
<portlet-client-model:require module="ibm.portal.xml.*" />
<portlet-client-model:require module="ibm.portal.portlet.*" />
</portlet-client-model:init>
<f:view>
<h2>Carga de Usuários</h2>
<h:form enctype="multipart/form-data">
<p>
<label for="arquivoCarga"> <span>File:</span> </label> <input
type="file" name="arquivoCarga" id="FileCarga" />
</p>
<br />
<br />
<h:commandButton value="Salvar File"
action="#{cargaUsuariosMB.doUploadArquivo}"></h:commandButton>
</h:form>
<h:panelGroup id="pnlProcessamento"
rendered="#{not empty cargaUsuariosMB.dadosCarga }">
<h:outputText
value="Dados do File #{cargaUsuariosMB.nomeArquivo} processados com sucesso."></h:outputText>
<br />
<h:dataTable id="tblDadosProcessamento"
columnClasses="numLinha,cpf,status"
value="#{cargaUsuariosMB.dadosCarga}" var="dadosCarga"
styleClass="dadosProcessamento" width="100%" border="1">
<%-- Show processing results. --%>
</h:dataTable>
</h:panelGroup>
<h:messages styleClass="messages" id="msgsPesquisaCadastro"
errorClass="mensagensErro" errorStyle="color: red;"></h:messages>
</f:view>
Please try adding the following in the portlet.xml and see if it works:
<container-runtime-option>
<name>javax.portlet.actionScopedRequestAttributes</name>
<value>true</value>
</container-runtime-option>
For more information please download and check the following section in Portlet V2.0 specification:
PLT.10.4.4 Runtime Option
javax.portlet.actionScopedRequestAttributes
You are right about the render and action request, JSF (or CDI) Request and ViewScoped doesn't work properly. But solution could be using JBoss Portlet Bridge which contains brand new scopes - PortletLifecycleScoped and PortletRedisplayScoped. The first will behave exactly like a RequestScope, you will find more info in the docs. However, I am not sure if will able to use these scopes in other portals except GateIn.
When you use request scope, the data needs to be carried from portlet action to portlet render phase. The data is normally carried for request scoped beans via the portlet render parameters are a String. In order to get your data saved there, your object needs to be Serializable.
Besides that, you might want to upgrade your WebSphere Application Server beneath the WebSphere Portal to version 8.0.0.6 to avoid PM79460 and Portal itself to the latest FixPack as well.
Hope this helps.
BTW: JSR286 and JEE6 do not specify how CDI shall interact with the Portlet programming model. You might want to look at JSR362 for that.
IBM uses its own portlet bridge. It is not recommended to use any bridges in addition to that.

JSF 2.0 Warning about a component not surronded by an h:form tag [duplicate]

I am getting the following error on my Facelet page, which simply consists of an IceFaces form with two fields and two buttons:
The form component needs to have a UIForm in its ancestry. Suggestion: enclose the necessary components within <h:form>
Here is the form:
<ice:form id="form1" partialSubmit="false">
<ice:panelLayout id="panelLayout3">
<ice:graphicImage id="graphicImage1" url="/resources/images/LoginImage.jpg" width="560" />
<ice:outputLabel for="j_username" id="outputLabel1" value="Username:"/>
<ice:outputLabel for="j_password" id="outputLabel2" value="Password:"/>
<ice:inputText binding="#{login.username}" id="j_username" required="true" />
<ice:inputSecret binding="#{login.password}" id="j_password" required="true" />
<ice:commandButton actionListener="#{login.login}" id="loginBtn" value="Login"/>
<ice:commandButton action="#{login.reset}" id="resetBtn" value="Reset"/>
<ice:outputText id="errorMessage" />
<ice:message errorClass="errorMessage" for="j_username" fatalClass="fatalMessage" id="messages1" infoClass="infoMessage" showSummary="false" warnClass="warnMessage"/>
</ice:panelLayout>
</ice:form>
How is this caused and how can I solve it?
This is not an error. This is a warning. The code looks fine, all input components are inside a form, it seems that it should run and work fine. If it indeed works fine, just ignore the warning. This warning is displayed only when the context parameter javax.faces.PROJECT_STAGE is set to Development anyway .
As to the false warning message itself, this check was introduced in Mojarra 2.1.1 as per issue 1663. However, as per issue 2147 it turns out to have some bugs and is been further improved in Mojarra 2.1.3. I'd imagine that the false warning is in your particular case caused by having an <ice:panelLayout> between the form and the input elements.
If you aren't on Mojarra 2.1.3 yet, you may want to consider upgrading to see if it removes the false warning message.

Is there something special required to use dijit widgets within a Struts2 application with the DOJO plugin?

I am taking a prototype of a web page and implementing it. The prototype makes heavy use of DOJO for some fancy UI elements. The application is built using Struts 2.1.8.1 with the DOJO plugin enabled. I am able to use the dojo specific tags within struts but I can't get the any of the dijit widgets to work.
<%# page contentType="text/html; charset=UTF-8" %>
<%# taglib prefix="s" uri="/struts-tags"%>
<%# taglib prefix="sx" uri="/struts-dojo-tags" %>
<html xmlns="\"http://www.w3.org/1999/xhtml\"" xml:lang="\"en\"" lang="\"en\"">
<head>
<sx:head parseContent="true" />
<script type="text/javascript">
dojo.require("dijit.Dialog");
dojo.require("dijit.form.Button");
dojo.require("dijit.form.TextBox");
dojo.require("dijit.form.DateTextBox");
dojo.require("dijit.form.TimeTextBox");
dojo.require("dijit.form.Slider");
dojo.require("dijit.Menu");
dojo.require("dijit.layout.AccordionContainer");
dojo.require("dojox.charting.Chart2D");
dojo.require("dojox.charting.themes.PlotKit.blue");
dojo.require("dojox.charting.themes.PlotKit.orange");
dojo.require("dijit.layout.ContentPane");
dojo.require("dijit.layout.SplitContainer");
dojo.require("dijit.form.DateTextBox");
dojo.require("dijit.Tooltip");
</script>
The error I'm getting is:
GET http://localhost:9080/quickstart/struts/dijit/Dialog.js
GET http://localhost:9080/quickstart/struts/dijit/Dialog.js
404 Not Found
struts_dojo.js (line 769)
GET http://localhost:9080/quickstart/struts/dijit.js
GET http://localhost:9080/quickstart/struts/dijit.js
404 Not Found
struts_dojo.js (line 769)
ParamsHeadersPostPutResponseCacheHTML
Error 404: Error reported: 404
GET http://localhost:9080/quickstart/struts/dojo/__package__.js
GET http://localhost:9080/quickstart/struts/dojo/__package__.js
404 Not Found
struts_dojo.js (line 769)
ParamsHeadersPostPutResponseCacheHTML
Error 404: Error reported: 404
Could not load 'dijit.Dialog'; last tried '__package__.js'
[Break on this error] throw _13||Error(_12);
Do I need to make a special build of Dojo to get access to these dijit widgets?
The answer is because struts, as late as Struts 2.1.8.1 which is the most recent version as I am writing this, includes DOJO 0.4. Dijit seems to have been introduced sometime after Dojo 1.0. (Current version is 1.4).
The widget library to use with Struts is Dojo.widget which gets loaded by default with struts.

Resources