making charts interactive in primefaces3 - primefaces

Trying to make my p:barChart interactive and getting jQuery.js.jsf script error in the browser window.
I added the following code as per the primefaces lab showcase to make my chart interactive,
java service code:
public void itemSelect(ItemSelectEvent event) {
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Item selected",
"Item Index: " + event.getItemIndex() + ", Series Index:" + event.getSeriesIndex());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
I use Primefaces3.M2 release and JSF2.
Can anybody help me fix this.

Related

Labels for tooltips on primefaces barchartseries

I have tried to search both the forum and Google extensively, but I have problems understanding how I should make this work:
PrimeFaces6
I have a BarchartModel based on the tutorial in the ShowCase:
CODE: SELECT ALL
private BarChartModel initStatusBarChart() {
BarChartModel model = new BarChartModel();
ChartSeries statusMessages = new ChartSeries();
statusMessages.setLabel("Label"));
statusMessages.set("Some String 1", list1.size());
statusMessages.set("Some String 2", list2.size());
model.addSeries(statusMessages);
return model;
}
The issue is that on render, I get tooltips the format of
"1, 515" and "2, 432", where 515 and 432 are the sizes of list1 and list2, respectively.
How can I replace 1 and 2 with the values "Some String" 1 and 2 ? Have tried extending highlighter and using dataTipFormat, with no success.
I solved the problem using the datatip editor of the chart model (with Primefaces 6.1, by the way). I used this for a stacked bar chart.
I needed to apply this solution at two places: the backing bean and the JSF page.
In the backing bean I had to set a JavaScript function name this way:
barModel.setDatatipEditor("chartDatatipEditor");
I tried to set it using the corresponding tag attribute in the JSF page but to no effect.
In the JSF I inserted this JavaScript code:
<script type="text/javascript">
function chartDatatipEditor(str, seriesIndex, pointIndex, plot) {
//console.log('chartDatatipEditor: '+str+" - "+seriesIndex+" - "+pointIndex);
var point = seriesIndex+','+pointIndex;
#{bean.datatipsJs}
}
</script>
This JS function gets the chart coordinates as parameters. I concat them so that the following JS code gets easier.
seriesIndex is the index of the chart series. pointIndex is the index on the X scale of the diagram.
To find out what are the correct values for your chart you can uncomment the console.log line above.
The inserted JS code is constructed in the backing bean this way:
private Map<String, String> chartDatatips;
public String getDatatipsJs() {
StringBuilder sb = new StringBuilder("switch ( point ) {\n");
for (String point : chartDatatips.keySet()) {
sb.append("case '").append(point).append("': return '").append(chartDatatips.get(point)).append("'; break;\n");
}
sb.append("default: return 'Unknown point'; break; }");
return sb.toString();
}
The map chartDatatips has the coordinate point as key (e.g., "2,1") and the tooltip as value.
During the chart setup you obviously have to fill this map with useful details ;-)
Like this:
chartDatatips.put("2,5", "Label ...");
...
Hope this helps, if you didn't already solved this.
~Alex
Based on Alex's answer I have come up with this. Only requiring javascript - it displays the label and value:
In the backing bean, set a JavaScript function name this way:
barModel.setDatatipEditor("chartDatatipEditor");
In the HTML file:
function chartDatatipEditor(str, seriesIndex, pointIndex, plot) {
return plot.series[seriesIndex].label + ' - ' + plot.data[seriesIndex][pointIndex];
}

Unable to create a button in my Class ASP.net

So I want to add a asp button after my I create a new instance. I'm having trouble giving the button a name, id, etc. Like so <asp:Button ID="Button1" runat="server" Text="Button" /> I'm unable to do this because everytime I try to add parenthesis " " it won't work. Also, I want to be able to give all the Logs a seperate id for each button created. I'm also having trouble removing the output that its creating in the top left hand side corner, why is this appearing twice? I just want it to appear ONCE in the middle of the page! Keep in mind, I've search alot of places for this but there are no answers. Any help, I will provide all the code below that is need. Thanks!
Class:
public class WelcomeText
{
public string Greet;
public string Name;
public DateTime Visited;
public WelcomeText(string greet, string name, DateTime visited)
{
Greet = greet;
Name = name;
Visited = visited;
}
public void greetUser(string msg)
{
HttpContext.Current.Response.Write(msg + Greet + " " + Name + " " + Visited + "<button></button><br/>");
}
}
HTML:
<body>
<form id="form1" runat="server">
<div>
<section>
<%=displayWelcomeText()%>
</section>
</div>
</form>
</body>
Code behind:
public partial class WebForm1 : System.Web.UI.Page
{
public delegate void greetDel(string msg);
protected void Page_Load(object sender, EventArgs e)
{
// display text
displayWelcomeText();
}
public string displayWelcomeText()
{
string greetString = "";
WelcomeText wT1 = new WelcomeText("Welcome", "Sean", DateTime.Now);
WelcomeText wT2 = new WelcomeText("Hey", "Test", DateTime.Now);
WelcomeText wT3 = new WelcomeText("Hello", "User", DateTime.Now);
greetDel gD1 = new greetDel(wT1.greetUser);
gD1("Log: ");
greetDel gD2 = new greetDel(wT2.greetUser);
gD2("Log: ");
greetDel gD3 = new greetDel(wT3.greetUser);
gD3("Log: ");
return greetString;
}
}
Problem with my code
Oy!! More than a few problems to solve here.
First, you see the output twice because you are calling the method named displayWelcomeText() twice: the first time in the Page load and again from the aspx page-code itself, e.g. <%=displayWelcomeText()%>.
If you were to examine the content sent by the server, you'd notice that the first set of text is being sent BEFORE the initial tag. Then the second set is inside the <div><section> area.
What's wrong with changing the to be a
Then in the page load method...
myPanel.Controls.Add(new Button() { Text=String.Format("{0} {1}, {2:MM/dd/yyyy}", wt.Greet, wt.Name, wt.Visited);
That will accomplish what you say you want to do. Whether that's going to do anything meaningful is another problem to resolve.

Eclipse FormEditor button as page title

I implemented my custom FormEditor. Now I want to let user create new FormPages (a.k.a. tabs) in this editor like it is made e.g. in Chrome tabs. How to insert a "new tab" button near the titles of existing FormPages?
Thank you in advance!
UPD:
I added a FormPage with title "+" and insert new page in listener to PageChangedEvent.
You can add actions to the toolbar at the top right of a FormPage like this:
ScrolledForm form = managedForm.getForm();
IToolBarManager manager = form.getToolBarManager();
Action myAction = new Action("My Action") {
public void run() {
// TODO your action
}
};
myAction.setToolTipText("tooltip text");
myAction.setImageDescriptor(action image descriptor);
manager.add(myAction);

Primefaces: Growl is displayed without the icon

When growl is displayed (in the example below, showing the message 'Chart updated') the icon does not appear. There are no error messages in the console. This happens in a single page, the rest of the application works fine. What could be wrong?
UPDATE: the page is loaded as an iframe
This is how the growl is declared:
<p:growl life="2000" id="messages" for="msg1" showDetail="true"/>
and the java:
FacesContext context = FacesContext.getCurrentInstance();
FacesMessage fm = new FacesMessage("Chart updated", "");
context.addMessage("msg1", fm);
You need to add the Severity of your FacesMessage. You can use the following constructor:
FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_INFO,
"Message header", "Message detail")
Cheers.

The image I add to a header doesn't appear

I'm trying to create a header with an image; the header is added, but the image is missing in header. My application is deployed on an Oracle Weblogic server (using Java EE and Hibernate).
I'm trying to create the image like this. getImage(seasonalFilter.getPictureFileId()).getAbsolutePath(). The image path is something like this: /tmp/6461346546165461313_65464.jpg.
Note that I want to add text under the image in the header (for every page).
public File convertHtmlToPdf(String JSONString, ExportQueryTypeDTO queryType, String htmlText, ExportTypeDTO type) throws VedStatException {
try {
File retFile = null;
FilterDTO filter = null;
HashMap<Object, Object> properties = new HashMap<Object, Object>(queryType.getHashMap());
filter = JSONCoder.decodeSeasonalFilterDTO(JSONString);
DateFormat formatter = new SimpleDateFormat("yyyy_MM_dd__HH_mm");
//logger.debug("<<<<<< HTML TEXT: " + htmlText + " >>>>>>>>>>>>>>>>");
StringBuilder tmpFileName = new StringBuilder();
tmpFileName.append(formatter.format(new Date()));
retFile = File.createTempFile(tmpFileName.toString(), type.getSuffix());
OutputStream out = new FileOutputStream(retFile);
com.lowagie.text.Document document = new com.lowagie.text.Document(com.lowagie.text.PageSize.LETTER);
com.lowagie.text.pdf.PdfWriter pdfWriter = com.lowagie.text.pdf.PdfWriter.getInstance(document, out);
document.open();
com.lowagie.text.html.simpleparser.HTMLWorker htmlWorker = new com.lowagie.text.html.simpleparser.HTMLWorker(document);
String str = htmlText.replaceAll("ű", "û").replaceAll("ő", "õ").replaceAll("Ő", "Õ").replaceAll("Ű", "Û");
htmlWorker.parse(new StringReader(str));
if (filter instanceof SeasonalFilterDTO) {
SeasonalFilterDTO seasonalFilter = (SeasonalFilterDTO) filter;
if (seasonalFilter.getPictureFileId() != null) {
logger.debug("Image absolutePath: " + getImage(seasonalFilter.getPictureFileId()).getAbsolutePath());
Image logo = Image.getInstance(getImage(seasonalFilter.getPictureFileId()).getAbsolutePath());
logo.setAlignment(Image.MIDDLE);
logo.setAbsolutePosition(0, 0);
logo.scalePercent(100);
Chunk chunk = new Chunk(logo, 0, 0);
HeaderFooter header = new HeaderFooter(new Phrase(chunk), true);
header.setBorder(Rectangle.NO_BORDER);
document.setHeader(header);
}
}
document.close();
return retFile;
} catch (Exception e) {
throw new VedStatException(e);
}
}
I really dislike your false allegation that "Every tutorial is based on C:\imagelocation\dsadsa.jpg"
I'm the author of two books and many tutorials about iText and I know for a fact that what you say doesn't make any sense. Take a look at my name: "Bruno Lowagie." You are using my name in your code, so please believe me when I say you're doing it completely wrong.
Instead of HTMLWorker, you should use XML Worker. HTMLWorker is no longer supported and will probably be removed from iText in the near future.
I see that you're also using the HeaderFooter class. This class has been removed several years ago. Please take a look at the newer examples: http://www.itextpdf.com/themes/keyword.php?id=221
These examples are written in Java; if you need the C# version, please look for the corresponding C# examples in the SVN repository.
Regarding images, you may want to read chapter 10 of my book.
Finally: please read http://lowagie.com/itext2