BlackBerry save checkbox state in persistent store - blackberry

I have a login page (username,password fields) that has a checkbox 'Remember me'. If the checkbox is selected, the application is required to remember the username & password for next login. That is done and working fine. However I am finding it hard to save the state of the checkbox field, i.e. whether it is checked or not. I am saving the username/password through the following code:
if (persistentObject.getContents() == null)
{
persistentHashtable = new Hashtable();
persistentObject.setContents(persistentHashtable);
} else {
persistentHashtable = (Hashtable) persistentObject.getContents();
}
if (persistentHashtable.containsKey("username") && persistentHashtable.containsKey("password"))
{
username.setText((String) persistentHashtable.get("username"));
passwd.setText((String) persistentHashtable.get("password"));
}
If the checkbox is selected and login is successfull, username and password are saved through the following:
if(checkBox1.getChecked() == true)
{
persistentHashtable.put("username", user_id);
persistentHashtable.put("password", password);
}
I tried to save the checkbox state with the line below but that is incorrect.
persistentHashtable.put("checkbox", checkBox1.setChecked(true));
Can somebody please help?

RIM rapc.exe compiler does not support autoboxing (it works in java 1.3 compatibility mode), and then you need to wrap your boolean value to a Boolean class instance before saving it in a hashtable or passing it to persistent store.

Hey guys I managed to find a solution to my problem. I worked around by checking if the username field is empty, then the checkbox state should be 'unchecked' else it should be 'checked'. This is doing what I wanted. If anyone of you have a better way of doing this please do suggest. My working line of code is as below:
if(username.getText().length()==0)
{
checkBox1 = new CheckboxField("Remember me",false);
}
else
{
checkBox1 = new CheckboxField("Remember me",true);
}
false = unchecked , true = checked

Check box is used for user wishes , according to your code , If user have entered user name checkbox will be checked.
Your Code is bit complex , First you need to setcontent code to persistent in very last , once you set your hashtable . You are having a login screen so you must have a submit button.
Do like this on submit button event:
// to set persistent values
if(checkBox1.getChecked() == true)
{
persistentHashtable = new Hashtable();
persistentHashtable.put("username", user_id);
persistentHashtable.put("password", password);
persistentHashtable.put("checkbox", "true");
persistentObject.setContents(persistentHashtable);
persistentObject.commit() ;
}
// to get from persistent values
if (persistentObject.getContents() != null)
{
persistentHashtable = (Hashtable) persistentObject.getContents();
username.setText((String) persistentHashtable.get("username"));
passwd.setText((String) persistentHashtable.get("password"));
String boolval = (String) persistentHashtable.get("checkbox");
if(boolval.equals("true"))
checkBox1 = new CheckboxField("Remember me",true);
else
checkBox1 = new CheckboxField("Remember me",false);
}

Related

SWT: Integrate clickable link into StyledText

With the help of this question I was able to figure out how I can display a link inside a StyledText widget in SwT. The color is correct and even the cursor changes shape when hovering over the link.
So far so good, but the link is not actually clickable. Although the cursor changes its shape, nothing happens if clicking on the link. Therefore I am asking how I can make clicking the link to actually open it in the browser.
I thought of using a MouseListener, tracking the click-location back to the respective text the click has been performed on and then deciding whether to open the link or not. However that seems way too complicated given that there already is some routine going on for changing the cursor accordingly. I believe that there is some easy way to do this (and assuring that the clicking-behavior is actually consistent to when the cursor changes its shape).
Does anyone have any suggestions?
Here's an MWE demonstrating what I have done so far:
public static void main(String[] args) throws MalformedURLException {
final URL testURL = new URL("https://stackoverflow.com/questions/1494337/can-html-style-links-be-added-to-swt-styledtext");
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout(1, true));
StyledText sTextWidget = new StyledText(shell, SWT.READ_ONLY);
final String firstPart = "Some text before ";
String msg = firstPart + testURL.toString() + " some text after";
sTextWidget.setText(msg);
sTextWidget.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
StyleRange linkStyleRange = new StyleRange(firstPart.length(), testURL.toString().length(), null, null);
linkStyleRange.underline = true;
linkStyleRange.underlineStyle = SWT.UNDERLINE_LINK;
linkStyleRange.data = testURL.toString();
sTextWidget.setStyleRange(linkStyleRange);
shell.open();
while(!shell.isDisposed()) {
display.readAndDispatch();
}
}
Okay I was being a little too fast on posting this question... There's a snippet that deals with exactly this problem and it shows, that one indeed has to use an extra MouseListener in order to get things working.
The snippet can be found here and this is the relevant part setting up the listener:
styledText.addListener(SWT.MouseDown, event -> {
// It is up to the application to determine when and how a link should be activated.
// In this snippet links are activated on mouse down when the control key is held down
if ((event.stateMask & SWT.MOD1) != 0) {
int offset = styledText.getOffsetAtLocation(new Point (event.x, event.y));
if (offset != -1) {
StyleRange style1 = null;
try {
style1 = styledText.getStyleRangeAtOffset(offset);
} catch (IllegalArgumentException e) {
// no character under event.x, event.y
}
if (style1 != null && style1.underline && style1.underlineStyle == SWT.UNDERLINE_LINK) {
System.out.println("Click on a Link");
}
}
}
});

Display contact address in ios using xamarin

absolute beginner with xamarin.
Followed the following tutorial to try and simply click a button to display the contact list, select a contact, and then to display firstname, surname, and address on the screen.
https://github.com/xamarin/recipes/tree/master/Recipes/ios/shared_resources/contacts/choose_a_contact
Managed to get the firstname and surname to be displayed, but cannot get the address. Constantly getting the error
Foundation.MonoTouchException: Objective-C exception thrown. Name: CNPropertyNotFetchedException Reason: A property was not requested when contact was fetched.
On the
contanct.PostalAddresses
This is the snippet of code:-
partial void UIButton197_TouchUpInside(UIButton sender)
{
// Create a new picker
var picker = new CNContactPickerViewController();
// Select property to pick
picker.DisplayedPropertyKeys = new NSString[] { CNContactKey.GivenName, CNContactKey.FamilyName, CNContactKey.PostalAddresses };
// Respond to selection
var pickerDelegate = new ContactPickerDelegate();
picker.Delegate = pickerDelegate;
pickerDelegate.SelectionCanceled += () => {
SelectedContact1.Text = "";
};
pickerDelegate.ContactSelected += (contact) => {
SelectedContact1.Text = contact.GivenName;
SelectedContact2.Text = contact.FamilyName;
SelectedContact3.Text = contact.PostalAddresses
};
pickerDelegate.ContactPropertySelected += (property) => {
SelectedContact1.Text = property.Value.ToString();
};
// Display picker
PresentViewController(picker, true, null);
}
Am i missing something?
Seem to have resolved this if anyone else is having a similar issue.
The solution was to completely close down visual studio on the mac and re-open it.
Originally, i was stopping the project, and re-building. Possibly a bug, but non of my changes where being picked up.
A simple re-start kicked it back in

Not able to clear cookies properly

Hi my application has two types of login's one is facebook and other is normal log in. To differentiate between them and bring the values accordingly i have used cookies and clearing those in logout event like this.
But when i login through email and password and then logout and again log in through Fb the UserCookie cookie is still persisting and its entering to the first if statement again
public ActionResult Logout(string returnUrl = "/")
{
try
{
FormsAuthentication.SignOut();
}
finally
{
if (Request.Cookies["UserCookie"] != null)
{
Request.Cookies["UserCookie"].Expires = DateTime.Now;
Request.Cookies["UserCookie"].Value = "";
}
if (Request.Cookies["fbUserUserID"] != null)
{
Request.Cookies["fbUserUserID"].Expires = DateTime.Now;
Request.Cookies["fbUserUserID"].Value = "";
}
if (Request.Cookies["fbFirstName"] != null)
{
Request.Cookies["fbFirstName"].Expires = DateTime.Now;
Request.Cookies["fbFirstName"].Value = "";
}
FederatedAuthentication.WSFederationAuthenticationModule.SignOut(true);
}
//return Redirect(returnUrl);
return View();
}
and in my view i am checking for cookies like this
#if (HttpContext.Current.Request.Cookies["UserCookie"] != null && HttpContext.Current.Request.Cookies["UserCookie"].Value != "")
{
}
else if (HttpContext.Current.Request.Cookies["fbFirstName"] != null && HttpContext.Current.Request.Cookies["fbFirstName"].Value != "")
{
}
but its not clearing i guess its showing empty string "" for the cookie value in the controller but i donno whats happening in view.
is there any thing that i am missing?
Request.Cookies is used to read the cookies that have come to the server from the client. If you want to set cookies, you need to use Response.Cookies so the server sends the cookie information the server response.
Try modifying your code to use Response.Cookies instead of Request.Cookies when you are trying to unset the cookies.

Jquery compelete function not working

I m very much new to the jQuery and AJAX technology. I am trying to create a form which will insert the values in the database without refresh the page. Most of the code are working as expected. But among there are two case which is not working as expected.
I am fetching values through checkbox. When I select only one checkbox it works but when I select multiple checkbox, the value stored in the database as Array.
I want to display a message once the form data submitted succesfully but its not working.
Please find the below respective code for the same.
Jquery:
$('#add').click(function(){
var domain_type = $('#domain').val();
var domain_zone = $('#domain_zone').val();
var client_name = $('#client_name').val();
//var language[] = "";
var lang = new Array();
if(language==1){
//alert("You select one language");
valid = true;
lang = "English";
}else{
//alert("You select multiple language");
var i =0;
$.each($('input[name=lang]:checked'), function(){
lang.push($(this).val());
});
var count = lang.length;
if(count ==1){
alert("You need to select two languages");
var valid = false;
}else if(count>2){
alert("You can select only two languages");
var valid = false;
}else{
valid = true;
}
}
var formMsge = $('#formStatus');
$('#formStatus').html('<img src="./img/loader.gif"> Please wait while adding the data in database.');
$.ajax({
type: "POST",
url: "./test/test.php",
data: {domain_type:domain_type, domain_zone:domain_zone, client_name:client_name, 'lang[]':lang},
success:function(conf){
$('#formStatus').ajaxComplete(
function(event,request){
if(conf=="OK"){
$('#formSuccess').show();
$('#addClient').hide();
}else{
$('#formError').show();
$('#forError').text("Please try again");
}
}
);
}
});
return false;
});
test.php:
include('../../classes/access_user/all.class.inc.php');
echo $workstream->addClient()
;
php class file:
public function addClient(){
$domain_type = isset($_POST['domain_type'])?$_POST['domain_type']:'';
$domain_zone = isset($_POST['domain_zone'])?$_POST['domain_zone']:'';
$client_name = isset($_POST['client_name'])?$_POST['client_name']:'';
$lang = isset($_POST['lang'])?$_POST['lang']:'';
$add_by = 'Robindra Singha';
$add_on = date("Y-m-d");
if(isset($domain_type) || isset($domain_zone) || isset($client_name) || isset($lang)){
$sql = "INSERT INTO client_list (domain_type_id, client_name, domain_zone, language, add_on, add_by, last_update_on, last_update_by) VALUES('$domain_type','$client_name','$domain_zone','$lang','$add_on','$add_by','$add_on','$add_by')";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_inserted_id() != 0){
$msg = "OK";
}else{
$msg = "System face an issue while adding client details!";
}
}else{
$msg = "System face an issue while adding client details, please try again!";
}
return $msg;
}
In above code, my issue is checkbox value are not able to pass when I select the multiple checkbox, second I am not able to display any text once the form is successfully submit. Except this two issues, my code able to insert the information successfully. I would be glad if any one guide me in completing the work properly. Thank you in advance for your kind support.
Note: I am not able to add the HTML file as i paste here, it display as normal text. please suggest.

Can't delete Cookies that I get after Facebook Connect

I implemented Facebook-Connect successfully and I'm able to retrieve User-Information using the Facebook Toolkit. But I cant sucessfully logout.
When I press the facebook-Logout button (which automatically appears when I'm logged in, because I'm using the autologoutlink-property)
<fb:login-button autologoutlink="true"></fb:login-button>
I still have all five Facebook-Cookies:
MyApiKey
MyApiKey_ss
MyApiKey_SessionKey
MyApiKey_expires
MyApiKey_user
After I'm logged out, I'm really logged out in Facebook, because I need to login again at facebook.com but isConnected() always returns true and I can still retrieve the user Information:
var connectSession = new ConnectSession(ConfigurationManager.AppSettings["ApiKey"], ConfigurationManager.AppSettings["Secret"]);
if (connectSession.IsConnected())
{
var api = new Api(connectSession);
filterContext.Controller.ViewData["FBUser"] = api.Users.GetInfo();
}
First I don't understand why I can still retrieve User Information even though I'm not logged in any more, and secondly: How I can delete this Cookies. The Following Code didn't work:
public static void ClearFacebookCookies()
{
String[] shortNames = new String[] { "_user", "_session_key", "_expires", "_ss", "" };
HttpContext currentContext = HttpContext.Current;
if (currentContext == null)
{
return;
}
string appKey = ConfigurationManager.AppSettings["APIKey"];
if (appKey == null)
{
throw new Exception("APIKey is not defined in web.config");
}
foreach (var name in shortNames)
{
string fullName = appKey + name;
HttpCookie cookie = currentContext.Response.Cookies[fullName];
if (cookie != null)
{
cookie.Value = null;
cookie.Expires= DateTime.Now.AddDays(-1d);
}
HttpCookie cookieRequest = currentContext.Request.Cookies[fullName];
if (cookieRequest != null)
{
cookieRequest.Value = null;
cookieRequest.Expires = DateTime.Now.AddDays(-1d);
}
}
}// end Method
This may be a shot in the dark, but did you make sure the fb.init is placed just before the closing body tag?
<script type="text/javascript" src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US"></script>
<script type="text/javascript">FB.init('somekey');</script>
That's caused me problems before.

Resources