JOOQ: how do I add multiple interfaces to generated record classes using matcher strategy - interface

Building on the answer provided here, I am trying to make my generated records implement multiple interfaces. Depending on which regex matches (REGEX_A, REGEX_B or both), the generated record should implement one, or both of IFoo and IBar.
I do have a gradle-jooq-plugin configuration file, but it should be semantically equal to this:
<generator>
<strategy>
<matchers>
<tables>
<table>
<expression>REGEX_A</expression>
<recordImplements>com.test.IFoo</recordImplements>
</table>
<table>
<expression>REGEX_B</expression>
<recordImplements>com.test.IBar</recordImplements>
</table>
</tables>
</matchers>
</strategy>
</generator>
The result I am getting is that a record matching both matchers will only implement IFoo. Is that the expected result? And is there a way to achieve what I want with matcher configuration only?

Only the first matching <table> specification is applied
The way these matcher strategies work, only the first <table> specification whose <expression> matches is applied to a generated artifact. The subsequent matches are ignored. This means, you cannot merge the various <recordImplements/> specifications. Instead, you'll have to add another specification that matches both your regexes in the beginning, like this:
<generator>
<strategy>
<matchers>
<tables>
<table>
<expression>REGEX_A.*REGEX_B|REGEX_B.*REGEX_A</expression>
<recordImplements>com.test.IFoo, com.test.IBar</recordImplements>
</table>
<table>
<expression>REGEX_A</expression>
<recordImplements>com.test.IFoo</recordImplements>
</table>
<table>
<expression>REGEX_B</expression>
<recordImplements>com.test.IBar</recordImplements>
</table>
</tables>
</matchers>
</strategy>
</generator>
Why not merge the various <table> specifications?
For <recordImplements/>, it seems useful to be able to merge two matching <table> matcher specifications and let the resulting records match all the interface implementation specifications.
However, this isn't true for all the other possible elements inside of <table>, such as <tableClass>, <tableIdentifier>, etc., which is why only the first matching expression is applied to any table. In order to not complicate this functionality unnecessarily, only the first matching expression is applied.

Related

How to find xpath by element text in selenium ide in order to use the element?

Table contains columns with headers like those
vehicle no | driver
103 | John
the xpath location is:
//tr[3]/td[4] | //tr[3]/td[5]
The columns can be customized and then xpath will change therefore, is there a way to automatically find the xpath location of the columns by contained text ?
For now i'm using loop with scanning all of the headers, maybe there is more efficient way?
Try this for exact search:
//td[text()='EXACT']
Or for partial search:
//td[contains(text(),'PARTIAL')]
This gives you two options in xpath to patch for text.
Am assuming that your table would look some thing like below..
<table>
<th> <td> vehicle no</td> <td> driver</td></th>
<tr> <td> 103</td> <td> John</td></tr>
</table>
To create xpath location of the column, by contained text ? You can use 'contains' in xpath..
XPATH1 = //table//td[contains(.,'John')]
XPATH2 = //table//td[text()='John']
Please let me know if the above does not solve your problem.
Maybe this helps?
if you want to get 'John':
in the command field put: [verify text]
in the target field put: xpath=//table//td[contains(.,'driver')]/following::tr/td[2]
in the value field put: John

How to access a session ArrayList by index in a form?

I have a session variable which is of type ArrayList.
In the jsp page I need to access it by index to create a form dynamically, but after I submit the form I found out that the session ArrayList's elements values didn't change.
Here it is what I've tried on my JSP page (I use struts2 Framework):
<s:iterator value="anotherArray" status="RowsIterator">
<tr>
<td>
<s:iterator value="actionOptionsArray" status="iter">
<s:radio
name="#session.chosenActionsArray[%{#RowsIterator.index}]" <!-- The concerned line -->
list="%{actionOptionsArray[#iter.index]}"
value="#{actionOptionsArray[0]}"
theme="simple" />
<br>
</s:iterator>
</td>
<!-- other fields-->
</tr>
</s:iterator>
anotherArray and #session.chosenActionsArray have the same size.
I guess I iterate it wrongly, but in my case iterating it by index is an obligation.
Thank you a lot in advance :)
You need to access the session via an action, the session is accessible from the jsp but not directly from the outside world in this way.
Have the action you are submitting the form to implement SessionAware. I would create a getter/setter for an ArrayList along with proper validation and then move those values into into the session via the execute method. I'm not a fan of exposing your session directly to the outside world (providing a setter for the session in your action)... if you do this you need to be aware that you may have given a malicious user access to things you might not have expected.
Edit
Suppose you have an ArrayList of ArrayList of String called "matrix" in your action... you can iterate the properties via:
<s:iterator value="matrix">
<s:iterator>
<s:property/>
</s:iterator>
</s:iterator>
The outer iterator, iterates over "matrix" which pushes each instance to the top of the value stack. The inner iterator will use what is at the top of the stack by default same with the property tag. Placing tr's and td elements in the right place an you could render a table.
To generate the right name attribute for input elements (possibly hidden ones) you would want them in the form matrix[i][j] where i and j are integers and would define an appropriate matrix. Using status attribute of iterator as you've done would be a good way to generate the indexes.

Alternative to uibinder I18n

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.

Spring MVC 3 - custom labels in <form:select>

I'm creating a form in which user will be able to choose (among the others) the factory of a product.
Each factory is identified by and ID and has specific address.
I want to use custom label in following code:
<form:select items="${factories}" path="factory" itemValue="id" itemLabel="..."/>
At first i tried using Spring Formatter functionality (org.springframework.format.Formatter interface), but when I did this, and when I removed "itemLabel" attribute to have it displayed automatically via Formatter):
<form:select items="${factories}" path="factory" itemValue="id"/>
But then It wasn't selecting proper value if it was set (in case of editing).
Then I tried to:
<form:select path="factory" itemValue="id">
<c:forEach ...>
<form:option value="${factory.id}" label="${factory.address.city} ${factory.address.street}"
</c:foreach>
</form:select>
But as in earlier solution spring was not selecting proper value that was set in model.
My question is:
Is it possible to format entity in a way, that form:select works properly, when a value of select field is not the same as its label.
I had the same problem, the trouble is the form:option value and label maps directly to a property rather than having the flexibility to specify jstl.
So you have to hand crank the html, to something like:
<select name="factory">
<c:forEach var="factory" items="${factories}" >
<option value="${factory.id}" label="${factory.address.city} ${factory.address.street}"/>
</c:forEach>
</select>
Spring will pick up the 'path' based on the name attribute('factory' in this case), as it will try and map to the model object you are using automatically.
Another way is to add another field to the model to concatenate and format label as you wish. And if its an #Entity object then make the field #Transient.
You can also override toString() method in Factory class
#Override
public String toString() {
return "desired string";
}
Then in your jsp
<form:select items="${factories}" itemValue="id" path="factory"/>

struts2: param tag doesn't use conversion

Problem
In my struts2 application I have JSP page where the list of book is displayed. Each book has an id and the name. Also I want to place a link "edit" alongside any book, which can be edited by current user. This "edit" link should invoke corresponding action, passing book id as parameter to it. So I implemented this page using the code:
<table>
<s:iterator value="books" status="stat">
<tr>
<td><s:property value="id"/></td>
<td><s:property value="name"/></td>
<td>
<s:if test="canEdit[#stat.index]">
<s:a action="editBook">edit
<s:param name="bookId" value="id"/>
</s:a>
</s:if>
</td>
</tr>
</s:iterator>
</table>
Book id is not of a basic type, I use custom class for it. So I decided to implement my own converter.
And here comes the problem: in the code above converter is used only when evaluating tag <s:property value="id"/> but it is not used to evaluate <s:param name="bookId" value="id"/>. Instead toString() method of book id class is used. Why <s:param> doesn't use my converter? How do i force it to do so? Or maybe there is another way to pass book id as parameter in link?
Some (probably useless) details
To configure converter I placed xwork-conversion.properties inside my /src/main/resources/ folder with the following contents:
my.app.Id = my.app.struts.IdConverter
my.app.Id is an abstract class which is extended by book id class.
The result of rendering of the JSP for a single-entry list is the following:
<table>
<tr>
<td>8</td>
<td>Book 01</td>
<td>edit</td>
</tr>
</table>
id%288%29 is an escaped version of string id(8) which is the result of toString() method (defined in base abstract class my.app.Id) for id with int value of 8.
The <s:param> tag is meant for "simple" parameters. In this case, you may be able to just set a temporary value using <s:property> if that does the conversion you expect.
It uses the toString of the book id because that's what a getId() will print out when rendered, just as if you did a System.out.println(book.getId()).
Found corresponding issue with explanation of problem:
http://jira.opensymphony.com/browse/WW-808
In a few words the difference is between specifying <param value="myValue"/> and specifying <param><property value="myValue"/></param>. Conversion is used only in second case.