How to create a tooltip over cell in Struts2 display:column? - struts2

I have a long text to display in a struts2 display:column. Thus, I truncate since it's not that important. How do I decorate each of those cells with a regular html tooltip (title/alt) when the cursor is positioned over that cell? This way I could still display the complete text to the user on demand.
Could I extend the display:column tag?
<display:column sortable="true" property="codeIdentification" />
Thanks,

Ok, I used a table decorator, which encapsulates the text (codeIdentification) with a span and an title attribute. i.e.
<span title="xxx">codeIdentification</span>
Sufficient.
You may define the decorator in the display:column tag.
<display:table name="dataPage" id="process" export="false"
decorator="com.mysite.decorator.CodeStringFormatter"
requestURI="dataList.action"
sort="list"
pagesize="30"
>
Of course, in this decorator class you need to create a getter method. In my case that is getCodeIdentificatin()
That does the job. Sufficient.

Related

how to set radio button for edit in grails

I am using grails 2.1.1 I have a domain where I want to save religion of member. I am saving it there is no problem. But when I go to edit page then it does not checked the original value.Suppose I am saving a religion for Buddhist and at the time of edit I want to be checked the value of it. But it is checking for Muslim. I want the field to be checked on edit page. Can anyone please help me on this please ??!!! Here are my attempts below ::
my domain class >>>
class RadioButton {
String religion
static constraints = {
}
}
my form page >>>
<div class="fieldcontain ${hasErrors(bean: radioButtonInstance, field: 'religion', 'error')} ">
<label for="religion">
<g:message code="radioButton.religion.label" default="Religion"/>
</label>
<g:radio name="religion" value="muslim" checked="checked"/> Muslim <br/>
<g:radio name="religion" value="hindu"/> Hindu<br/>
<g:radio name="religion" value="christian"/> Christian<br/>
<g:radio name="religion" value="buddhist"/> Buddhist
</div>
You may want to consider the radioGroup tag within Grails instead of manually authoring your radio buttons.
However, if you decide to continue manually authoring your radio buttons you will need to account for selecting the current value. For example:
<g:radio name="religion" value="muslim" checked="${radioButtonInstance?.religion.equals('muslim')}"/>
In the above example you will notice that the checked attribute is being set to a boolean value (which is correct according to the documentation).
I think radioGroup is by far a better solution for you as you are using grails.
They main problem is that you are not passing the currently set religion to the GSP. There is nothing telling the radio group which religion has already been set by the user, instead Muslim has been hard-coded with the checked="checked".
Judging from your first line which sets the class of the div if the bean has an error, I assume you can access the currently set religion from the radioButtonInstance. Using the radioGroup tag you pass the currently set value as ${radioButtonInstance?.religion}, then we set the values and the labels you need, as shown:
<g:radioGroup name="religion"
values="['Muslim', 'Hindu', 'Christian', 'Buddhist']"
labels="['Muslim', 'Hindu', 'Christian', 'Buddhist']"
value="${radioButtonInstance?.religion}">
<p>${it.label}: ${it.radio}</p>
</g:radioGroup>
I would, however, suggest that you set the available religions as an enum class rather than hard coding it onto the GSP, as you might want to reuse it. You could then pass it as a variable in the model through the controller, calling it, for example, religions, then your radioGroup would look like:
<g:radioGroup name="religion"
values="${religions}"
labels="${religions}"
value="${radioButtonInstance?.religion}">
<p>${it.label}: ${it.radio}</p>
</g:radioGroup>

How to render a table of divs with JSF?

I need to draw a table with a column and a dynamic number of rows depending on a number of bills that I file with JSF without using an extension as PrimeFaces.
I've been looking for how to use the component h:panelGrid with h:panelGroup inside for bills without finding a solution.
welcome your suggestions
If you want to create a table of divs, one way would be to use iterating tag :
View :
<ui:repeat value="#{bean.rows}" var="row">
<div>
#{row.data}
</div>
</ui:repeat>
Bean :
public List<YourObject> getRows()
{
return this.rows;
}
This is only a draft, but it show you the way. If you add more informations how your data is constructed, It will be easier to give a more detailed answer.

How to iterate over variable in param using JSF EL expression

I have a PrimeFaces <p:dataGrid> component that contains a variable number of panels. Each panel contains a number of derived components. I have a delete button contained inside each of these panels to allow for deletion. I also have an add button outside of the dataGrid. Instead of using immediate="true" on the buttons, I figured out how to set the required attribute of each component in each panel.
For instance:
required="#{empty param['vehicleGrid:0:btnDelete'] and empty param['btnAdd']}".
For every delete button in the dataGrid and the add button, ignore component validation.
This works if there is a panel inside of the dataGrid, but it only references the first one. I need to dynamically check every panel. Maybe instead of looking at it from the markup page, maybe I need to look at it in Java terms since param is a Map<String, String>.
Bind the delete button component to the view and use UIComponent#getClientId() instead.
<h:inputText ... required="#{empty param[deleteButton.clientId]}" />
...
<h:commandButton binding="#{deleteButton}" ... />
This way the proper client ID will be looked up in the parameter map and there's then no need to iterate over the parameter map.

Struts 2 "if" tag

In my application, I use Struts 2.
In one page, I want to use the Struts 2 <s:if> tag, but can't get it to work.
In the action, I expose a "person" entity to the view.
Then in the page, I want to compare the current date with the person's birthday.
I tried this:
<s:if test="person.birthday > new java.util.Date()">xxxx</s:if>
But it does not work.
How to fix it?
I believe that you are using Date as a data type for person.brithday.You can do it as follows way
If you can change/Modify your action add new java.util.Date() to action as a new field.
Additionally using java.util.Date() is not good practice at all since most of its method are deprecated so i suggest you to use java.util.Calendar which is more flexible.
You can use Date.equals(), Date.before() and Date.after() to compare 2 dates.All you need to do something as follows
<s:if test="%{person.brithday.before(currentdate)}">
inside If block
</s:if>
<s:else>
else block
</s:else>
Where i am assuming that currentDate is being set in your Action class, but if you want to change it to use it only in jsp page can change it.

Add custom html attribute to be rendered for jsf2 component

<h:selectBooleanCheckbox />
will render a html checkbox.
How do I add a custom attribute 'myAttribute' with value 6 to it so that the result will be:
<input type="checkbox" data-myAttribute="6" ... />
There is no trivial way to achieve this. Unregistered attribtues are completely ignored. Assuming that you're using Mojarra, your best bet is to extend Mojarra's CheckboxRenderer with a custom one wherein you override the getEndTextToRender() method which writes the extra attribute. To get it to run, just register it in faces-config.xml as a renderer for component family javax.faces.SelectBoolean and renderer type javax.faces.Checkbox.
An alternative is to delegate the job to some onload JavaScript.

Resources