PDA

View Full Version : Why can not Login ?



nikolayLevin
13 Jul 2010, 12:43 AM
hello evrybody, i would like to make a login panel with sencha touch for iphones, i used touch library and i want to use JSP to check user informations. I can not send form values to JSP file. What is wrong with my code?
Login.js file;

Ext.setup({
onReady: function(){
var formBase = {
scrool: 'vertical',
items: [{
xtype: 'fieldset',
title: 'Login',
defaults : {
required : true,
labelAlign: 'left'
},
items : [
{
xtype: 'textfield',
name: 'name',
placeholder: 'Kullanici Adi / UserName'
},{
xtype: 'passwordfield',
name: 'password',
placeholder: 'Sifre / Password'
},
{
xtype: 'select',
name : 'language',
label: 'Dil/Language',
options: [
{text: 'Turkce', value: 'turkish'},
{text: 'English', value: 'english'}
]
}
]
}
],
dockedItems :[{
xtype : 'toolbar',
dock : 'bottom',
items : [
{
text: 'Login',
ui:'action',
handler : function(){
Ext.getBody().mask(false, '<div class="demos-loading">Loading&hellip;</div>');
Ext.Ajax.request({
url: 'loginUser.jsp',
method: 'post',
params: loginForm.getValues(),
success: function(response, opts) {
x = Ext.decode(response.responseText);

if (x.errorMessage != null)
alert(x.errorMessage);
else {
mainPanel.setCard(dashboard, 'slide');
}
Ext.getBody().unmask();
}
});
}
},
{
text: 'Reset',
handler: function(){
form.reset();
}
}
]
}]

};
if (Ext.platform.isAndroidOS) {
formBase.items.unshift({
xtype: 'component',
styleHtmlContent: true,
html: '<span style="color: red">Forms on Android are currently under development. We are working hard to improve this in upcoming releases.</span>'
});
}

if (Ext.platform.isPhone) {
formBase.fullscreen = true;
} else {
Ext.apply(formBase, {
autoRender: true,
floating: true,
modal: true,
centered: true,
hideOnMaskTap: false,
height: 385,
width: 480


});
}
var form = new Ext.form.FormPanel(formBase);
form.show();
}
}
)

Login.JSP file;
<%
String result;
String loginUsername = request.getParameter("name");
if (null != loginUsername && loginUsername.length() > 0) {
if (loginUsername.equals("name"))
result = "{success:true}";
else
result = "{success:false,errors:{reason:'Login failed.Try again'}}";

} else {
result = "{success:false,errors:{reason:'Login failed.Try again'}}";
}
%>
<%=result %>

TommyMaintz
14 Jul 2010, 11:23 AM
I could only find one thing that was wrong with your code. You were calling loginForm.getValues() instead of form.getValues();



Ext.setup({
onReady: function() {
var formBase = {
scrool: 'vertical',
items: [{
xtype: 'fieldset',
title: 'Login',
defaults: {
required: true,
labelAlign: 'left'
},
items: [
{
xtype: 'textfield',
name: 'name',
placeholder: 'Kullanici Adi / UserName'
},
{
xtype: 'passwordfield',
name: 'password',
placeholder: 'Sifre / Password'
},
{
xtype: 'select',
name: 'language',
label: 'Dil/Language',
options: [
{
text: 'Turkce',
value: 'turkish'
},
{
text: 'English',
value: 'english'
}
]
}
]
}
],
dockedItems: [{
xtype: 'toolbar',
dock: 'bottom',
items: [
{
text: 'Login',
ui: 'action',
handler: function() {
Ext.getBody().mask(false, '<div class="demos-loading">Loading&hellip;</div>');
Ext.Ajax.request({
url: 'loginUser.jsp',
method: 'post',
params: form.getValues(),
success: function(response, opts) {
x = Ext.decode(response.responseText);

if (x.errorMessage != null)
alert(x.errorMessage);
else {
mainPanel.setCard(dashboard, 'slide');
}
Ext.getBody().unmask();
}
});
}
},
{
text: 'Reset',
handler: function() {
form.reset();
}
}
]
}]

};
if (Ext.platform.isAndroidOS) {
formBase.items.unshift({
xtype: 'component',
styleHtmlContent: true,
html: '<span style="color: red">Forms on Android are currently under development. We are working hard to improve this in upcoming releases.</span>'
});
}

if (Ext.platform.isPhone) {
formBase.fullscreen = true;
} else {
Ext.apply(formBase, {
autoRender: true,
floating: true,
modal: true,
centered: true,
hideOnMaskTap: false,
height: 385,
width: 480


});
}
var form = new Ext.form.FormPanel(formBase);
form.show();
}
}
)


This sends a request to your jsp file for me, sending the correct post data.

nikolayLevin
14 Jul 2010, 11:57 PM
Thank you Tommy, when i tried form.getValues() instead of loginForm.getValues() it sent the parameters to JSP file correctly. Thank you very much

TommyMaintz
15 Jul 2010, 11:34 AM
Didn't your debugger tell you that loginForm was undefined? Both chrome and safari have a debugger that helps you solve these problems very easily. When I ran your code, it told me that loginForm was not defined.

nikolayLevin
22 Jul 2010, 5:57 AM
i havent use debugger yet, but i will use debugger anymore