struts2 dynamically change style on textfield - struts2

I'm trying to dynamically change the style of a Struts2 textfield to change background color depending on a certain conditions.
Question 1 - is this possible
Question 2 - from other posts here - I've tried the following but the style is not getting evaluated?
Any pointers on how this can be done or what I have incorrect below?
<s:if test='%{contactStatusCode == "ARE" }'>
<s:set var="AREStyle" value="%{'background:#eeeeee'}"/>
<s:textfield name = "followUpComment"
id = "followUpComment[%{#index.index}]"
style = "%{#AREStyle}"
size = "15"
maxlength = "100" />

How about changing css class of textfield
<s:textfield name="followUpComment" cssClass="%{contactStatusCode == 'ARE' ? 'areClass' : 'notAreClass'}" />

Related

Making an asterisk in a label red

I have the following .html markup
.html
<paper-button
raised
active
toggles
on-tap = "toggler"
class = "bold">Patient *
<iron-icon
icon = ""
id = "fe-icon"></iron-icon>
</paper-button>
</div>
How can I make the * in Patient * red without the entire label being red, and also make the asterisk larger?
Just wrap it with a <span> like >Patient <span class="asterisk">*</span></iron-icon> then you can style it individually.

Change text (label) with jquery ui button toggle

I have a jquery-ui button and I know how to change the styling between states with css, but I would like to know how to change the label text too. For example, an ON/OFF button like below -- when [checked="checked"] then the label text would = "ON" (and OFF when not checked).
<input type="checkbox" id="device_4_state" name="device_4_state" class="toggle-button on-off" checked="checked" />
<label for="device_4_state">ON</label>
Any help would be tremendous. Thanks.
here is the solution :
$('#device_4_state').change(function(){
if ($("#device_4_state").is(':checked'))
{
$("label[for='device_4_state']").text("ON");
}
else
{
$("label[for='device_4_state']").text("OFF");
}
});
If you wish to use pure CSS to set the label text, you can use CSS pseudo elements to automatically generate the content of the label based on the state of the jquery-ui button. To use this approach, leave the label empty (<label for="device_4_state"></label>) and include CSS like this:
.on-off + label > span:before {
content: "OFF";
}
.on-off + label.ui-state-active > span:before {
content: "ON";
}
As in this jsfiddle: http://jsfiddle.net/GjPXZ/1/

PrimeFaces datatable scrollbar position

How to set a scrollbar position of primefaces datatable from last to first?
Actually, I want see the information from bottom to top. Below is my code:
<p:dataTable var="c" value="#{MessagingUserBean.inboxDetails1}" scrollable="true" scrollHeight="517" liveScroll="true" emptyMessage="No Message Found" scrollRows="8" scrollWidth="815" >
Well you can try to not use a liveScroll because you then don't know the end of dataList. Try this and maybe this suit your needs. This will scrolldown to the bottom of your dataTable with a delay.
<h:form prependId="false">
<p:dataTable id="dataTable" var="c" value="#{MessagingUserBean.inboxDetails1}" scrollHeight="517" liveScroll="true" emptyMessage="No Message Found" scrollWidth="815" >
//Your dataTable stuff
</p:dataTable>
</h:form>
<script>
//Get the scrollheight
var s = jQuery('#dataTable .ui-datatable-scrollable-body').prop('scrollHeight');
//Get total size of datatable
var o = jQuery('#dataTable .ui-datatable-scrollable-body').prop('offsetHeight');
//calculate how many times it can scrolldown to set your timer
var t = Math.ceil(s/o);
//Excute scrolldown animation (max scrolldown is scrollHeight - offsetHeight)
$('#dataTable .ui-datatable-scrollable-body').animate({scrollTop:s-0}, t*1000);
</script>
You will need some javascript to do this.
var $scrollable = $(dataTableSelector).children('.ui-datatable-scrollable-body')[0];
$scrollable.scrollTop = $scrollable.scrollHeight;
Where "dataTableSelector" is a selector for your primefaces table (a styleClass for example).
Of course, this assume that the last element in the list you're displaying is actually the first you want to show.

Buttons in Jquery Ui having some problem with the change of a Label

I have a little problem, and I can't figure out where does it come from.
I'm using jQuery UI (and of course jQuery)
I have the following HTML:
<input type="checkbox" id="test" value="test"/>
<label for="test">Show Test</label>
<div id="checkedDiv"></div>
and the following JS:
function clickChange() {
var currentText = this.nextSibling.innerHTML;
this.nextSibling.innerHTML =
(this.checked) ? currentText.replace("Show","Hide") :
currentText.replace("Hide", "Show");
$("#checkedDiv").text(this.nextSibling.innerHTML);
}
var test=document.getElementById("test")
test.onclick=clickChange;
$("#test").button();
The problem is that on the first click, the innerHTML doesn't change. After that it works.
And to be a little more disappointed, the nextSibling seems to change (at least from what is seen in the #checkedDiv), but doesn't appear on the DOM Tree on firefox/firebug.
Am I missing something ?
Thanks
(if you want to try it yourself, it's here: http://jsfiddle.net/nvNKW/3/ )
EDIT:
The (or at least one) solution is to use label as suggested by Aziz Shaikh:
function clickChange() {
var currentText = $(this).button( "option","label");
$(this).button( "option","label",(this.checked)? currentText.replace("Show","Hide") : currentText.replace("Hide", "Show"));
}
And there is no need to change the html or the button initialisation.
Try setting the label using $("#test").button({ label: newText }); instead of this.nextSibling.innerHTML
Edit: So your fixed JS function would be:
function clickChange() {
var currentText = this.nextSibling.firstChild.innerHTML;
var newText = (this.checked) ? currentText.replace("Show","Hide") : currentText.replace("Hide", "Show");
$("#test").button("option", "label", newText);
$("#checkedDiv").text(this.nextSibling.innerHTML);
}
It's because nextSibling() also returns text nodes. You are changing the blank empty space after the input, not the next tag.
jQuery makes it easy, do
$(this).next('label').html()

Access to multiple ItemRenderers within an AdvancedDataGrid

I've create an AdvancedDataGrid where most of the cell are based on an ItemRenderer. The custom ItemRenderer (SoundBox) extends VBox. This custom component allow for simple changes in the background color based on user clicking on a cell.
Here is the snippet of the AdvancedDataGrid (nothing too advanced):
<mx:AdvancedDataGrid id="fsfw" dataProvider="{fsfWordList}" sortableColumns="false" >
<mx:groupedColumns>
<mx:AdvancedDataGridColumn width="35" dataField="wordcount" headerText=" "/>
<mx:AdvancedDataGridColumn id="myWord" width="150" headerText="TEST ITEMS">
<mx:itemRenderer>
<mx:Component>
<components:SoundBox width="100%" letterSound="{data.word}" />
</mx:Component>
</mx:itemRenderer>
</mx:AdvancedDataGridColumn>
<mx:AdvancedDataGridColumn width="200" headerText="Correct / 2 points" dataField="sound1">
<mx:itemRenderer>
<mx:Component>
<components:SoundBox width="100%" letterSound="{data.sound1}" pointColumn="2"/>
</mx:Component>
</mx:itemRenderer>
</mx:AdvancedDataGridColumn>
</mx:groupedColumns>
</AdvancedDataGrid>
What I'm trying to do is change the background color of (let's just say I have one row of data) row1, cell1 to green when the user clicks on cell3 of row1.
I'm unsure as to how I get access to those items (ItemRenderer/SoundBox) within the Grid.
Any Ideas? THX!
look at the following code,,, it will return the item rendrer of given row and colomn index.. Extended the Advance dataGrid and define this function in the extended class,to get it worked, then use it like "CustomADG.indicesToItemRenderer(0,0)" and in that reuturend object try to get the reference to soundComponent.
public function indicesToItemRenderer(rowIndex:int, colIndex:int):IListItemRenderer
{
var firstItemIndex:int = verticalScrollPosition - offscreenExtraRowsTop;
if (rowIndex < firstItemIndex ||
rowIndex >= firstItemIndex + listItems.length)
{
return null;
}
return listItems[rowIndex - firstItemIndex][colIndex];
}

Resources