What to import to use Lift's FieldTransform - lift

I just started using Lift's Wizard/LiftScreen classes and need to add placeholder text to my text fields. I found the FieldTransform class as a solution to this here
https://groups.google.com/forum/#!topic/liftweb/x_t9rvvZ8jk and here http://comments.gmane.org/gmane.comp.web.lift/59985
But now I'm trying to use that information, but can't for the life of me figure out what import statement is needed (where the class is, in the libraries).
Lift 2.5-M3 talks about the API changing liftweb.net/25_m3, but nowhere do I find the class actually listed in the API (liftweb.net/api/25/api/#package).
What's the import I need? How should I be looking this up; I'd like to know how to find a class quickly next time.
EDIT:
To be a good Stackoverflow citizen, here's some code.. :-)
object WizardExample extends Wizard {
val screen1BrandInfo = new Screen {
val brandName = field("Name", "Mike")
}
}
I'm trying to add HTML5 placeholder text to the "Name" field so the user sees sample text when they view the page.
RESOLUTION:
Wow, that was my first StackOverflow. I'm blown away by what I've learned from you guys in a few hours!
#jcern: thanks for all your help. I'm working in Lift 2.4, so initially I didn't find FieldTransform in Wizard$Screen, then I clicked on the link you provided (2.5) and saw it. What a jungle to navigate! Thanks for all your help. I now see how to navigate all this. And thanks again so much for the "All" view hint. That was critical!
#Vasya Novikov: Thanks so much for this answer. This is what I'll have to do since I'm working in 2.4 and don't have access to FieldTransform.

The two best places to find classes in Lift are either in the API:
http://liftweb.net/api/25/api/#package
Or, directly in GitHub (where you can search for classes and for text/definitions within them):
https://github.com/lift/framework
As for the FieldTransform class, that should be available to any class that extends LiftScreen. See the API here -- you may need to toggle the visibility to All to see FieldTransform as it is a protected class.
You can import LiftScreen with:
import net.liftweb.http.LiftScreen

Related

Enterprise Architect Code Generation: Get tags of interface

I use Enterprise Architect for code generation and I would like to automatically retrieve all tags (in my case Java annotations) of the interfaces that a class realizes. Consider the following example:
From this model, I want to generate a class that looks like this:
#AnnotationOfMyInterface
public class MyClass {
...
}
So I want to add annotations as tags to MyInterface that should be applied to MyClass during code generation. In the UI, tags of implemented interfaces are shown so I was hoping there is a way to get these tags during code generation.
I tried to edit the code generation templates and found macros to get
All interfaces that a class implements: %list="ClassInterface" #separator=", "%
All tags with a given name (of the class that code is being generated for): %classTag:"annotations"%
But unfortunately, I cannot combine these macros, i.e., I cannot pass one interface to the classTag macro so that I can retrieve the tags of that particular interface (and not the one I'm generating code for). Is there a way to get classTags of a specific class / interface?
I also tried to create a separate code generation template and "call" it from the main class code generation template. But inside my template, the classTag macro still only gets the tags of the class.
Thanks to the comments above and especially because of an answer to my question in EA's forum, I was able to setup a little proof of concept achieving what I wanted. I'm answering my question to document my solution in case someone has a similar problem in the future.
After Eve's hint in EA's forum I looked into creating an AddIn for Enterprise Architect to use this AddIn from a code generation template. I started by writing a basic AddIn as explained by #Geert Bellekens in this tutorial. Afterwards I changed the AddIn to fit my needs. This is how I finally got the tagged values (annotations) of the interfaces a class realizes:
First step:
Inside a code generation template, I get all the interfaces a class realizes and pass them to my AddIn:
$interfaces=%list="ClassInterface" #separator=", "%
%EXEC_ADD_IN("MyAddin","getInterfaceTags", $interfaces)%
Second step:
As documented here the repository objects gets passed along with the EXEC_ADD_IN call. I use the repository object and query for all interfaces using the names contained in $interfaces. I can then get the tagged values of each interface element. Simple prototype that achieves this for a single interface:
public Object getInterfaceTags(EA.Repository repo, Object args)
{
String[] interfaceNames = args as String[];
String firstInterfaceName = interfaceNames[0];
EA.Element interfaceElement = repo.GetElementsByQuery("Simple", firstInterfaceName).GetAt(0);
String tag = interfaceElement.TaggedValues.GetAt(0);
return interfaceElement.Name + " has tag value" + tag.Value;
}
I know, there are a couple of shortcomings but this is just a simple proof of concept for an idea that will most likely never be production code.

Eclipse fails to auto-suggest Jackson class

What is causing Eclipse to NOT recognize and consequently not offer any suggestion on an import of JsonParser.Feature as shown in the picture below:
Manually adding the static import of com.fasterxml.jackson.core.JsonParser.Feature.ALLOW_SINGLE_QUOTES (commented in the picture above), however, works fine.
Would it be the case that something is eclipsing the file on the classpath, and if so - what is Eclipse's strategy on resolving those conflicts? Or is it something else?
Thank you in advance.
You cannot use JsonParser class to access Feature since it is not a static member of the class. Instead you can directly use the Feature class :
mapper.configure(Feature.ALLOW_SINGLE_QUOTES, true);
I can suggest 2 workarounds:
Use AutoComplete (Ctrl + Space) to suggest classes:
Add . to class Name (JsonParser.) and then remove it (JsonParser) it will suggest all JsonParser classes:

Reuse PDE' s ManifestEditor and meet NullPointerException

1.what we are planning to do :
Reuse the ManifestEditor to open the MANIFEST.MF file, and add our features to the first OverviewPage.
2.what we already have known and done :
It's dangerous to use the internal classes and APIs, so we create a ManifestEditorNew which extends ManifestEditor.
import org.eclipse.pde.internal.ui.editor.plugin.ManifestEditor;
import org.eclipse.pde.internal.ui.editor.plugin.OverviewPage;
public class TheNewManifestEditor extends ManifestEditor{
//it's strange that the default fist page is not the OverviewPage,so we override this method
#Override
protected String computeInitialPageId() {
return OverviewPage.PAGE_ID;
}
}
3.what Exception we meet :
The NullPointerException.
Once our TheNewManifestEditor gained focus, the give us an NPE, but we can not find ant clues which caused this.
You probably need to called super.computeInitialPageId() because it looks like it does some set up.
Note: The reason the overview page is not always shown is because the editor remembers the the last page you looked at and shows you that. It will default to the overview page the first time the manifest is edited.
Just extending an internal class does not remove the fact that you are using internal Eclipse classes which violates the Eclipse API Rules of Engagement. Internal classes can and do change and sometimes even disappear altogether, you are likely to have a lot of trouble when moving between Eclipse releases.

Magento: Accessing models/blocks from a phtml

Hi I have a situation where I need to look up the number of recently viewed products on catalog/product/view.phtml. In the recently viewed 'product_viewed.phtml' file it calls
$_products = $this->getRecentlyViewedProducts()
to get the recently viewed. How would I access this method from within the catalog/product/view.phtml file?
I don't know where this method is. I've tried searching for it but it doesn't seem to exist. When I write click it in Netbeans and click go to declaration it takes me to
class Mage_Reports_Block_Product_Viewed extends Mage_Reports_Block_Product_Abstract
Actually on the class itself. This class only has _toHtml(), getCount(), and getPageSize() methods.
I just need to know whether there are any recently viewed products.
Any help most appreciated!
Billy
If you look into 'Mage_Reports_Block_Product_Viewed', you will notice:
$this->setRecentlyViewedProducts($this->getItemsCollection());
That 'getItemsCollection' method is defined in the abstract class... And you will notice this abstract class will create a model based on $_indexName defined in the (subclassed) block.
If you just want the collection, you can probably get away with:
$_products = Mage::getModel('reports/product_index_viewed')->getCollection();
And then adding whatever you want to the collection:
$_products
->addAttributeToSelect('*')
->setAddedAtOrder();
// optionally add other methods similar to Mage_Reports_Block_Product_Abstract::getItemsCollection
Another approach that might be more suited would be to create the original block:
$productViewedBlock = $this->getLayout()->createBlock('reports/product_viewed');
On which you can simply call whatever you want:
$_collection = $productViewedBlock->getItemsCollection();
$_count = $productViewedBlock->getCount();
The getRecentlyViewedProducts function is a magical getter that gets the data that was set with setRecentlyViewedProducts in app/code/core/Mage/Reports/Block/Product/Viewed.php (which builds it using app/code/core/Mage/Reports/Block/Product/Abstract.php's function _getRecentProductsCollection).
This is complicated stuff that you don't want to reproduce; its better, IMO to make your own Block that extends Mage_Catalog_Block_Product_Abstract that will give you access to the same functionality, and drop your new block into the page you're working on.

Using an interface classifier in a UML Class Diagram

I am trying to implement an UML Class Diagram and I would like to use an interface classifier CreateItem to inform a developer that (that rappresents an input web form), in order to populate an attribute TitleI in a class Item, he/she MUST use one or more TitleO of a class Object. That is, I would like to indicate that using a web form CreateItem you can "compose" a Item TitleI (TitleI is a string) exclusively searching and adding to it one or more Object TitleO (TitleO is a string).
It should working as "composing" the StackOverflow Tags "string" when you Ask a new question. The only difference is that I would like to create a Title string made by those Tags.
I "learned" to solve part of my issue in thinking this way:
< < interface > > **CreateItem** is a *realization* of **Item**
Then?
You can depict the composition/aggregation using respective relationships. You can use the dependency relationship to depict creation. If this doesn't help, try to formulate your question in other way or to be more precise and I will try to answer.