How to add One modelAndView object to another ModelAndView object - object

How to add one modelAndView object to another ModelAndView object. Like i have one ModelAndView object mv1 and i want another modelandview object mv2 value to be added to mv1.can i use mv1.addObject("mv1",mv2);

As you said, if you want to add one ModelAndView inside another:
mv1.addObject("mv2", mv2);
If you want to include all objects from one ModelAndView to another one:
mv1.addAllObjects(mv2.getModel());

Related

from an activity to new xml file without making new class for the xml

I want to know if threre is a way to use a button.OnclickListener() to go from one activity to xml file without making a class for that xml.For example:
btn.OnClickListener(new OnclickListener(){
#Override
public void onClick(View v) {
Intent i = new Intent(ex.this, ex.class);
startActivity(i);
}};
we use the intent to go from activity class to another new activity class, and in the new class there is setContentView(R.layout.example); in onCreate method, so the xml layout will be displayed.
but I ask if there is a way to display the xml layout withot making a class activity.
There isn't if want to go to a new activity I believe you need a class. You can do this programatically without any XML.
(however I am reasonably new to android so could be wrong)

Watir: how to find iframe's tag?

I have an element, for example #<Watir::IFrame:0x..f98fef949215c673e located=false selector={:element=>(webdriver element)}>. How do I determine what tag it is (iframe)?
Found it by searching for similar Javascript method: there exists element.tag_name, but when using it for iframe I get NoMethodError: private method 'tag_name' called for #<Watir::IFrame:0x00000002f8c288>'.
What does it mean and is there some alternative to .tag_name for iframes?
The exception means that the tag_name method is private for Watir::IFrame (and Watir::Frame) objects. "Private", along with "public" and "protected", methods are used for controlling access of methods within a class. The Ruby Pickaxe book has a good description of the method types:
Public methods can be called by anyone---there is no access control. Methods are public by default (except for initialize, which is always private).
Protected methods can be invoked only by objects of the defining class and its subclasses. Access is kept within the family.
Private methods cannot be called with an explicit receiver. Because you cannot specify an object when using them, private methods can be called only in the defining class and by direct descendents within that same object.
Ultimately, this means that you cannot call the tag_name from outside of the class.
Given that the Watir API allows calling the tag_name method for other element types, I would say it is a bug. A pull request has been opened to have the method made public Issue 293.
As a workaround, you can call private methods by using send:
browser.iframe.send('tag_name')
#=> "iframe"
Note that given you already have a Watir::IFrame object and depending on what you are trying to do, you might not need to check the tag name. You could check the class of the object instead:
browser.iframe.class
#=> Watir::IFrame

How to display multiple ListViews in one activity

In my application I need to display multiple (three) listviews at a time sections wise. Can anyone suggest me a best way to implement this.
Thanks in advance,
Chandra.
Maybe you want to look into fragments.
http://developer.android.com/guide/components/fragments.html
if you create the ListView's in an XML file, you can just specify the ID attribute like so: android:id="#+id/listView1, providing a different ID for each ListView. In your Java code, you will want to extend Activity and create three ListView objects and point them towards the IDs in your XML file. Once you have a handle on the ListView's, you want to create a data source and ArrayAdapter<String> for each ListView. I prefer to use ArrayList<String> over the convential String[] simple because, to me, they are easier to use. A working Java sample below would work for a single ListView. Duplicate the variables and objects twice more with differing names for the two other ListViews. Hope this helps:
public class MainListActivityExample extends Activity {
ListView listView1;
ArrayList<String> lvContents1 = new ArrayList<String>;
ArrayAdapter<String> lvAdapter1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Tell the method which layout file to look at
setContentView(R.layout.listViewExample_activity);
// Point the ListView object to the XML item
listView1 = (ListView) findViewById(R.id.listView1);
// Create the Adapter with the contents of the ArrayList<String>
lvAdapter1 = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, lvContents1);
// Attach the Adapter to the ListView
listView1.setAdapter(lvAdapter1);
// Add a couple of items to the contents
lvContents1.add("Foo");
lvContents1.add("Bar");
// Tell the adapter that the contents have changed
lvAdapter1.notifyDataSetChanged();
}
In order to add the other two ListViews, create two more ListView objects, two more ArrayList<String> objects, and two more ArrayAdapter<String> objects, each with corresponding names so you know which belongs to which. You can then follow the exact same steps to initialize them.

Alternative to #ModelAttribute

I am using spring mvc for my web application.
I want alternative to #ModelAttribute.
I am setting model object in jsp file by filling form details and right now in controller i am getting it by using #ModelAttribute method parameter as mentioned below.
#RequestMapping(value = "/requestPattern")
public ModelAndView methodName(
#ModelAttribute FormDetail formDetail,BindingResult result,
HttpSession session) {
// I want formDetail object without using #ModelAttribute as a method argument.
}
Please help me out.
At least in Spring 3.X you should be able to omit #ModelAttribute and still have your FormDetail object populated. This is the case with my application. You can see some details here:
Omit ModelAttribute from view

How to access a method of another class(.cs)inside another ascx page(design page)

I have 1 method which returns the count of records,i want to access this method in design page(ascx) .how to do that?
If your method is in the code-behind class for the ascx then method needs to have public or protected (because ascx class will inherit from code behind class) - then you can use server directives or data binding to access the method - for example
<span><%= this.CallMyMethod() %></span>
or
<span><%# this.CallMyMethod() #></span>
For later (data-binding) syntax to work, you must call DataBind method on the parent(ancestor) control.
In case, your method is in another class and its instance method then you need to have instance of that class to call the method. Calling mechanism remains same as above except replace this keyword with the variable (instance) of another class. For static methods, you can invoke them using className.MethodName syntax. Note that the method has to be accessible from ascx (i.e. public or internal etc).

Resources