I have a question about using parameters from the controller in the view.
This is my situation:
In my Controller I have :
foreach ($projects as $project) {
$projectTitle = $project->getName();
}
Now In my view I want to show every title from a project in a table.
How can I do this the right way? I also want to create a link with in my view like this :
"controller/action/projectid/1"
to edit the project.
Why not have an array called $titles and do an array_push inside the for loop like this:
array_push($titles,$project->getName())
And send the $titles directly to the view?
Related
Where, and how do I clear out the input date on a view....
E.g. when the data is saved, and I access my page from the menu, the old data is still displayed in the input boxes.
I've tried the onInit() function but that only fires the first time into the view.
The navto call is in the BaseController which calls the defaultTimes page (view/controller).
onNavToDefaultTimes : function(oEvent) {
this.getRouter().navTo("defaultTimes");
}
My clear code was in the _onRouteMatched function of detaultTimes.....
_onRouteMatched : function(oEvent) {
var view = this.getView();
view.byId("shopInput").setValue("");
view.byId("effectiveDateFrom").setValue("");
view.byId("shop24Hrs").setSelected(false);
view.byId("shopClosed").setSelected(false);
},
The problem is though, _onRouteMatched is also callled from navBack of the page following default times. And I don't want to clear the fields in this case.
How do I implement the clear from the onNavToDefaultTimes function of the base Controller only?
Can you give an example.
Let's say the name of the view in which your input field is created is test.js, then whenever you are navigating to the view or navigating from the view, you can use invalidate view like below
sap.ui.getCore().byId("test").invalidate();
this makes the view to be rendered again when you are coming back to the view and onBeforeRendering() is triggered
You can choose one of the following options, and put one of them, after the code to save is executed:
Option 1:
var yourInput = this.getView().byId("yourInputID");
yourInput.setValue("");
Options 2 (Try someone):
var yourInput = this.getView().byId("yourInputID");
yourInput.unbindValue();
yourInput.unbindElement();
yourInput.unbindObject();
Or put the code in the following method, which is executed every time the view is displayed:
onAfterRendering: function(){
//Option choosed
}
If I use this.getView() inside the controller of a view I can retrieve it without problems.
How can I retrieve the view if I am outside the controller (e. g. in controller of another view)?
I try sap.ui.core.Core().byId("<name of view>") but it returns undefined.
You can instantiate another view using:
var view = sap.ui.jsview("<name of view>");
If you´re using different view types you can choose the necessary function from here.
To avoid multiple instantiation you could do something like this:
var view = sap.ui.getCore().byId("id");
if (view === undefined) {
view = sap.ui.jsview("id", "<name of view>");
}
See this for more details regarding view definition/instantiation and IDs.
When I create a view i set a id
var theView=sap.ui.xmlview("OperationDetail, "<name of view>");
then i retrieve it by id
var theView = sap.ui.core.Core().byId("OperationDetail");
var myPage=theView.byId("pageOperation");
varRequired = sap.ui.getCore().byId("<name of view>");
this keyword refers to only the particular controller where as sap.ui.getCore() refers to the project views.
I have 3 radio buttons and 2 text boxes in a view. Initially I need to save the values in DB through the view and once its saved I need to display the saved values in the particular view according to which radio button I clicked.
One way is to post the values to a controller method, save it, then render back a new view with the values.
This got solved. We can use JQuery to achive tgis
View
--------
var url = '#Url.Action("YourActionName", "YourControllerName")';
$.post(url, 'ID=' + radio button Id , function (data) {
$('#txtBox1').val(data.Key1);
$('#txtBox2').val(data.Key2);
$('#txtBox3').val(data.Key3);
}
Controller
----------
Inside your action method , construct a JSON string as showed below and send back to JQuery Function.
var dataTest = new { "Key1"= "value1","Key2"= "value2", "Key3"= "value3" };
return Json(dataTest, JsonRequestBehavior.AllowGet);
i am developing an iphone application in which i have 3 classes => main class , abc class, pqr class. On main view , i have imageview on which i am displaying image. when user touch at the center of image on main view , new view will be pushed (depending on condition mentioned below)
a) if user came from abc view then
new view will not be pushed
b) if user came from pqr view then i
have to push new view .
My problem is how can i detect from which view user came to main view.
I create 1 class in which i have following code in .h file
typedef enum {
abcViewSelected,
pqrViewSelected
} SelectedViewType;
#interface Enumeration : NSObject {
SelectedViewType selectedViewType;
}
#property(nonatomic) SelectedViewType selectedViewType;
In . m file i have
#synthesize selectedViewType;
When user select table cell from abcView & pqrView , i am pushing main view & setting view type in didSelectRowAtIndexPath as follows :-
enumObj.selectedViewType = abcViewSelected;
enumObj.selectedViewType = pqrViewSelected;
In main view's touchBegan method i am compairing which view is selected by writing this
if(enum.selectedViewType == pqrViewSelected) => push new view
else do nothing.
But this is not compairing & in none of case new view is pushed. I have imported all the required header files everywhere.
Plz help me ....Thanks in advance.
The problem must be in this line:
if(enum.selectedViewType = pqrViewSelected)
Here you do not compare current type value, but rather assign pqrViewSelected to it (you have '=' instead of '=='). Try changing that line to:
if(pqrViewSelected == enum.selectedViewType){
// push view
}
Note that having constant expression as first parameter in comparison makes it impossible to mistakingly use assignment ('=') instead of comparison ('==').
I am creating an RCP application. I need to open multiple instances of the same view but with different data. I did it by setting secondary id for different instances of the same view. Specifically, my problem is as follows: Please take a look
I have a graph view called Views.GraphView. I opened different instances of it from a command called openGraphView to show different graphs. The command is as follows:
page.showView("Views.GraphView", Integer.toString(instanceNum++), IWorkbenchPage.VIEW_ACTIVATE);
Now, I have a command called TreeLayout on this Views.GraphView toolbar, which suppose to change the layout of the graph and it will operate on each instance of the view. But for this, I think, I need to identify which instance of the view is active. The TreeLayout command looks something like this:
IViewPart findView = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage(). findView( "Views.GraphView"); //I think in the findView I need to give the id of the view [but how can I put the secondary id?]
GraphView view = (GraphView) findView;
view.changeLayout(); //I wrote this method in the graph view to change the layout
//I just tried to print the secondary id, but it did not print anyting
System.out.println("From treelayout command:- " + view.getViewSite().getSecondaryId());
So how can I identify which instance of the view is currently active and to operate on it?
You can use IWorkBenchPage.findViewReference(String viewId, String viewId) , if it returns null, the view with viewId and viewId is not present in the current perspective.
If you have a ViewReference you can use ViewReference.getView(boolean restore) to get the view
so in your handler you get something like:
final IWorkbenchPage page = HandlerUtil.getActiveWorkbenchWindow(
event).getActivePage();
final int instanceNum = 8;//the number of instances that are created
for (int index = 0; index < instanceNum; index++) {
final IViewReference viewReference = page.findViewReference(
"Views.GraphView", Integer.toString(index));
if (viewReference != null) {
final IViewPart view = viewReference.getView(true);
if (view instanceof GraphView) {
final GraphView graphView = (GraphView) view;
graphView.changeLayout();
}
}
}
The view.getViewSite().getSecondaryId() method is the good one to identify a secondary view. This method only returns the Null string for the "primary" view: the one opened when user click Window -> Show View - Your View.
I don't understand why your view toolbar button has to operate on all the view instances. TO my eyes, you should have one button in each view instance toolbar operating only in its own view. If you really need to operate from one button to ALL the views I think you will have to keep the open views references yourself, because I think the workbench doesn't provide a findViews method returning a view array.
using the below code you should be able to get the current active view.
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart()
Active view and Editor name display on MessageDialogbox
public class Active_Workbench extends AbstractHandler{
#Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// A part service tracks the creation and activation of parts within a workbench page.
IPartService service = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService();
MessageDialog.openInformation(HandlerUtil.getActiveWorkbenchWindow(
event).getShell(), "Current Workbench Window", service.getActivePart().getTitle().toString());
return null;
}
}
I hope this answer is useful.