I am new to Blackberry development. Currently I am having 2 pages page1.qml and page2.qml. Now I am redirect to page2.qml from page1.qml on a button click using NavigationPane. Now I want to refresh page1.qml when we tap Back button on page2.xml. How i can refresh page.
Please Help me.
You can achieve this by passing page1 reference to page2.qml and call refresh() of page1.qml from paneProperties of page2.qml like :
Page1.qml
Page{
id: page1
.......
.......
Button {
onClicked: {
var page=page2.createObject()
page.page1Ref=page1
navigationpane.push(page)
}
}
function refresh(){
// write a code to refresh page1.qml
}
}
Page2.qml
Page{
id: page2
property Page page1Ref
.......
.......
paneProperties: NavigationPaneProperties {
backButton: ActionItem {
onTriggered: {
page1Ref.refresh()
navigationpane.pop();
}
}
}
}
Related
I have been working with controllers for a while and everything is working really great.
Until now!
My current scenario is that I have is a view that contains a button which triggers JavaScript code.
That JS code then triggers a method of a controller. And here I have an if condition that returns the view or does a RedirectToAction to another controller's method, which returns a view.
When pressing that button, I see in the debugger that my code runs through all those methods, when when it comes to returning the view, nothing happens.
Below is a simplified version of my code:
<script>
jQuery.ajax({
type: "POST",
url: "#Url.Action("applyChanges", "Controller1")",
data: { jsondata: config}
});
</script>
public class Controller1: Controller {
public ActionResult applyChanges(string jsondata)
{
return RedirectToAction("validateData", "Controller2", new { id = account.id});
}
}
public class Controller2: Controller
{
public ActionResult validateData(int id)
{
if(data.stored.under.this.id == false)
{
return View("validateData");
}
else
{
return RedirectToAction("viewList", "PMGLists", new { id = id });
}
}
}
The browser simply stays as if nothing happened.
What am I missing here?
I have a custom component that allows for editing a user. It displays a dialog which can be fed an existing user. Or not. It has the markup:
<button mat-button (click)="openUserDialog()">Edit</button>
and the controller:
#Component({
selector: 'app-user-edit',
templateUrl: './user-edit.component.html',
})
export class UserEditComponent implements OnChanges {
#Input() existingUser: User;
#Output() userEditedEvent: EventEmitter<User> = new EventEmitter<User>();
userDialogRef: MatDialogRef<UserDialogComponent>;
constructor(
private matDialog: MatDialog,
private userService: UserService
) { }
ngOnChanges() {
}
openUserDialog() {
this.userDialogRef = this.matDialog.open(UserDialogComponent, {
hasBackdrop: false,
data: {
user: this.existingUser
}
});
this.userDialogRef
.afterClosed()
.subscribe(user => {
// TODO validate the edited user
if (user) {
if (this.existingUser) {
user.id = this.existingUser.id;
this.userService.fullUpdate(user)
.subscribe(updatedUser => {
this.userEditedEvent.emit(updatedUser);
// TODO Add a hint that the user has been added
});
} else {
this.userService.add(user)
.subscribe(addedUser => {
this.userEditedEvent.emit(addedUser);
// TODO Add a hint that the user has been updated
});
}
}
});
}
}
The component is then being used in the users list page, once on top of the list to add a new user, with the markup:
<app-user-edit (userEditedEvent)="refreshList($event)"></app-user-edit>
and on each row of the list to edit the user, with the markup:
<app-user-edit [existingUser]="user" (userEditedEvent)="refreshList($event)"></app-user-edit>
The trouble is that the view displays the Edit label both to add and to edit a user.
How could I have a custom Add label on top of the list, and another Update label for each user ?
I feel like I may have overengineered the whole thing.
You can add another #Input parameter say label and pass the value of the label from the mark up.
export class UserEditComponent implements OnChanges {
#Input() existingUser: User;
#Input() label: string = "Edit" // set default to EDIT. If preferred can initialised to empty.
Mark up for ADD:
<app-user-edit (userEditedEvent)="refreshList($event)" label="ADD"></app-user-edit>
Mark up for EDIT:
<app-user-edit [existingUser]="user" (userEditedEvent)="refreshList($event)" label="EDIT"></app-user-edit>
Also, bind parameter label in view where it needs to be shown.
I have two controllers and each one have a flow. In my menu I have a link to the flows. If I'm in flow #1 and click in the link of the flow #2, Grails will show me the view of the flow #1.
The only way I found to make this transition work was to have a link to an action that redirects to the flow.
class FirstController {
def firstFlow = {
}
def toFirst() {
redirect action: 'first'
}
}
class SecondController {
def secondFlow = {
}
def toSecond() {
redirect action: 'second'
}
}
Going to /first/first shows the view correctly.
Going to /second/second shows the view of first.
Going to /second/toSecond redirects and show the view correctly.
Backing to /first/first shows the view of second
Goingo to /first/toFisrt shows the view correctly.
Is this a expected behavior? Why the flow don't go to the correct view?
EDIT
The menu is created using Platform Core Navigation API.
navigation = {
app {
first(controller: 'first', action: 'first', title: 'nav.exportar')
second(controller: 'second', action: 'second', title: 'nav.importar')
}
}
Links
http://localhost:8080/my-application/first/first?execution=e14s1
http://localhost:8080/my-application/second/second?execution=e14s1
If we want to cease a flow process (like clicking menu), we need to tell webflow end-state.
so the menu link url should include eventId parameter that means end-state.
I don't know navigation api, but g:link example below:
<g:if test="${params.action=='first'}"><%-- we are in first flow. --%>
<g:link event="toSecond">Go to second</g:link>
</g:if>
<g:else><%-- we are not in first flow, normal link. --%>
<g:link controller="second" action="second">Go to second</g:link>
</g:else>
and first controller:
class FirstController {
def firstFlow = {
// view-state
firstViewState {
on('next').to 'nextAction'
on('toSecond').to 'toSecond' // <g:link event='toSecond'> in gsp
}
// end-state
toSecond() {
redirect (controller:'second', action:'second')
}
}
def toFirst() {
redirect action: 'first'
}
}
I have two user controls on the page and one of the user control has this text aread.
which is used to add a note and but when they click add note button the page reloads.
I do not want the page to reload ,i was looking for an example which this is done without
postback.
Thanks
i tired doing this using JSON , but it throws the following error
The HTTP verb POST used to access path '/Documents/TestNote/Documents/AddNote' is not allowed.
<script type="text/javascript">
$(document).ready(function() {
$("#btnAddNote").click(function() {
alert("knock knock");
var gnote = getNotes();
//var notes = $("#txtNote").val();
if (gnote == null) {
alert("Note is null");
return;
}
$.post("Documents/AddNote", gnote, function(data) {
var msg = data.Msg;
$("#resultMsg").html(msg);
});
});
});
function getNotes() {
alert("I am in getNotes function");
var notes = $("#txtNote").val();
if (notes == "")
alert("notes is empty");
return (notes == "") ? null : { Note: notes };
}
</script>
</asp:Content>
Something like this would give you the ability to send data to an action do some logic and return a Json result then you can update your View accordingly.
Javascript Function
function AddNote(){
var d = new Date(); // IE hack to prevent caching
$.getJSON('/MyController/MyAction', { data: "hello world", Date: d.getTime() }, function(data) {
alert(data);
// call back update your view here
});
}
MyController Action
public virtual JsonResult MyAction(string data)
{
// do stuff with your data here, which right now my data equals hello world for this example
return Json("ReturnSomeObject");
}
What you want is AJAX update. There will always be a postback (unless you are satisfied with simple Javascript page update that does not save on the server), but it won't be the flashing screen effect any more.
Here's the behavior I'm looking for:
User selects a record from an index view, which redirects to that record's detail view.
User clicks a link to delete the currently displayed record.
A modal dialog asks for confirmation of the delete.
User presses the Confirm button.
The associated controller action method is executed, which is supposed to delete the record.
User is returned to the index view, where the deleted record is no longer displayed.
I am using ASP.NET MVC 1.0 as the primary framework, the dialog component from the jQuery UI, and LINQ-to-SQL to handle database interaction. Steps one through four execute just fine. Step five, however, retrieves the record, but doesn't delete it. Step six executes, but the record is still displayed in the list.
Here is the code for the delete link:
<% if (Model.CanDelete())
{ %>
<%= Html.ActionLink("Delete", "Delete", new { id = Model.Package_ID },
new { onclick = string.Format("deletePackage({0}); return false;", Model.Package_ID) })%> |
<% } %>
Here is the code for the onclick handler:
function deletePackage(packageID) {
createDialogContent(); // The HTML for the dialog content is set in this method
$.getJSON('/Spectrum/Package/DetailsJSON/' + packageID, function(json) {
$('p.message').html('Delete <strong>' + json.Description + '</strong>?');
});
$('div.confirm').attr('title', 'Delete Package');
$('div.confirm').dialog({
draggable: false,
modal: true,
overlay: {
backgroundColor: '#000',
opacity: 0.5
},
resizable: false,
buttons: {
'Confirm': function() {
$(this).dialog('destroy').remove();
$.post('/Spectrum/Package/Delete/' + packageID);
// The next line used to be: $.get('/Spectrum/Package/Index');
window.location.href = '/Spectrum/Package/Index';
},
Cancel: function() {
$(this).dialog('destroy').remove();
}
}
});
}
Here is the code for the delete controller method:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Delete(int id)
{
Package package = RepositoryManager.Package().GetPackage(id);
PackageDeleteViewModel viewModel = new PackageDeleteViewModel
{
Package_ID = package.Package_ID
};
RepositoryManager.Package().PackageDelete(viewModel); // see code below
return new EmptyResult();
}
Finally, here is the repository method for the delete:
public void PackageDelete(PackageDeleteViewModel data)
{
Package package = RepositoryManager.Package().GetPackage(data.Package_ID);
if (package.BrokerageOrderPackages.Count == 0
&& package.ManagementOrderPackages.Count == 0
&& package.Seeds.Count == 0)
{
db.Packages.DeleteOnSubmit(package); // This branch is being executed
db.SubmitChanges();
}
else
{
throw new RulesException("Package cannot be deleted.", "PackageDelete");
}
}
I don't think I'm pushing the envelope here or getting too fancy. One area of concern: In the Confirm button handler of the onclick method, the first version would delete the record successfully, but not redirect to the Index view. With the current version, the delete fails silently, but the redirection occurs. Firefox/Firebug reported 200's for the Index GET in both situations. The behavior is similar in both Firefox and IE.
$.post is an async ajax request, if you reload the page the call gets cancelled. You should reload the page on its callback function parameter:
$.post('/Spectrum/Package/Delete/' + packageID,
null,
function(json){
if (json.success) {
window.location.href = '/Spectrum/Package/Index';
} else {
// jquery dialog call or
alert(json.errorMessage);
}
},
'json');
And the controller code:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Delete(int id)
{
try {
// Validation and deletion code
} catch exception ex {
return Json(new {errorMessage = ex.Message, success = false});
}
return Json(new {success = true});
}