Alias in OGNL inside MyBatis - mybatis

I'm programming with MyBatis and I have this code
<if test="#mypackage.verylongname.utilities.MyBatisUtilities#isNotEmpty(recipient)">
and DOCUMENTS.recipient = #{recipient}
</if>
I'd like to have a way to avoid to use the full pathname of my class MyBatisUtilities. Is it there?
Adding an Alias to the mybatis-config file doesn't work
<typeAlias alias="MyBatisUtilities" type="mypackage.verylongname.utilities.MyBatisUtilities"/>

Don't think there is a way no, not unless mybatis provides some special extended functionality for OGNL.
That doesn't mean it ~couldn't~ be done within OGNL somehow with changes to the core library, just don't believe it does currently. (my memory may be bad, but pretty certain #fullclassname#methodname is the only way OGNL knows of to resolve static method invocations)

"bind" lets you make a variable out of an OGNL expression. For more info see : http://mybatis.github.io/mybatis-3/dynamic-sql.html
<select id="selectBlogsLike" parameterType="Blog" resultType="Blog">
<bind name="pattern" value="'%' + _parameter.getTitle() + '%'" />
SELECT * FROM BLOG
WHERE title LIKE #{pattern}
</select>

Related

Set class or ID on <h:inputHidden> in JSF

I'm trying to set a class or id parameter on a <h:inputHidden> in JSF. The code looks like this:
<h:inputHidden value="#{getData.name}" class="targ" />
But in the browser, the class isn't set:
<input type="hidden" name="j_idt6" value="j_idt6">
I need to set a class to this parameter, because I have a JavaScript autocomplete function for a <h:inputText> that sets a value in the hidden input, which needs to be passed in the next page.
Any ideas? Thanks!
I know it's a little bit late, but it can help someone in the future.
As inputHidden shows nothing in the browser there's no sense to allow it to have a class.
You can use the Id but as the Id could change as you change the component parents using it would bring some headache.
I'd suggest as a workaround, you can give it a parent so you can manipulate it by javascript.
Exemple:
JSF
<h:panelGroup styleClass="someCssClass">
<h:inputHidden id="someId" value="someValue" />
</h:panelGroup>
Javascript (using jQuery, you could use pure javascript also)
$('.someCssClass input[type=hidden]').val('yourNewValue');
None of these answers here satisfied my needs (need the PrimeFaces component, need class not ID, wrapping is too much work), so here's what I came up with:
Use pass-through attributes: https://www.primefaces.org/jsf-2-2-pass-through-attributes
Use pass:hidden-class="blah" (in my case, it's xmlns:pass up top)
Use [attribute=value] selector:
https://www.w3schools.com/cssref/sel_attribute_value.asp
document.querySelector multiple data-attributes in one element
That basically boils down to using something like this (because h:inputHidden becomes a regular input): document.querySelector("input[hidden-class=" + blah + "]")
Please, see similar question - How can I know the id of a JSF component so I can use in Javascript
You can sed "id" property, but in final html code it can be not the same, but composite: for example, if your input with id="myhidden" is inside form with id="myform", final input will have id="myform:myhidden".
In the end, I used a standard HTML <input type="hidden"> tag, as I had no advantages for using the JSF one. If you're trying to set a value in a hidden input with JavaScript, I recommend using this workaround.

Why bindings do not work?

<textbox id="nextTitleTextbox" readonly="true" value="#bind(ivm.inventory.successorTitleName)" />
<button id="nextTitleButton" label="..." mold="trendy" onClick="#command('chooseFormerOrSuccessor', isFormer = false)"/>
<a id="nextTitleHrefView" href="/inventory_new.do?method=edit&docUID=${ivm.inventory.successorTitleName}">view</a>
<a id="nextTitleHrefHistory" href="javascript:showRenamingHistory(${ivm.inventory.successorTitleName},${ivm.inventory.successorTitleName})">history</a>
The problem is in 'a' tags. Textbox and buttons works fine, but links in 'a' tags do not catch information from binding, so link there looks like /inventory_new.do?method=edit&docUID=. I really don't understand what's wrong here, because I tried a lot of combination and something similar is working on other pages. Where is mistake in this binding?
I even tried to put string from zscript
<zscript>
String successorTitleHref = "/inventory_new.do?method=edit&docUID=" + ivm.inventory.successorTitleName;
</zscript>
But got exception:
Typed variable declaration : Class or variable not found: ivm.inventory.replacementTitleName.
Also, it's supported controls, that locates in separate file, and every control adding with use derective.
Binding in ZK has nothing to do with variable replacement. #bind() doesn't mean you can use ${...}. The two are completely separate concepts even though both are called "EL Expression" in the manual. But binding EL Expression and ZUML EL Expressions are two different things.
To allow access to ivm in a zscript, you need to define this variable somewhere in the script. One way is to instantiate it:
IVM ivm = new IVM();
or you can use a custom variable resolver.

How to i18N localize the header of a tab in GWT TabLayoutPanel

I am unable to use the usual i18N localization of GWT to localize a tabs name ('header') in a TabLayoutPanel.
This works:
<g:TabLayoutPanel addStyleNames='LocationsModule' barUnit="PX" barHeight="30" >
<g:tab>
<g:header>Locations</g:header>
But I can't get any other version to work:
<g:header text='{messages.layersTabTitle}' />
or
<g:customHeader>
<g:Label text='{messages.locationsTabTitle}' />
<g:Label>'{messages.locationsTabTitle}'</g:Label>
</g:customHeader>
anyone been able to do this, without resorting to code?
I think you need to use a slightly different syntax here:
check this example:
http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/test/com/google/gwt/uibinder/test/client/I18nMessageTest.ui.xml?r=7940
so it should be something like:
<g:customHeader>
<g:Label><ui:text from="{messages.locationsTabTitle}" /></g:Label>
</g:customHeader>
You can also use the ui:text element directly within the g:header element, avoiding the need for g:customHeader or g:Label, e.g:
<g:header><ui:text from="{messages.locationsTabTitle}" /></g:header>
(This is similar - although not quite the same - to how the file linked to by Arne uses ui:text within an h2 element: http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/test/com/google/gwt/uibinder/test/client/I18nMessageTest.ui.xml?r=7940)
Tested in GWT 2.4.0.

How to apply a method to a parameter in MyBatis

After reading about Mapper XMLs I can't help to wonder how one might go about appling some common transforms to a parameter. For example...
<select id="selectPerson" parameterType="String" resultType="hashmap">
<!-- #{name} should always be upper case and have a trailing % -->
SELECT * FROM PERSON WHERE FIRST_NAME like #{name}
</select>
After reading this and this I can make some observations.
Using SQL functions such as upper or concat or '||' or '+' to do transforms kills performance in DB2
I could always wrap the the mapper or expose the details in the service layer but that seems messy
What I want is to be able to do something like...
<select id="selectPerson" parameterType="String" resultType="hashmap">
<!-- #{name} should always be upper case and have a trailing % -->
SELECT * FROM PERSON WHERE FIRST_NAME like #{name.upperCase() + '%'}
</select>
Is something like this possible or what is the second best solution?
Update: it appears that MyBatis uses OGNL for some expression evaluation. For example, if and ${} expressions use OGNL but #{} does NOT appear to unless there is some way to trick it.
Bind
MyBatis allows for creating values from method and properties in the context using <bind/>.
Bind creates a new variable in the scope of the current statement. The OGNL statement that binds the value can use the passed in _parameter object to compute a new bound value that can then used by MyBatis to construct the prepared statement.
Example
Your example using bind:
<select id="selectPerson" parameterType="String" resultType="hashmap">
<!-- #{name} should always be upper case and have a trailing % -->
<bind name="nameStartsWith" value="_parameter.getName().upperCase() + '%'"/>
SELECT * FROM PERSON WHERE FIRST_NAME like #{nameStartsWith}
</select>
Source
MyBatis Dynamic SQL Documentation
I ran through the same problem too. But I didn't find any solution for this. So I had to preprocess the #{name} parameter from the calling function.

ICEFACES : Multiple Parameters in link

I have a datatable with multiple rows, I want to put one link to redirect the values to one Servlet. The old call that I use is similar like this :
a onclick=openWindow('./Servlet?param1=xx&param2=xxx')
I'm newbie in ICEfaces... I need your help because I don't know how can I put one parameter only like this :
ice:outputLinktarget="mainFrame" value="./Servlet?param1=#{item.id}
but when I put two parameters, I got an errors in the code.
ice:outputLinktarget="mainFrame" value="./Servlet?param1=#{item.id}&param2=#{item.id}
Somebody knows how to do it?
The ampersand (&) is the culprit; you need to escape it or else IceFaces gets confused about the page structure.
Another way to do it:
<ice:outputLink target="mainFrame" value="./Servlet">
<f:param name="param1" value="#{item.id}"/>
<f:param name="param2" value="#{item.id}"/>
</ice:outputLink>
The f:param tags add the parameters to the base URL automatically.
You haven't said about what technology you use (jsp/jsf)?
For jsf try:
<ice:outputLinktarget="mainFrame" value="./Servlet>
<f:param name="param1" value="#{item.id}"/>
<ice:outputLinktarget=>