I am using a Dynamic View Panel to display various views inside a single XPage. I am using customizer bean to change date format, number format etc. on documents and it works fine.
Now I want to change/translate column titles, but I don't have an idea how to set different column title using customizer bean. Has somebody already solved that issue?
You can override 'createColumn' method and adjust the column information. You just need to cast ColumnDef arg3 argument to DefaultColumnDef so you can update some properties. Then you have to send this updated DefaultColumnDef object into former createColumn method ...
#Override
public IControl createColumn(FacesContext arg0, UIDynamicViewPanel arg1,int arg2, ColumnDef arg3) {
DefaultColumnDef dc=(DefaultColumnDef) arg3;
dc.title=arg3.getTitle()+"some your text";
// send DefaultColumn object into former createColumn method ...
IControl col = super.createColumn(arg0, arg1, arg2, dc);
return col;
}
Related
I have a JavaFX TableView where each row should have a conditional style.
The styling is dependent on whether the source item of of the table row is present in a certain list or not.
This is what I have so far:
1) The data class that holds the data of a table row together with two boolean properties (true if the data is contained in list X) and a string property that should bind to the correct style attributes.
private class WebPageData {
private WebPage page;
private BooleanProperty isReferenced = new SimpleBooleanProperty(false);
private BooleanProperty isReferencing = new SimpleBooleanProperty(false);
private StringBinding style = new When(isReferenced).then("...").otherwise(...);
}
2) A change listener on table selection change that updates each boolean property accordingly, when the table selection changes
tblResultData.getSelectionModel().getSelectedIndices().addListener(new ListChangeListener<Integer>() {
#Override
public void onChanged(ListChangeListener.Change<? extends Integer> arg0) {
if (arg0.getList().size() == 0) {
selectedPage.set(null);
} else {
// for coloring only consider the first selected row
// multi select must be doable for certain other features
WebPage selectedWebPage = tblResultData.getItems().get(arg0.getList().get(0)).page;
selectedPage.set(selectedWebPage);
// tableModel.data holds a list of data for every table row
for (WebPageData data : tableModel.data) {
boolean referenced = selectedWebPage.getReferencedWebPagesList().contains(data.page);
boolean referencing = selectedWebPage.getReferencingWebPagesList().contains(data.page);
data.isReferenced.set(referenced);
data.isReferencing.set(referencing);
}
}
}
});
Now what I want to do is to somehow bind the style property of each table cell to the style property of WebPageData - so that the change listener updates the two boolean properties, therefore the style property of WebPageData is updated and in consequence the style of the table cell changes.
I tried to bind the style during creation phase by using a custom TableCellFactory, but of course this approach fails as there is no WebPageData instance present at this time. As the TableColumn classes don't provide an opportunity to iterate over all cells (so I could bind the style after the table actually gets its data), the only option I currently see is to keep a reference to each created table cell. I don't consider this solution is good practice.
So is there any other option to bind the cell styles? If I don't bind them, I have to set the styles manually each time the table selection changes - which puts me to the "I can't iterate over cells" problem again.
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ChangeListener;
import javafx.scene.control.TreeTableRow;
public class HighlightBoundTreeTableRow extends TreeTableRow<Thing> {
private static final String CHOSEN_STYLE_CLASS = "chosenStyle";
private final ObjectProperty<Boolean> chosen = new SimpleObjectProperty<>();
private final ChangeListener propertyChangeListener = (obs, ov, nv) -> updateHighlight();
#Override
protected void updateItem(Thing item, boolean empty) {
super.updateItem(item, empty);
//cleanup
getStyleClass().remove(CHOSEN_STYLE_CLASS);
chosen.unbind(); // unbinding something that is not bound has no effect
chosen.removeListener(propertyChangeListener); // also ok to remove a listener that was never there
if (empty) {
return;
}
chosen.bind(item.chosenProperty()); //bind will also set the intial value
chosen.addListener(propertyChangeListener);
updateHighlight();
}
private void updateHighlight() {
if (chosen.get()) {
getStyleClass().add(CHOSEN_STYLE_CLASS);
} else {
getStyleClass().remove(CHOSEN_STYLE_CLASS);
}
}
}
I know this was asked forever ago but maybe it'll help someone.
I had a similar issue I wanted to solve. I know you're using a TableCell and this involves a TreeTableRow but I believe the concept is the same: You want to change a field in your data object and have that change update the styling on wherever that object is being displayed in a table.
So I extended TreeTableRow and gave that class its own property field to hold on to. Every time that row is updated I unbind that property and rebind it to the field I want to listen to. (I do the same with the listener.) Since every time updateItem() is called it could be getting a different instance of my data object.
"chosenStyle" is just a class in my style sheet that changes the background color. Using classes instead of calling setStyle() makes it easier to remove the styling.
I'm an Android newbie.
I'm trying to set custom colors inside an ExpandableListView adapter. I have defined my colors in colors.xml, but I'm unable to use them in my adapter. I get an error "The method getResources() is undefined for the type ExpandableListAdapter"
The function expects an int. I've tried to pass my result from getResources in, but, it does'nt work. I've also tried to pass in a hex value, but it does'nt change anything.
How can I use my custom colors in my code?
public View getGroupView(int groupPosition, boolean arg1, View convertView,
ViewGroup arg3) {
int n = 0;
String laptopName = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.group_item, null);
}
TextView item = (TextView) convertView.findViewById(R.id.demo);
item.setTypeface(null, Typeface.BOLD);
item.setText(laptopName);
convertView.setBackgroundColor(getResources().getColor(R.color.purple));
return convertView;
}
Thanks guys, the following snippet works
this.context = (Activity) context;
convertView.setBackgroundColor(this.context.getResources().getColor(R.color.purple));
Assuming you have a context instance somewhere in the adapter instead of this
convertView.setBackgroundColor(getResources().getColor(R.color.purple));
it should be this
convertView.setBackgroundColor((your context).getResources().getColor(R.color.purple));
and if you don't have a reference to the context just pass it in to the adapter constructor
As loulou8284 mentioned you can put it in your XML, or if it is fixed, define it with Color.rgb(), but to make your code running you need to get the reference to your Context as your class is not declared inside a context-class:
convertView.setBackgroundColor(getContext().getResources().getColor(R.color.purple));
You can declare the color in you .xml file ( in your item xml file )
Use setBackgroundResource() rather than setBackgroundColor()
setBackgroundResource() takes an integer resource index as parameter, and load whatever resource that index points to (for example; a drawable, a string or in your case a color).
setBackgroundColor(), however takes an integer representing a color. That is, not a color-resource, but a direct, hexadecimal, rgba value (0xAARRGGBB).
I need to get help with a problem.
I have an application, which displays data from database.
In database I am using one column for identifying an object with changes in time (version of object).
I mean that rows have different IDs, but same OBJECT_ID.
They are also differentiated by validity DATE columns (VALID_FROM and VALID_TO), so i can find the proper version of object in selected time.
When page is shown to user, he sets DATE for displaying data.
There is form on page, with Select Boxes (their items are object from database).
I need to show only items, that satisfy the validity condition.
Everything is OK before form handling.
I am using custom converter, that converts String value (ID of row in database table) to Object of my model, but I need two values for row to find. (ID and DATE from user form).
Converter method getAsObject gets only one VALUE parameter (ID from Select Box).
How to get second parametr to work?
Can i find it from Bean or from JSF input object?
If there is some way that includes using <f:attribute/>, is there way to set <f:attribute/> by Java code in Bean? (Form is generated by bean method).
I am sorry for my English, i try my best :o)
P.S.: Date parameter is important in sqlMap because of JOIN used. I search by ID, but other tables are joined by OBJECT_ID (version) => and i need to get one row only
Thanks for answers and have a nice day
Worsik
Edit:
Select Boxes are generated by this code:
uiInput = new HtmlSelectOneMenu();
UISelectItems items = new UISelectItems();
items.setValueExpression("value", createValueExpression(
"#{myBean.referencedList." + item.getName() + "}",
List.class));
uiInput.getChildren().add(items);
Converter method looks like this:
public Object getAsObject(FacesContext context, UIComponent component, String value)
{
if (value.equals("")) {
return null;
}
Class entityType = component.getValueExpression("value").getType(
FacesContext.getCurrentInstance().getELContext());
// TODO: need to get date value from form
Date day = new Date();
return myService(context).findEntityById(entityType, Long.valueOf(value), day);
}
entityType is Class of model for object from database
myService calls Dao object and sqlMap is called
select * from object_table as t1
JOIN other_table as t2 ON t1.object_fk = t2.object_id // (or version_id)
where t1.id = #id:INTEGER#
and t2.valid_from <= #day:DATE#
and t2.valid_to >= #day:DATE#
I figured out how to do this by <f:attribute/> by code in converter:
Date day = (Date) component.getAttributes().get("dateForSearch");
and in bean method after generating SelectBox with code:
uiInput.getAttributes().put("dateForSearch", getSelectedDate());
and in pages without dynamic generating of forms i used:
<SelectOneMenu>
...
<f:attribute name="dateForSearch" value="#{myBean.selectedDate}" />
</SelectOneMenu>
I hope that this will not be only self answered question and will help somebody else
I'm trying to put an autocomplete that fetches suggestions as a list of Entry<String, Integer>
<p:autoComplete completeMethod="#{suggester.suggestTopics}"
var="x1" itemLabel="#{x1.key}" itemValue="#{x1.value.toString()}"
value="#{topicController.selected}" />
Manged bean code is as follows:
private int selected;
public int getSelected() {
return selected;
}
public void setSelected(int selected) {
this.selected= selected;
}
But this fails saying the Integer class doesn't have method/property named key. If I remove the value attribute from autocomplete then it starts working properly. But when I put value attribute it starts expecting that the object inside var should be of the same type as that inside value attribute. I believe/expect it should be that the object inside itemValue should be of the same type as that inside value attribute.
I want to use POJOs for suggestions but pass just the entity Id to the value
Using :
Primefaces 3.1
JSF 2.1.6
I believe/expect it should be that the object inside itemValue should
be of the same type as that inside value attribute.
Yes this makes sense, and it is the same in the primefaces showcase:
<p:autoComplete value="#{autoCompleteBean.selectedPlayer1}"
id="basicPojo"
completeMethod="#{autoCompleteBean.completePlayer}"
var="p" itemLabel="#{p.name}" itemValue="#{p}"
converter="player" forceSelection="true"/>
As you see is var="p" and itemValue="#{p} where p is an instance of Player. And selectedPlayer1 is also an instance of Player.
I don't know if it works with a Map since the Primefaces example is called "Pojo support" and the suggestions should be a List of elements of the same type as in the value attribute.
I think you want to use the Simple auto complete , but instead you looked at the wrong example on the showcase of the Pojo Support
x1 refers to the int selected - while it expect to be referred to a POJO (with key and value properties.) , that's why you get the message
Integer class doesn't have method/property named key
Or simple use the Simple auto complete
As commented to Matt you dont need to rebuild Player(Pojo) from Db. You can set simply id property of Player(Pojo) and in action method may be utilize this id to fetch it from DB.
In your case in convertor you might do
Entry<String, Integer> e = new Entry<String, Integer>();
e.setId(value) // where value is passed in to convertor in method getAsObject.....
This value will be set to private Entry<String, Integer> selected
I have used Pojo autocomplete but not tried with generic classes.
Hope this helps.
I know the question is outdated but I've had the same problem.
The point is that you have to assign var to p (var="p"). I think it's terribly unobvious (documentation doesnot mention it has to be that way) 'cause I thought I can assign any var name I want.
I am having some trouble with using h:selectOneRadio. I have a list of objects which is being returned which needs to be displayed. I am trying something like this:
<h:selectOneRadio id="selectPlan" layout="pageDirection">
<f:selectItems value="#{detailsHandler.planList}" />
</h:selectOneRadio>
and planList is a List of Plans. Plan is defined as:
public class Plan {
protected String id;
protected String partNumber;
protected String shortName;
protected String price;
protected boolean isService;
protected boolean isOption;
//With all getters/setters
}
The text that must appear for each radio button is actually in a properties file, and I need to insert params in the text to fill out some value in the bean. For example the text in my properties file is:
plan_price=The price of this plan is {0}.
I was hoping to do something like this:
<f:selectItems value="<h:outputFormat value="#{i18n.plan_price}">
<f:param value="#{planHandler.price}">
</h:outputFormat>" />
Usually if it's not a h:selectOneRadio component, if it's just text I use the h:outputFormat along with f:param tags to display the messages in my .property file called i18n above, and insert a param which is in the backing bean. here this does not work. Does anyone have any ideas how I can deal with this?
I am being returned a list of Plans each with their own prices and the text to be displayed is held in property file. Any help much appreciated.
Thanks!
I am now able to resolve the above issue following the recommendation below. But now I have another question.
Each radio button item must display like this:
Click **here** to see what is included. The cost is XX.
Now the above is what is displayed for each radio button. The "here" needs to be a hyperlink which the user can click and should bring up a dialog box with more info.I can display the sentence above but how do I make the "here" clickable?
Since the above is what is displayed it is the label for SelectItem(Object value, String label) which is returned.
Any ideas much appreciated.
The value passed to <f:selectItems /> must be a list or array of type javax.faces.model.SelectItem.
You can set the output label in the constructor of the SelectItem. I imagine you can access your properties file from the backing bean. The method to get the SelectItems would look something like this:
public List<SelectItem> getPlanItems() {
List<SelectItem> list = new ArrayList<SelectItem>();
for (Plan plan : planList) {
String label = buildPlanPriceLabel(plan.getPrice());
list.add(new SelectItem(plan, label));
}
return list;
}
Leaving buildPlanPriceLabel as an exercise for the reader.