Alternative to uibinder I18n - gwt

There is the Uibinder way of doing i18n as described here
And then there is this suggestion for GWT i18n.
I am considering the alternative as I am experiencing some issues with the first solution.
I wish to know the pros and cons of both methods so I know what to choose.
Please advise.

The first solution is very verbose, requires you to put localization files in specific folders and is described as a kind of a nightmare but it does support text with (runtime) variables. The second solution doesn't support variables in messages, but is much easier to use.
The second solution support 2 use cases. This is how they look for both solutions:
Plain text:
Solution 1:
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
ui:generateFormat='com.google.gwt.i18n.rebind.format.PropertiesFormat'
ui:generateKeys="com.google.gwt.i18n.rebind.keygen.MD5KeyGenerator"
ui:generateLocales="default">
<div><ui:msg key="helloWorld" description="Greeting">Hello, world.</ui:msg></div>
</ui:UiBinder>
Solution 2:
<ui:with field='i18n' type='x.y.client.i18n.MyMessages' />
....
<div><ui:text from="{i18n.helloWorld}" /></div>
In the solution 1 the text inside the tag will be the default text and the description is in the description attribute. In the second solution you would add that in the interface class MyMessages which extends Messages.
Static method argument:
Solution 1:
<th title="Gross receipts">
<ui:attribute ui:name='title' ui:description='Tooltip text for gross column'/>
...
</th>
Solution 2:
<th title="{i18n.grossReceiptsTitle}">...</th>
Any more advanced usage of message like passing arguments is not possible with solution 2, but you can always fall back to add them in your constructor after the initWidget call.

Related

Find an Element in Protractor

<div>
<label localize="{data: 'Name', suffix: ':'}">Name:</label>
<span class="required" ng-class="{'disabled': meterCreating}" input-control="{title: 'Meter', okCallback:setMeterName, value: meter.meterName, ss: 'meters'}">
<span hs-placeholder="Enter Name" class="ng-binding"></span>
</span>
</div>
What is the best way to find an element: placeholder = "Enter Name"?
Scenario: find an element using Snippet above
User clicks on the "Enter Name" box, another windows pops-up for entering a name.
Based off that HTML, the cleanest way I can see is by css chaining:
element(by.css('span.required span.ng-binding')) (would normally just be span.ng-binding, but I highly doubt that's unique. I also doubt that span.required span.ng-binding is unique either)
There are many other options, however they won't be pretty cause they will be similar chains.
element(by.cssContainingText('label', 'Name:')).element(by.css('span > span'));
or
element(by.css('div label span.ng-binding')) etc..
I would suggest asking your developers for better locators (specifically, ID's), it makes JavaScript way easier. Unfortunately, I don't think you're able to locate that element by HTML attributes, which is one of my favorite ways. It would have looked like this:
element(by.css('span[placeholder=Enter Name]')) -- but I'm pretty sure that will throw an error for invalid locator. It accepts most "standard" html attributes such as value, option, style etc...

Selenium-Webdriver JAVA:- i am getting error ""org.openqa.selenium.NoSuchElementException: no such element""" but Appointment Icon is present

I want to verify the tool tip but getting error no such element. I have confirmed that element is exist.
Java Code:
String toolTipTextAppointment = driver
.findElement(By
.id("//*[#id='EditView_NOTE_POPUP']/table/tbody/tr[2]/td/table/tbody/tr[3]/td[2]/table/tbody/tr/td[1]/a/img")).getAttribute("title");
System.out.println(toolTipTextAppointment);
HTML Code:
<td nowrap="nowrap" style="border:0px;">
<a class="" href="javascript:void(0);" onclick="showPopupActivity('Meetings','activityPopupFormAraContent',440,600);">
<img style="border: 6px none;" title="Appointment" src="themes/AutoAccelerator/images/calender_icon.gif"/>
</a>
</td>
Try
driver.findElement(By.cssSelector("img[src*='calender_icon.gif']")).getAttribute("title")
you have used findElement(By.id("")) but you passed xpath in it that is why it is not working
String toolTipTextAppointment = driver.findElement(By.xpath("/html/body/table/tbody/tr/td/a/img")).getAttribute("title");
System.out.println(toolTipTextAppointment);
The problem is visibility. There are two different concepts, existence and visibility (reachable to click or see).
You need to check if the element is visible, not sure about the syntax as I use the clojure library (clj-webdriver) but as far as I know should be shomething like this
e=driver.findElement(By.id("idOfElement")).isDisplayed();
Take into account that the driver will find hidden element but they are not visible. In this particular case you may need to scroll down the page to make the element visible, I suggest retrieve its e.location and use the coordinates with a javascript snippet
((JavascriptExecutor)driver).executeScript("window.scrollTo(" + e.location + ")");
Then the element will be visible and you will be able to interact with it, I usually have this code embedded in a helper function as it's a quite common issue.
Disclaimer: code is just an orientation, I don't know the syntax as I don't use Java. Hope it helps

Html coders + zend form

So I use a zend framework, but for all commercial projects I am not using zend form component.
HTML+Js coders are working on frontend and I don't want to have nothing with it, I just connect the final view in my zf based application.
So for example I have in view a html form which looks like this:
http://pastie.org/1668143
So form design, elements and classes can be changed by frontend coders, and I want to know is there easy way for me, to use zend form with this concept (in each project form code looks different of course )?
My main problem here is code duplication in my controllers, which in this case looks something like this:
http://pastie.org/1668023 (please don't take exceptions and loggedMember seriously, they are just used for this snippet, to demonstrate a problem, which I have)
So, what would be the best solution for problem which I have, what do u think :) ?
If you have absolutely no control over the form's html structure, but still want to maximize the use of Zend_Form's features, use Zend_Form_Decorator_ViewScript.
http://framework.zend.com/manual/en/zend.form.standardDecorators.html (last section)
$element->setDecorators(array(array('ViewScript', array(
'viewScript' => '_element.phtml',
'class' => 'form element'
))));
I would do it like this:
create a form class that has all elements, validators and filters
create an instance of the form in your action and set the view script(s) (this way you can change them per controller and still have very little duplicated definition code.
Splendid, I don't understand why you would have a problem with code duplication, in your 2nd link, you are performing your checks, then check if the page is a post request, then performing the checks again, yes its duplicated, but I don't understand what you are trying to explain by doing this?
As for the form, its up to you how you use it, you could create the form object, then instead of ever out putting the form, simply pass it the data from your designers form, and use it to validate things.
Or you could use custom templates for the form, OK it means you don't give the designers quite as much freedom of them designing a form and you sorting the results, but they can still do their best at it.
This is the setup I use, after all I am in charge of the functionality as the programmer, the designers just make it look good what the user see's.
So for example, if I want to create an input element I can:
$arrival_time = $this->createElement('text', 'arrival_time', array(
'required' => true,
'label' => 'Arrival Time:',
));
$arrival_time->removeDecorator('HtmlTag');
$this->addElement($arrival_time);
Notice I have removed the HtmlTag decorators here - I don't need them for the markup as the designers will be arranging things for me.
Next thing to do is tell the form to use the layout the designers have made:
$this->setDecorators(array(array('ViewScript', array('viewScript' => 'NewArrivalsForm.phtml'))));
Here my template is within the view's, script's directory.
Now the designers have a few options. They could do:
<table border="0" width="100%">
<tr>
<td>
<?php echo $this->element->arrival_time; ?>
</td>
This will give you the following output:
<td>
<dt id="arrival_time"><label for="arrival_time" class="required">Arrival Time:</label></dt>
<input type="text" name="arrival_time" id="arrival_time" value="" />
</td>
If there we're an error, that would be presented as well. You could remove the decorators 'Label', 'Description' & 'Errors' as well, to make it simply an input box:
<td>
<input type="text" name="arrival_time" id="arrival_time" value="" />
</td>
Even once you have removed the decorators, the designers could still use for example:
<tr>
<td>
<?php echo $this->element->time_on_site->getLabel(); ?>
</td>
</tr>
<tr>
<td>
<?php echo $this->element->time_on_site ?>
</td>
This will allow them to lay the form out exactly as they want to. But it will still allow you to use the full power of Zend_Form for your final validation checks. Take a look inside the Zend/form/element.php for all the methods you and your designers can use on the form element.

customizing size of form fields created using field.custom.widget

I used the following code to generate a form in attached image.
Is it possible to change the size of the fields in the form.
I want to decrease size of input field of Estimated time and the dropbox field to the right of it
{{=form.custom.begin}}
<table>
<table><tr>
<td><b>Type :</b></td><td><div>{{=form.custom.widget.type}}</div></td>
</tr><tr>
<td><b>Title :</b></td><td><div>{{=form.custom.widget.title}}</div></td>
</tr><tr>
<td><b>Description :</b></td><td><div>{{=form.custom.widget.description}}</div></td>
</tr><tr>
<td><b>Estimated Time :</b></td><div'><td>{{=form.custom.widget.estimated_time}}{{=form.custom.widget.estimated_time_unit}}</td> </div>
</tr>
<tr>
<td></td><td><div align='center'>{{=form.custom.submit}}</div></td>
</tr>
</table>
{{=form.custom.end}}
Yes. You can and there are many ways.
The recommended way is to look at the generates JS. You will find it follows a naming convention described in the book. You can use CSS to change the look-and feel of every widget.
input[name=estimate_time] { width:50px }
Similarly you can use JS/jQuery (I would recommend you do this in the view).
jQuery(document).ready(function(){ jQuery('input[name=estimate_time]').css('width','50px');});
You can also use jQuery-like syntax in python in the controller:
form.element('input[name=estimate_time]')['_style']='width:50px'

Extract part of HTML in C/Objective-C

I need to extract the detail content of a website while preserve all formatting of the division. The section I wish to extract is:
...
<div class="detailContent"><p>
<P dir=ltr><STRONG>Hinweis</strong>: Auf ... </p>
</div>
...
My current solution is to use HTMLParser from libxml2 and xpath to find the nodes and walk through all the nodes to reconstruct this piece of HTML. This is a long an complicated code.
I' just wondering if there is an easier solution to extract part of HTML?
Thanks.
Simple Javascript solution: document.getElementsByClassName("detailContent")
Combine that with UIWebView's support for running Javascript and you might have a more concise solution.