I have several questions how to improve this Primefaces chart.
This is the source code:
<h:form>
<p:barChart id="basic" value="#{DashboardController.categoryModel}" legendPosition="ne"
title="Accounts and Groups" min="0" max="200" style="height:400px"
shadow="true" barPadding="60"/>
</h:form>
import org.primefaces.model.chart.CartesianChartModel;
import org.primefaces.model.chart.ChartSeries;
#Named("DashboardController")
#SessionScoped
public class Dashboard implements Serializable
{
/*
* Call the Oracle JDBC Connection driver
*/
#Resource(name = "jdbc/Oracle")
private DataSource ds;
private CartesianChartModel categoryModel;
public Dashboard()
{
createCategoryModel();
}
public CartesianChartModel getCategoryModel()
{
return categoryModel;
}
private void createCategoryModel()
{
categoryModel = new CartesianChartModel();
// Active Accounts
ChartSeries ActiveAccounts = new ChartSeries();
ActiveAccounts.setLabel("Active Accounts");
ActiveAccounts.set("Active Accounts", 120);
categoryModel.addSeries(ActiveAccounts);
// Blocked Accounts
ChartSeries BlockedAccounts = new ChartSeries();
BlockedAccounts.setLabel("Blocked Accounts");
BlockedAccounts.set("Blocked Accounts", 120);
categoryModel.addSeries(BlockedAccounts);
// Active Groups
ChartSeries ActiveGroups = new ChartSeries();
ActiveGroups.setLabel("Active Groups");
ActiveGroups.set("Active Groups", 120);
categoryModel.addSeries(ActiveGroups);
// Blocked Groups
ChartSeries BlockedGroups = new ChartSeries();
BlockedGroups.setLabel("Blocked Groups");
BlockedGroups.set("Blocked Groups", 120);
categoryModel.addSeries(BlockedGroups);
}
}
Can you tell me how I can change the color of the chart size, also the color of "Accounts and Groups"?
I also want to ask you how I can add names below every column? Now I have only one name "Active Accounts". I want to name the columns individually.
Best wishes
P.S I tested this code into the JSF header but it's not working:
<script type="text/css">
.jqplot-title{
color:red;
}
</script>
P.S 2 Only the label of the chart is changed
Use the seriesColors attribute of <p:barChart
like this seriesColors="000000, FFFFFF, 2288AA"
about the title and the axis color, use this:
.jqplot-title{
color: #FF0000;
}
.jqplot-xaxis-label{
color: #FF0000;
}
.jqplot-yaxis-label{
color: #FF0000;
}
Related
I have been following this tutorial
http://www.primefaces.org/showcase-ext/sections/dynaform/basicUsage.jsf
I have been able to create tree Dynaform objects and send it to the page. But I am having a hard time obtaining the values that the user entered once they clicked submit. I want to be able to get these values in the backbean.
Here is submit button
<p:commandButton value="Submit" action="#{dynaFormController.submitForm}"
process="dynaForm" update=":mainForm:dynaFormGroup :mainForm:inputValues"
oncomplete="handleComplete(xhr, status, args)"/>
<p:commandButton type="reset" value="Reset" style="margin-left: 5px;"/>
I know the submit calls this function
<h:outputScript id="dynaFormScript" target="body">
/* <![CDATA[ */
function handleComplete(xhr, status, args) {
if(args && args.isValid) {
PF('inputValuesWidget').show();
} else {
PF('inputValuesWidget').hide();
}
}
/* ]]> */
</h:outputScript>
Then in the bean we have:
public String submitForm() {
FacesMessage.Severity sev = FacesContext.getCurrentInstance().getMaximumSeverity();
boolean hasErrors = (sev != null && (FacesMessage.SEVERITY_ERROR.compareTo(sev) >= 0));
RequestContext requestContext = RequestContext.getCurrentInstance();
requestContext.addCallbackParam("isValid", !hasErrors);
return null;
}
How would I be able to get either the fields values from the submitted form?
I have 3 dynaforms that I would like to submit them and be able to get the values in the back bean. Can anyone explain? I tried looking up some tutorials but I didn't find any explaining this.
Thanks.
It's the same as plain JSF.
You need a variable in your bean, its getters and setters.
Then, you compare it to the DynaFormControl.
#ManagedBean
#SessionScoped
public class DynaFormController implements Serializable {
private static final long serialVersionUID = 1L;
private DynaFormModel model;
private BookProperty bookProperty;
public String getBookProperty() {
return bookProperty;
}
public void setBookProperty(BookProperty bookProperty) {
this.bookProperty = bookProperty;
}
public String submitForm() {
//your code
List<DynaFormControl> controls = model.getControls();
for (DynaFormControl control : controls) {
if(control.getData() instanceof BookProperty) {
BookProperty bp = (BookProperty) c.getData();
//use the object
}
}
return null;
}
}
I have data grid and table.In data grid ,I have command buttons for every location. In(mysql) table I have id,date,location attributes. The button should get coloured based on the id present in the table. how can I get this? please do some favour..Thanks in advance..
This is my command Button ..
<h:commandButton id="login" value="Reason"
style="#{home.rest()},height: 20px;left: 200px;font-size: 50%;bottom: 1px;font-family: bold;position: relative" />
I have used Java method..here it is...
public String rest(){
String a;
String table_id;
List user=new ArrayList();
DBQuery db=new DBQuery();
user=db.table(getDate());
String id="";
List off=new ArrayList();
off = db.entire_location(toDate(),getDate());
for(int j=0;j<user.size();j++){
for(int i=0;i<off.size();i++){
home_bean hello = (home_bean)user.get(j);
table_id=hello.getable_id();
home_bean hi = (home_bean)off.get(i);
id= hi.getentire_id();
if(id.equals(table_id)){
System.out.println("True");
a="red";
// return "background-color: red;width:100%";
} else
a="";
System.out.println("Fallse");
}}return "a";
}
I think what you should do is the following :
1- create a variable in your bean :
private String style;
public void setStyle(String style) {
this.style = style;
}
public String getStyle() {
return style;
}
2- in your JSF tag do like the following :
<h:commandButton id="login" value="Reason"
style="#{bean.style}" />
and try to put your java code in the setStyle method
Hope That Helps.
dude Is this correct way to put in the style attribute..
style="#{home.rest()},height: 20px;left: 200px;font-size: 50%;bottom: 1px;font-family: bold;position: relative" />
I'm trying primefaces 4 but there are no documentation around for the new MenuModel. Here, Optimus Prime wrote about the new menu system with a little example.
http://blog.primefaces.org/?p=2594
At this point, he wrote about a setCommand method:
This point to a save method (found in the pf4 showcase: http://www.primefaces.org/showcase/ui/menu/menu.xhtml):
After this introduction, here's the question/problem. I'm creating a dynamic menu from a bean but I don't understand how know the menu clicked by the user and do the right operation.
public void init() {
if (spBean == null) {
System.out.println("spBean is NULL!");
return;
}
for (ServiceProvider sp: spBean.getListaSP()) {
DefaultMenuItem item = new DefaultMenuItem(sp.getNome());
//item.setUrl("#");
item.setIcon("images/sps/" + sp.getImageId() + ".png");
item.setCommand("#{dockMenuBackingBean.setNewMenu}");
//
model.addElement(item);
System.out.println(sp.getNome());
}
}
public void setNewMenu() {
System.out.println("A menu was clicked BUT witch menu? Arghh!!");
//
}
What I want to do, is to change the spSelected in ServiceProviderBackingBean, like I've done in PF3.5:
<p:dock>
<c:forEach items="#{serviceProvidersBean.sps}" var="sp">
<p:menuitem
value="#{sp.spInstanceName}"
icon="/images/sps/#{sp.spInstanceId}.png"
update=":form:spDetail" >
<f:setPropertyActionListener
value="#{sp}"
target="#{serviceProvidersBean.spSelected}" />
</p:menuitem>
</c:forEach>
</p:dock>
Any help?
EDIT:
Actually I'm doing this, but I'm looking for a better and cleaner way to achieve this.
public void init() {
if (spBean == null) {
System.out.println("spBean is NULL!");
return;
}
for (ServiceProvider sp: spBean.getListaSP()) {
DefaultMenuItem item = new DefaultMenuItem(sp.getNome());
//item.setUrl("#");
item.setIcon("images/sps/" + sp.getImageId() + ".png");
String command = String.format("#{dockMenuBackingBean.setNewMenu('%d')}", spBean.getListaSP().indexOf(sp));
item.setCommand(command);
//
model.addElement(item);
System.out.println(sp.getNome());
}
}
public void setNewMenu(Object x) {
Integer selectedId = Integer.parseInt((String)x);
System.out.println("Menu changed " + Integer.toString(selectedId));
//
}
Setting command parameters by setParam(key,value) can be done like that:
In your menu generating bean:
DefaultMenuItem item = new DefaultMenuItem("display list");
item.setId("listMenuItem");
item.setCommand("#{myBean.displayList}");
item.setParam("listId", 1l);
In your managed bean containing the action:
public String displayList(ActionEvent event) {
MenuItem menuItem = ((MenuActionEvent) event).getMenuItem();
Long id = Long.parseLong(menuItem.getParams().get("listId").get(0));
findListBy(id);
}
Reading parameters seems to be a bit complicated. But ActionListeners aren't supported by Primefaces 4 MenuItems (because they aren't derived from UICommand any more) so params seem to be new new way.
Optimus here, use setParam(key,value). You need to update to trunk code though for this.
I have this css file which sets the default font size and type in JavaFX application:
.root {
-fx-font: 13px Tahoma;
}
scene.getStylesheets().add(getClass().getResource("/styles/Styles.css").toExternalForm());
I want to update the size and the font type from the Java code dynamically of the root component (all components). How I can do this?
Note:
This code updates the Font type and size of all components into the JavaFX application.
Please consider taking a look at the official JavaFX documentation. There you find the code example which answers your question:
Text t = new Text("That's the text");
t.setFont(Font.font ("Verdana", 20));
UPDATE
In your application controller get an instance of your root pane, e.g. AnchorPane and use the setId("") function to set new style for the whole pane (my actionChange is connected with a button on the pane, which triggers the event/change):
public class AppController implements Initializable {
#FXML
private AnchorPane mainPane;
#Override
public void initialize(URL arg0, ResourceBundle arg1) {
// TODO Auto-generated method stub
}
#FXML
public void actionChange() {
mainPane.setId("fancytext");
}
}
When pressing the button, the style for the pane is changed. I just used the font-size as an example. Before, you need to specify the new style in your CSS file:
.root {
-fx-font: 12px Tahoma;
}
#fancytext {
-fx-font: 20px Tahoma;
}
That's before:
That's after the button was pressed:
Is there something like a GroupBox or TitledBorder available on JavaFX 2?
Thanks for any hint :-)
Unless you need the custom styling in this answer, I prefer the TitledPane with setCollapsible(false) solution by Andriy Kryvtsun. For use, see a TitledPane tutorial.
No such exact standard control, but it it is easy to create your own. Here is a sample implementation:
/** Places content in a bordered pane with a title. */
class BorderedTitledPane extends StackPane {
BorderedTitledPane(String titleString, Node content) {
Label title = new Label(" " + titleString + " ");
title.getStyleClass().add("bordered-titled-title");
StackPane.setAlignment(title, Pos.TOP_CENTER);
StackPane contentPane = new StackPane();
content.getStyleClass().add("bordered-titled-content");
contentPane.getChildren().add(content);
getStyleClass().add("bordered-titled-border");
getChildren().addAll(title, contentPane);
}
}
And the accompanying css for it:
.label {
-fx-font: 28px Vivaldi;
}
.bordered-titled-title {
-fx-background-color: white;
-fx-translate-y: -16;
}
.bordered-titled-border {
-fx-content-display: top;
-fx-border-insets: 20 15 15 15;
-fx-background-color: white;
-fx-border-color: black;
-fx-border-width: 2;
}
.bordered-titled-content {
-fx-padding: 26 10 10 10;
}
The code is from a example I created in response to an Oracle JavaFX forum thread post "Equivalent to BorderFactory.createTitledBorder".
The output of the example program is as shown below.
I used TitledPane with setCollapsible(false). It looks more consistent than using CSS styles. Here is result
FXML version of jewelsea's answer:
TitledBorder (I renamed the BorderedTitledPane to TitledBorder)
package com.example.controls;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
public class TitledBorder extends StackPane
{
private Label titleLabel = new Label();
private StackPane contentPane = new StackPane();
private Node content;
public void setContent(Node content)
{
content.getStyleClass().add("bordered-titled-content");
contentPane.getChildren().add(content);
}
public Node getContent()
{
return content;
}
public void setTitle(String title)
{
titleLabel.setText(" " + title + " ");
}
public String getTitle()
{
return titleLabel.getText();
}
public TitledBorder()
{
titleLabel.setText("default title");
titleLabel.getStyleClass().add("bordered-titled-title");
StackPane.setAlignment(titleLabel, Pos.TOP_CENTER);
getStyleClass().add("bordered-titled-border");
getChildren().addAll(titleLabel, contentPane);
}
}
FXML usage:
<?import com.example.controls.*?>
<TitledBorder title="title" >
<Label text="label with text" />
</TitledBorder>
Do no forget the Stylesheet!
Use this CSS for a normal font:
.bordered-titled-title {
-fx-background-color: white;
-fx-translate-y: -10; /* play around with this value when changing the title font to get a vertically centered title */
}
.bordered-titled-border {
-fx-content-display: top;
-fx-border-insets: 20 15 15 15;
-fx-background-color: white;
-fx-border-color: black;
-fx-border-width: 2;
}
.bordered-titled-content {
-fx-padding: 26 10 10 10;
}
Using this CSS it now looks like this:
Update:
Problems when title is longer then content:
Any hint to fix this problem?
Here is an FXML document that can be loaded into SceneBuilder which has similar functionality:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane style="-fx-border-insets: 8 0 0 0; -fx-background-color: #FFFFFF; -fx-border-color: black;">
<children>
<Label alignment="TOP_LEFT" layoutX="14.0" style="-fx-padding: 0 5; -fx-background-color: inherit;" text="Title" />
<AnchorPane prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="1.0" AnchorPane.leftAnchor="1.0" AnchorPane.rightAnchor="1.0" AnchorPane.topAnchor="10.0" />
</children>
</AnchorPane>
If you need to make the label text / border size larger you should only have to edit the CSS and the topAnchor of the child AnchorPane and the first argument of -fx-border-insets of the parent AnchorPane.
GroupBox - that is usual Group layout, as far as I see.
TitledBorder - looks like a TitledPane (which is usually a component of Accordion, but could be a separately existing control).
JavaFX-2 analogs looks different from yours (but not significantly), and as usual, you can use different ways of control appearance changing: css, control's skin replacing, etc
Here is a GroupBox implementation based on TitledPane. It provides three methods to set the title, content, and content padding of the GroupBox.
public final class GroupBox extends Parent {
private StackPane _stackPane;
private TitledPane _titledPane;
public GroupBox() {
_stackPane = new StackPane();
_titledPane = new TitledPane();
setContentPadding(new Insets(10));
_titledPane.setCollapsible(false);
_titledPane.setContent(_stackPane);
super.getChildren().add(_titledPane);
}
public GroupBox(String title, Node content) {
this();
setText(title);
setContent(content);
}
public GroupBox(String title, Node content, Insets contentPadding) {
this(title, content);
setContentPadding(contentPadding);
}
public void setText(String value) {
_titledPane.setText(value);
}
public void setContent(Node node) {
_stackPane.getChildren().add(node);
}
public void setContentPadding(Insets value) {
_stackPane.setPadding(value);
}
}