The Issue:
We have a Java web application, based on Apache MyFaces Trinidad. We are facing some problems when trying to partial submit (that's it: via Ajax) a form, when a field contains some special characters, such as Ñ, á, etc.
When we write a value like camión at the text field, the resulting message is Hola cami (it drops the special char, and the next one).
The application server we are runnign our code at is IBM WebSphere AS 7.0.
This behaviour has been observed on IExplorer and Firefox browsers, all run from Windows XP Professional (spanish version).
Main code snippets:
UPDATE: based on lkdg's answer (thanks), I have updated the JSP and resulting HTML code snippets.
JSP Page Code:
<%#page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%# taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%# taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%# taglib uri="http://myfaces.apache.org/trinidad" prefix="tr" %>
<%# taglib uri="http://myfaces.apache.org/trinidad/html" prefix="trh" %>
<f:view>
<tr:document>
<trh:head title="Prueba de AJAX con todas las Cabeceras">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</trh:head>
<tr:form>
<tr:panelHorizontalLayout halign="left">
<f:facet name="separator">
<tr:spacer width="10" height="5"/>
</f:facet>
<tr:inputText id="elCampo" label="Your name" value="#{commandButtonBean.name}"
requiredMessageDetail="Name is required"
/>
<tr:commandButton id="sayHello" text="Say Hello"
partialSubmit="true"
action="#{commandButtonBean.sayHello}"
/>
</tr:panelHorizontalLayout>
<tr:spacer height="15px"/>
<tr:outputText value="#{commandButtonBean.message}" partialTriggers="sayHello"
inlineStyle="font-weight: bold;"/>
</tr:form>
</tr:document>
</f:view>
This is the resulting HTML output (removed some empty lines):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><!--Start: org.apache.myfaces.trinidad.Document["j_id_jsp_1876237926_1"]--><html dir="ltr" lang="es-ES">
<head>
<meta name="generator" content="Apache MyFaces Trinidad">
<link rel="stylesheet" charset="UTF-8" type="text/css" href="/ModuloTrinidadPilotoWeb/adf/styles/cache/bigfont-desktop-nur72r-ltr-gecko.css">
</head>
<!--Start: org.apache.myfaces.trinidad.Document["j_id_jsp_1876237926_1"]-->
<body onload="_checkLoad()" onunload="_checkUnload(event)"><script type="text/javascript">var _AdfWindowOpenError='Se ha detectado un bloqueo de ventana emergente en el explorador. Estos bloqueos interfieren con el funcionamiento de esta aplicación. Desactívelo o permita elementos emergentes desde esta dirección.';</script><script type="text/javascript" src="/ModuloTrinidadPilotoWeb/adf/jsLibs/Common1_2_10.js"></script><!--Start: org.apache.myfaces.trinidad.Document["j_id_jsp_1876237926_1"]--><div id="tr_pprBlockingDiv" onclick="return _pprConsumeClick(event);" style="position:absolute;left:0;top:0;width:0;height:0;cursor:wait;" onkeydown="return false;" onkeyup="return false;" onmousedown="return false;" onmouseup="return false;" onkeypress="return false;"></div><a name="top"></a>
<noscript>Esta página utiliza JavaScript y necesita un explorador activado para JavaScript. Su explorador no está activado para JavaScript.</noscript>
<!--Start: org.apache.myfaces.trinidad.Head["j_id_jsp_1876237926_2"]-->
<head>
<title>Prueba de AJAX con todas las Cabeceras</title>
<meta name="generator" content="Apache MyFaces Trinidad">
<link rel="stylesheet" charset="UTF-8" type="text/css" href="/ModuloTrinidadPilotoWeb/adf/styles/cache/bigfont-desktop-nur72r-ltr-gecko.css">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<!--Start: org.apache.myfaces.trinidad.Form["j_id_jsp_1876237926_3"]-->
<form id="j_id_jsp_1876237926_3" name="j_id_jsp_1876237926_3" style="margin:0px" method="POST" onkeypress="return _submitOnEnter(event,'j_id_jsp_1876237926_3');" action="/ModuloTrinidadPilotoWeb/jsp/sgtc/pruebaAjax2.faces"><!--Start: org.apache.myfaces.trinidad.Panel["j_id_jsp_1876237926_4"]--><table cellpadding="0" cellspacing="0" border="0" summary=""><tr>
<td><!--Start: org.apache.myfaces.trinidad.Input["elCampo"]--><table id="elCampo__xc_" class="af_inputText" cellpadding="0" cellspacing="0" border="0" summary=""><tr>
<td class="af_inputText_label" nowrap><span id="elCampo::icon" style="display:none;"><a name="_msgAnc_elCampo" title="Error" class="AFErrorIconStyle">X</a></span> <label for="elCampo">Your name</label></td>
<td valign="top" nowrap class="AFContentCell"><!--Start: org.apache.myfaces.trinidad.Input["elCampo"]--><input id="elCampo" name="elCampo" class="af_inputText_content" size="30" type="text"></td>
</tr><tr>
<td></td>
<td class="AFComponentMessageCell"><!--Start: org.apache.myfaces.trinidad.Input["elCampo"]--><span id="elCampo::msg" class="OraInlineErrorText"></span></td>
</tr></table></td>
<td><!--Start: org.apache.myfaces.trinidad.Object["j_id_jsp_1876237926_5"]--><img src="/ModuloTrinidadPilotoWeb/adf/images/t.gif" alt="" width="10" height="5"></td>
<td><script type="text/javascript">var _pprUpDatemode=false;function _adfspu(f,v,e,s,o){_pprUpdateMode=true;if(!o)o=new Object();if(e)o.event=e;if(s)o.source=s;_submitPartialChange(f,v,o);}</script><!--Start: org.apache.myfaces.trinidad.Command["sayHello"]-->
<button id="sayHello" name="sayHello" type="button" onclick="TrPage._autoSubmit('j_id_jsp_1876237926_3','sayHello',event,1);return false;" class="af_commandButton">Say Hello</button>
</td>
</tr></table><!--Start: org.apache.myfaces.trinidad.Object["j_id_jsp_1876237926_8"]--><div style="margin-top:15px"></div><!--Start: org.apache.myfaces.trinidad.Output["j_id_jsp_1876237926_9"]--><span id="j_id_jsp_1876237926_9" style="font-weight: bold;"></span><input type="hidden" name="org.apache.myfaces.trinidad.faces.FORM" value="j_id_jsp_1876237926_3"><!--Start: org.apache.myfaces.trinidad.Form--><span id="tr_j_id_jsp_1876237926_3_Postscript"><input type="hidden" name="javax.faces.ViewState" value="!-4fd3ee50"><script type="text/javascript">function _j_id_jsp_1876237926_3Validator(f,s){return _validateInline(f,s);}var j_id_jsp_1876237926_3_SF={};</script></span><script type="text/javascript">_submitFormCheck();</script></form>
</body>
<!--Created by Apache Trinidad (Apache MyFaces Trinidad API - 1.2.10/Apache MyFaces Trinidad Impl - 1.2.10), skin:bigfont.desktop (bigfont)--></html>
The CommandButton bean code:
public class CommandButtonBean {
public String name;
public String message;
public String sayHello(){
message = "Hola " + name;
return "";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
Of course, the command button is configured at faces-config.xml (I think that this snippet is not relevant).
Attempted fixes so far:
We have checked the charset encoding at different levels (application, JVM, etc). It seems to be aligned between the differen layers.
Also, we have included at web.xml the next context parameter:
<context-param>
<param-name>PARAMETER_ENCODING</param-name>
<param-value>UTF-8</param-value>
</context-param>
We have logged what is the value
passed as an argument to the
setName method, for if it could be
an error at writing the response. The
value passed is already wrong.
We have tried to write a web Filter,
to set the request charset to UTF-8 (just in
case, you know). But when logging the
parameter values at the filter, we
got the wrong value too.
At last we removed the
partialSubmit attribute of the
submit button, and got the right
value. But this won't really fix our
problem, as we are trying to
implement some inline searches and
validations (we don't want to repaint
the whole page).
So, when we send a normal POST message, we get the expected result, but when we try to use the Ajax approach, we loose these special characters.
And, at last, The Question:
Have you any suggestions on how to fix this issue?
Thank you very much.
This is a known issue with trinidad&WAS: http://www.mail-archive.com/dev#myfaces.apache.org/msg46298.html . You will have to make a small modification to two js files, you need to encode the sent characters (the solution there by Naveen Ravindra works). Edit these files:
trinidad-impl-XXX.jar\META-INF\adf\jsLibsDebug\xhr\XMLRequest.js
trinidad-impl-XXX.jar\META-INF\adf\jsLibs\xhr\XMLRequest.js
Add this new function to them (paste this to the beginning of the js:
function encodeCharacters(string) {
string = string.replace(/\r\n/g, "\n");
var utftext = "";
for ( var n = 0; n < string.length; n++) {
var c = string.charCodeAt(n);
if (c < 128) {
utftext += String.fromCharCode(c);
} else if ((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
}
else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}
}
return utftext;
}
Change the TrXMLRequest.prototype.send function in the same js. In it change
xmlhttp.send(content); to xmlhttp.send(encodeCharacters(content)); in the debug version, and
a4.send(a3); to a4.send(encodeCharacters(a3)); in the production version.
Tested, works in WAS 7.0.0.11.
Hi I can't reproduce your problem. Actually I don't get anything going if I try to program the jsp Page like you did. This is how my jsp's look like
<%# taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%# taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%# taglib uri="http://myfaces.apache.org/trinidad" prefix="tr" %>
<%# taglib uri="http://myfaces.apache.org/trinidad/html" prefix="trh" %>
<%# page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<f:view>
<tr:document>
<trh:head title="Your Title">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</trh:head>
</tr:document>
</f:view>
The tr:document, which you don't use creates a html, body and head tag.
You can use trh:head if you need it.
See trinidad's documentation:
Documentation tr:document
With this configuration I had no problem with an ó.
I have no PARAMETER_ENCODING set in web.xml and I am using jsf1.2 trinidad 1.2.14
This is not really an answer but it probably helps.
Regards
I've forgotten trinidad a bit, but in order for the button to affect the input text, dont you need a "partialTriggers" attribute set on the inputText component, which should have the ID of the button?
it is lkdg again
I tried to reproduce your issue.
jsp:
<tr:inputText
id="myfield"
value="#{myBean.myname}">
</tr:inputText>
<tr:commandButton
id="sayHello"
text="Say Hello"
partialSubmit="true"
action="#{myBean.sayHello}"/>
<tr:outputText
value="#{myBean.message}"
partialTriggers="sayHello"
inlineStyle="font-weight: bold;"/>
bean:
private String myname;
private String message;
public String sayHello()
{
message = "Hola " + myname;
return "";
}
public String getMyname() {
return myname;
}
public void setMyname(String myname) {
this.myname = myname;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
Everything works fine with ó and ễ and whatever.
jsf-1.2;trinidad1.2.14;apache tomcat6.0.29
I don't know the IBM WebSphere AS 7.0. But probably your problem has got something to do with what this guy is writing here: Displaying UTF-8 Characters in resource response
Related
User control (ascx) with a password input. Right-click, inspect - the value is visible. This doesn't happen if the password input is in an aspx.
Hmm, it seems I have to add some ramblings here, since the platform won't allow me to post this thread due to "mostly code".
Default.aspx
<%# Page Language="C#" %>
<%# Register Src="UserPassword.ascx" TagName="UserPass" TagPrefix="uc" %>
<script runat="server">
protected void Page_Load( object sender, EventArgs e )
{
if ( !X.IsAjaxRequest )
{
this.BindUser();
}
}
public void BindUser()
{
userPass1.UserName = "AliBaba";
userPass1.Password = "OpenSesame";
}
</script>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Password inspect bug</title>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager runat="server" />
<ext:Window
ID="Window1"
runat="server"
Icon="User"
Closable="false"
Title="Customer Details"
Width="350"
Height="230"
Resizable="false"
BodyStyle="background-color:#fff;"
BodyPadding="5"
Layout="Anchor">
<Items>
<ext:Panel ID="panel1" runat="server" Header="false" Layout="FitLayout">
<Content>
<uc:UserPass ID="userPass1" runat="server"></uc:UserPass>
</Content>
</ext:Panel>
</Items>
</ext:Window>
</form>
</body>
</html>
UserPassword.ascx
<%# Control Language="C#" %>
<script runat="server">
public string UserName
{
get { return this.txtUser.Text; }
set { this.txtUser.Text = value; }
}
public string Password
{
get { return this.txtPassword.Text; }
set { this.txtPassword.Text = value; }
}
</script>
<ext:Panel ID="panel1" runat="server" BodyPadding="5" Layout="AnchorLayout">
<Items>
<ext:Panel ID="panel2" runat="server" Border="false" Header="false" AnchorHorizontal="100%" Layout="FormLayout">
<Items>
<ext:TextField ID="txtUser" runat="server" FieldLabel="User" />
<ext:TextField ID="txtPassword" runat="server" FieldLabel="Password" InputType="Password" />
</Items>
</ext:Panel>
</Items>
</ext:Panel>
Are there any known workarounds?
Short answer: Use this.txtPassword.setValue(value) not this.txtPassword.Text = value to fix your direct problem.
Long answer: Why you are setting the password from the server? Best practice states that passwords are stored as hashes on the server so you don't actually know a users real password, you are just comparing two hashes.
public string Password
{
get { return this.txtPassword.Text; }
set { this.txtPassword.Text = value; }
}
If you want to autofill a password, which i assume you do, you need to use a cookie.
if (Request.Cookies["username"] != null)
{
this.txtUsername.setValue(Request.Cookies["uid"].Value);
this.txtPassword.setValue(Request.Cookies["pwd"].Value);
}
Today I've spend several hours reproducing a very strange UI behavior in our web application using JSF facelets: In some cases the UI was partially rendered in the web browser before the server side really finished rendering the whole view.
In the end it all came down to an JSF view with a large number of elements – in my case items of a submenu. There seems to be some threshold that triggers a partial flush of the response.
Here is a minimized example that visually demonstrates that effect:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="de" xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h:head>
<style>
td {
vertical-align: top;
}
</style>
</h:head>
<h:body>
<h1>EURNEU-10056</h1>
<table>
<tr>
<td>
<ol>
<ui:repeat value="#{bean.strings(10)}" var="str">
<li><h:outputText value="#{str}" /></li>
</ui:repeat>
</ol>
<h:outputText value="#{bean.delay(2000)}" />
</td>
<td>
<ol>
<ui:repeat value="#{bean.strings(10)}" var="str">
<li><h:outputText value="#{str}" /></li>
</ui:repeat>
</ol>
<h:outputText value="#{bean.delay(2000)}" />
</td>
<td><ol>
<ui:repeat value="#{bean.strings(10)}" var="str">
<li><h:outputText value="#{str}" /></li>
</ui:repeat>
</ol>
<h:outputText value="#{bean.delay(2000)}" />
</td>
</tr>
</table>
</h:body>
</html>
That simple view uses the following bean to generate a certain amount of strings and adds some artificial delays into the rendering of 2000ms after each of the 3 columns.
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import javax.faces.bean.ManagedBean;
#ManagedBean
public class Bean implements Serializable {
private static final long serialVersionUID = 1L;
public List<String> strings(int count) {
List<String> all = new ArrayList<>();
for (int i = 0; i < count; i++) {
all.add(UUID.randomUUID().toString());
}
return all;
}
public String delay(int delay) {
try {
Thread.sleep(delay);
}
catch (InterruptedException ex) {
// NOP;
}
return String.format("This string has been delayed for %d ms!", delay);
}
}
The browsers shows the following phases while processing the request:
If I lower the amount of strings used while generating the view the response is only flushed at the very end of the render phase.
Is there anything I can do to avoid that partial rendering? (other than lowering the number of elements)
PS: We are using JBoss EAP v7.0.9 as a server. The application itself is quite complex.
It turned our that explizit defining of Facelets buffer-size in web.xml solves that problem.
<!-- We raise the buffer size to avoid partial rendering of complex pages. -->
<context-param>
<param-name>javax.faces.FACELETS_BUFFER_SIZE</param-name>
<param-value>1024000</param-value>
</context-param>
That setting and the structure of the generated HTML define the very moment, the browser starts to render the response. In our case the menu was already renderable and showed much earlier than expected.
I have a problem and i was wondering if anyone can help me. Any help is really appreciated. And i m sure that its an 'easy' question.
I have a jsp page that shows dynamic data in tables, my problem is that the page has multiple tables.
But i want to export to excel only a specific table with a specific id.
So far i m exporting to excel all data from the jsp page which is wrong, cause i want to export only one table with id="formAssignDemands", how can i do it ?
Here is my code,
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%# page contentType="text/html;charset=windows-1253"%>
<%# taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%# taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%# taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
<%# taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j"%>
<f:view>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1253"/>
<f:loadBundle basename="bundles.requests" var="FieldsDescr"/>
<f:loadBundle basename="bundles.messages" var="GeneralMessages"/>
<title>
<h:outputText value="#{FieldsDescr.AssignRequests_Title}"/>
</title>
<a4j:loadStyle src="#{AssignDemands_backing.municipality.url}#{AssignDemands_backing.municipality.templateId}#{GeneralMessages.CssPath}"/>
<script language="JavaScript" type="text/javascript"
src="./demands.js"></script>
<script language="JavaScript" type="text/javascript"
src="../reports/reports.js"></script>
</head>
<body><h:form>
<jsp:include page="/system/NavigationMenu.jsp"/>
</h:form>
<%
String exportToExcel = request.getParameter("exportToExcel");
if (exportToExcel != null && exportToExcel.toString().equalsIgnoreCase("YES")) {
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "inline; filename="
+ "excel.xls");
}
%>
<table cellspacing="0" cellpadding="0" border="0"
width="99%" align="center">
<tr>
<td class="componentheading" width="99%">
<h:outputText value="#{FieldsDescr.AssignRequests_SubHeader}"/>
</td>
<td class="componentheading" width="1%">
<table>
......
<tr>
<td class="main_component_seperator" colspan="2"> </td>
</tr>
<tr>
<td align="center" colspan="2">
<h:form id="formAssignDemands">
<t:dataTable id="demandsDataTable"
binding="#{AssignDemands_backing.demandsDataTable}"
var="demand"
value="#{AssignDemands_backing.unassignedDemandsList}"
rows="#{NavigationMenu_backing.rows}"
varDetailToggler="detailToggler"
sortColumn="#{AssignDemands_backing.sort}"
sortAscending="#{AssignDemands_backing.ascending}"
preserveSort="true"
headerClass="datatable_td_header"
rowClasses="tablerow1, tablerow2"
width="100%"
rowIndexVar="demandsRowIndex">
<f:facet name="header">
<h:panelGroup>
<f:verbatim>
<div style="float:left;"></div>
</f:verbatim>
<h:panelGrid columns="4"
cellspacing="2">
<h:outputText value="#{GeneralMessages.DataTable_RowsPerPage}"/>
.....
</table>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<%
if (exportToExcel == null) {
%>
Export to Excel
<%
}
%>
</body>
</html>
</f:view>
<%-- oracle-jdev-comment:auto-binding-backing-bean-name:AssignRequests--%>
Thank you guys for any help or any idea,,
i managed to do it with javascript and is working on 3 basic browsers mozilla, chrome and IE11 , so here it is,
<script type="text/javascript">
function ExcelReport()
{
var tab_text="<table border='2px'><tr bgcolor='#FFFFFF'>";
var textRange; var j=0;
tab = document.getElementById('table_id'); // id of table
for(j = 0 ; j < tab.rows.length ; j++)
{
tab_text=tab_text+tab.rows[j].innerHTML+"</tr>";
}
tab_text=tab_text+"</table>";
tab_text= tab_text.replace(/<A[^>]*>|<\/A>/g, "");
tab_text= tab_text.replace(/<img[^>]*>/gi,"");
tab_text= tab_text.replace(/<input[^>]*>|<\/input>/gi, "");
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./))
{
txtArea1.document.open("txt/html","replace");
txtArea1.document.write(tab_text);
txtArea1.document.close();
txtArea1.focus();
sa=txtArea1.document.execCommand("SaveAs",true,"Excel.xls");
}
else
sa = window.open('data:application/vnd.ms-excel,' + encodeURIComponent(tab_text));
return (sa);
}
</script>
and to call it somewere in your body can add the following with an iframe, like that,
<iframe id="txtArea1" style="display:none"></iframe>
<button id="btnExport" class="button_class" onclick="ExcelReport();">Export to Excel</button>
thats it , thank you guys for reading
I am working on real time vehicle tracking project.
I am getting vehicle location after every 6 sec and I store lat and long in static variable each time.
I want to show vehicle moving on Google map after change location using ajax.
I have written code as:
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%# taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%# taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%# taglib uri="http://richfaces.org/rich" prefix="rich"%>
<%# taglib uri="http://code.google.com/p/gmaps4jsf/" prefix="m"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<META HTTP-EQUIV=" " CONTENT="6">
<title>Insert title here</title>
<script
src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAtRLgopSfFn_inKV4Mb4dwRQrh986W3YN5ROngdOVRv-81htxfBSHsTcVUm4HRkCt9bSp5mP_3_snrw"
type="text/javascript">
</script>
</head>
<body>
<f:view>
<h:form id="aaaa">
<h:panelGrid columns="2">
<m:map id="mp" width="500px" height="500px" latitude=" #{mp3.lat} "
longitude=" #{mp3.lon}" zoom="15">
<m:mapControl name="GMapTypeControl" />
<m:mapControl name="GLargeMapControl"
position="G_ANCHOR_BOTTOM_RIGHT" />
<m:marker id="m" latitude=" #{mp3.lat} " longitude=" #{mp3.lon}">
<m:htmlInformationWindow htmlText="Start<br> " />
<a4j:support event="onchange" action=" " reRender="m"></a4j:support>
</m:marker>
</m:map>
</h:panelGrid>
<h:commandButton value="Start" action="#{mp3.meth}" />
<h:commandButton value="Path Map" action="pathmp" />
</h:form>
</f:view>
</body>
</html>
My question is how to move vehicle marker on google map using ajax a4j without reloading all page?
technology i have used are
- jsf
- richfaces
- a4j
- javaBean
Thanks
I have a JSF page on Websphere Process Server (on top of WAS 7) which has ViewExpiredException. When this happens I want the user to be logged out and then logged back in
I've set up a redirect on this exception in web.xml to the following logout page:
<%
session.invalidate();
response.sendRedirect("ibm_security_logout?logoutExitPage=/faces/ToDosOpen.jsp");
%>
Which then redirects to a login page:
<%# page import="com.ibm.wbit.tel.client.jsf.infrastructure.Messages, java.util.Locale" language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%
String contextPath = request.getContextPath();
Locale locale = request.getLocale();
final String SECURITY_CHECK = "j_security_check";
%>
...
</head>
<body>
...
<h1><%= Messages.getString("LOGIN_LINE", locale) %></h1>
<div class="help-text"><%= Messages.getString("LOGIN_LINE_DESCR", locale) %></div>
<form target="_top" method="POST" action=<%= SECURITY_CHECK %>>
<table id="login-form">
<tr>
<td><%= Messages.getString("LOGIN_NAME", locale) %>:</td>
<td><input type="text" name="j_username"></td>
</tr>
<tr>
<td><%= Messages.getString("LOGIN_PASSWORD", locale) %>:</td>
<td><input type="password" name="j_password"></td>
</tr>
<tr>
<td id="login-button" colspan="2">
<input type="submit" name="login" value="
<%= Messages.getString("BUTTON_LOGIN", locale) %>"></td>
</tr>
</table>
</form>
And when you login you're redirected to the page that caused the exception in the first place. Except what actually happens is the exception is thrown again, and back we go to the login page.
So you have to login twice.
Not sure what to do about this or where to start looking. Any help would be appreciated.
I have looked through existing questions on this and haven't been able to solve it.
EDIT: I've forgotten to mention that this works fine if the action that triggered the exception was a refresh, but fails (having to login twice) if the action was clicking on a commandbar.
Finally solved it using the following ViewHandler.
This basically recreates the view that expired. In the case where there were POST parameters, they've obviously been lost so any view that cannot be created without them needs special handling.
Hopefully this is useful to anyone else who runs into this problem, and please let me know if you see anything wrong with this solution because I am not 100% confident in it.
/**
* This class just handles cases where the session expired
* which causes an exception on reload.
*/
public class ViewExpiredHandler extends ViewHandlerWrapper {
private ViewHandler wrapped;
public ViewExpiredHandler(ViewHandler wrapped) {
this.wrapped = wrapped;
}
#Override
public UIViewRoot restoreView( FacesContext ctx, String viewId )
{
UIViewRoot viewRoot = super.restoreView( ctx, viewId );
try {
if ( viewRoot == null) {
viewRoot = super.createView( ctx, viewId );
ctx.setViewRoot( viewRoot );
}
} catch (Exception e) {
e.printStackTrace();
}
return viewRoot;
}
#Override
protected ViewHandler getWrapped() {
return wrapped;
}
}