how to call sub mxml values into main mxml in flex? - java

Actually in my Flex sample applicaion have Main mxml called Demo.mxml..
in the main mxml file have login button when we click login button Login.mxml file called
protected function button2_clickHandler(event:MouseEvent):void
{
PopUpManager.createPopUp(this,Login);
}
In Login.mxml file doing some authetication useing java..
public var userService:UserService = new UserService();
[Bindable] public var userVO:UserVO = new UserVO();
protected function loginUser(event:MouseEvent):void
{
var rpcAuthenticateUser:AsyncToken = userService.authenticateUser(userid_id.text, password_id.text);
rpcAuthenticateUser.addResponder(new mx.rpc.Responder(handle_authenticate_success, handler_failure));
}
........
userVO=userService.getUser();
......
All are done in Login.mxml file correctly Now i am getting value.
How to get userVO object in Demo.mxml file ?
Actually i'm trying but it give some Null values......Plz help me
Thanks in Advance...

create a model class that is a singleton See my answer here about making a singleton.
then in your Demo.mxml
[Bindable] public var model:MyModel = MyModel.getInstance();
then in your login form
public var model:MyModel = MyModel.getInstance();
then when you get the response from the service:
model.userVO = userService.getUser();
now in your Demo.mxml, userVO is now populated and usable there.

Related

Tapestry: How to display an alert dialog from my Java code

I'm actually writing a java code in the setupRender() method. Depending of a value provided by the server side, i would like to display an Alert dialog box to the user. By clicking on ok, the application should be closed.
I have not already found how to display an Alert dialog box with tapestry. Do somebody know how to procedd?
Thanks
It's not quite clear to me what you are trying to achieve, but perhaps the following two suggestions are useful.
Suggestion 1 - Display a message using AlertManager
In the page class, inject AlertManager and add the message to it.
public class YourPage {
#Inject
AlertManager alertManager;
Object setupRender() {
// ...
alertManager.alert(Duration.UNTIL_DISMISSED, Severity.INFO, "Love Tapestry");
}
}
Then use the <t:alerts/> component in the page template file to have the message displayed.
Note: The user may dismiss the message, that is, make it disappear. But it doesn't 'close the application' (whatever it is that you mean by that).
Suggestion 2 - Redirect to another page
The setupRender method can return different things. For example, it could return another page class, causing a redirect to that page. On that page, you could have the messages displayed and the session subsequently invalidated (if that's what you meant by 'application should be closed'.
public class YourPage {
Object setupRender() {
// ...
return AnotherPage.class;
}
}
public class AnotherPage {
#Inject
Request request;
void afterRender() {
Session session = request.getSession(false);
session.invalidate();
}
}
See the Tapestry docs for details about what setupRender() can return.
Suggestion 3 - Use JavaScript to display Alert and trigger Component Event
This approach uses JavaScript to display an Alert and subsequently trigger a component event via ajax. The event handler takes care of invalidating the session.
Note: Closing the current browser windows/tab with JavaScript isn't as easy as it used to be. See this Stackoverflow question for details.
YourPage.java
public class YourPage {
boolean someCondition;
void setupRender() {
someCondition = true;
}
#Inject
private JavaScriptSupport javaScriptSupport;
#Inject
ComponentResources resources;
public static final String EVENT = "logout";
void afterRender() {
if (someCondition) {
Link link = resources.createEventLink(EVENT);
JSONObject config = new JSONObject(
"msg", "See ya.",
"link", link.toAbsoluteURI()
);
javaScriptSupport.require("LogoutAndCloseWindow").with(config);
}
}
#Inject Request request;
#OnEvent(value = EVENT)
void logout() {
Session session = request.getSession(false);
if (session != null) session.invalidate();
}
}
YourPage.tml
<!DOCTYPE html>
<html
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_4.xsd"
xmlns:p="tapestry:parameter">
<h1>Hit the Road Jack</h1>
</html>
LogoutAndCloseWindow.js
define(["jquery"], function($) {
return function(config) {
alert(config.msg);
$.ajax({
type: "GET",
url: config.link
});
window.close(); // Legacy. Doesn't work in current browsers.
// See https://stackoverflow.com/questions/2076299/how-to-close-current-tab-in-a-browser-window
}
})

PHP let value fixed in a controller page

I'm trying to do a thing in php that I've learnt in Java.
When a user logs in a website a Controller page saves in a private $userLogged var user infos and redirects him in index.php. Now, if he clicks on "profile" I would like that Controller page had in $userLogged his infos still. How I can do it? I've done this:
controller.php
class ECommerce
{
private $checker;
private $errorManager;
private $userLogged;
[...]
function userLogIn($data) {
$user = new User();
$this->userLogged = $user->getByEmail($data["email"]);
if($this->userLogged) {
if($this->userLogged->checkPassword($data["password"])) {
$_SESSION["ec_code"] = $this->userLogged->getCode();
$_SESSION["ec_name"] = $this->userLogged->getName();
$_SESSION["ec_surname"] = $this->userLogged->getSurname();
$_SESSION["ec_email"] = $this->userLogged->getEmail();
$this->redirect("e-commerce/index.php", null);
}
else {
$data["error_message"] = $this->errorManager->getErrorUserLogIn();
$this->redirect("e-commerce/accedi.php?err=1", $data);
}
}
else {
$data["error_message"] = $this->errorManager->getErrorUserLogIn();
$this->redirect("e-commerce/accedi.php?err=1", $data);
}
}
function seeUserProfile() {
$data["try"] = $this->userLogged->getName();
$this->redirect("e-commerce/profilo_utente.php", $data);
}
user_profile.php
<?php
session_start();
session_regenerate_id();
echo $_SESSION["data"]["try"];
what's wrong?
Thank you before!
Uh this is the error message I receive:
Fatal error: Call to a member function getName() on a non-object in /home/mhd-01/HOST_NAME/htdocs/e-commerce/controller/ECommerce.php on line 110
In user_profile.php you need to include the ECommerce class like Liquidchrome mentioned like so:
require('Controller.php');
and then you'll need to create an instance of your ECommerce Class
if you want to pass the same data to user_profile.php page you'll need to instantiate the user_profileclass and pass the instance of the ECommerce class you were using to it.

how to access javascript custom global variable in another function

I have developing phonegap android application. I'm trying to establish the communication between javascript and android java classes.
For Communication i have used addJavaScriptInterfaceMethod in android main activity.So that i can use java object and method in javascript.
following is the Java Code :
public class Activity extends DroidGap
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setIntegerProperty("loadUrlTimeoutValue", 60000);
super.loadUrl("file:///android_asset/www/jq3.html");
MapTablesWrapper table = new MapTablesWrapper();
super.appView.addJavascriptInterface(new MapTablesWrapper(), "tables");
}
}
And in javascript :the following code does not printing the table value.It's alerting undefined
var tableName = tables.getTableName();
function(){
alert(tableName);
}
And if i declare var table inside the function.Its printing the tableName and following code is
function(){
var table = tables.getTableName();
alert(tableName);
}
But i would like to declare variable outside of the function and want to use that varaible in inside the function.
You can do like
var global = {
table : null
};
function()
{
global.table = tables.getTableName();
alert(global.table);
}
you can rename global as your JS file name, so that this variable can be accessed all the functions in the current file and also in any other JS File by using your fileName.table here it is global.table

How to make java Object visible in Sub mxml to Main mxml file in Flex?

In my Application using Flex-Blazeds-java...,in my Flex application side have two mxml file
Main.mxml
Login.mxml
In Main.mxml file have button called Login click this button one popup open that is called Login.mxml
in this File i have authentication logic to connect java...sample code`
public var userService:UserService = new UserService();
[Bindable] public var userVO1:UserVO = new UserVO();
protected function loginUser(event:MouseEvent):void
{
var rpcAuthenticateUser:AsyncToken = userService.authenticateUser(userid_id.text, password_id.text);//Hear authenticateUser(-,-) is a java method it return UserVO object
rpcAuthenticateUser.addResponder(new mx.rpc.Responder(handler_success, handler_failure));
}
private function handler_failure(event:FaultEvent): void {
Alert.show("in handler_failure :" + event.message);
}
private function handler_success(event:ResultEvent): void {
userVO = event.result as UserVO;
Alert.show("test "+userVO.loginId);
}
Hear Login Working Perfectly according my Database logic and also if it is ResultEvent the Alert box show correct value (for ex:loginId is 'narasimham')...and everthing working perfectly no default in Login.mxml
Now The Problem Start...
I want to Use UserVO object in Main.mxml file so in that i'm using following code..
public var loginUserVar:Login = new Login();
protected function afterLoginUser(event:FlexEvent):void
{
Alert.show("LoginId ="+loginUserVar.userVO.loginId);
}
Actually my thinking this Alert box giving value narasimham but it is giving null value.
Why it is giving Null value?Is their any Scope specify to create variable?
In handler_success you need to set the value of userVO1 otherwise it won't be available otuside of your mxml file. You also need to to reference it in afterLoginUser as userVO1 instead of userVO.
Correct Ethrbunny i'm not store the value of userVO object so it is not available to Out side mxml file....
That's way in Flex(3.5) Application in Login.mxml file i'm adding following code...
Application.application.userVO = event.result as UserVO;
//Hear userVO is Object defined in Main.mxml file....

stringByEvaluatingJavascriptFromString (iOS method, what is Android equivalent?)

In an iOS app, I used
stringFromJavaScript = [webView stringByEvaluatingJavascriptFromString:#"document.getElementById(\"image\").getAttribute(\"src")"];
To get the src directory of the image that was being displayed on the webView. I want to do the same for Android. What are my options?
Basically the intent is to capture the path so that I can email this same picture...
ie.
"picture.php?image=%#",stringFromJavascript
This way, that same image would be loaded when the user clicks the link, or posts it to facebook etc.
Yeah, I miss this method greatly in Android ;)
To execute JavaScript and get response you can do as follows:
Define JavaScript callback interface in your code:
class MyJavaScriptInterface {
#JavascriptInterface
public void someCallback(String jsResult) {
// your code...
}
}
Attach this callback to your WebView
MyJavaScriptInterface javaInterface = new MyJavaScriptInterface();
yourWebView.addJavascriptInterface(javaInterface, "HTMLOUT");
Run your JavaScript calling window.HTMLOUT.someCallback from the script:
yourWebView.loadUrl("javascript:( function () { var resultSrc = document.getElementById(\"image\").getAttribute(\"src\"); window.HTMLOUT.someCallback(resultSrc); } ) ()");
Hope this helps!

Categories

Resources