I just started using PrimeFaces and cannot figure what is wrong with my code. It is exactly the same as the show case sample with the exception of the bean names. I looked at this site for answers without success.
PrimeFaces:
<p:calendar value="#{securityForecastReturnBean.date}"
mode="inline" onSelectUpdate="inputsGrowl"
selectListener="#{securityForecastReturnBean.handleDateSelect}"
required="true" />
Java Bean:
#Component
#Scope("request")
#ManagedBean
public class SecurityForecastReturnBean {
public void handleDateSelect(DateSelectEvent event) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
FacesContext facesContext = FacesContext.getCurrentInstance();
facesContext.addMessage(null,
new FacesMessage(FacesMessage.SEVERITY_INFO, "Date Selected",
format.format(event.getDate())));
}
}
It should be really straightforward yet it is saying that my bean does not have this property??
Here is the exact error message:
javax.servlet.ServletException: /security_page.xhtml: The class 'com.ls.forecast.webui.beans.SecurityForecastReturnBean' does not have the property 'handleDateSelect'.
javax.faces.webapp.FacesServlet.service(FacesServlet.java:325)
com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:546)
com.sun.faces.application.view.JspViewHandlingStrategy.executePageToBuildView(JspViewHandlingStrategy.java:363)
com.sun.faces.application.view.JspViewHandlingStrategy.buildView(JspViewHandlingStrategy.java:154)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:100)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
I am using PrimeFaces 2.2.1.
Any help would be greatly appreciated!
I figured out my issue. It had to do with using the wrong namespace. I had to use http://primefaces.org/ui instead of the old one.
This looks like it might be an error in the documentation:
From the Primefaces Guide 2.2:
Ajax Selection
Calendar supports instant ajax selection which means whenever a date is selected a server side
selectListener can be invoked with an org.primefaces.event.DateSelectEvent instance as a
parameter. Optional onSelectUpdate option allows updating other component(s) on page.
<p:calendar value="#{calendarBean.date}" onSelectUpdate="messages"
selectListener="#{calendarBean.handleDateSelect}" />
<p:messages id="messages" />
public void handleDateSelect(DateSelectEvent event) {
Date date = event.getDate();
//Add facesmessage
}
Programatically it seems to expect a property on the managed bean. You can try changing it to this and see if it makes a difference #{calendarBean.handleDateSelect()}. Are you absolutely sure that you are not referencing handleDateSelect elsewhere in the markup?
The source code example given in the PrimeFaces Showcase is wrong. The method should not be taking org.primefaces.event.SelectEvent, it should be taking org.primefaces.event.DateSelectEvent. A quick change to the source code example now looks like this:
public void handleDateSelect(DateSelectEvent event) {
FacesContext facesContext = FacesContext.getCurrentInstance();
SimpleDateFormat format = new SimpleDateFormat("d/M/yyyy");
facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Date Selected", format.format(event.getDate())));
}
Related
I'm trying to make use of the #onclick when developing a jenkins plugin but nothing happens when the checkbox which has this attribute is clicked (same with #onchange).
I have a checkbox for each job implemented as a ListViewColumn with the corresponding column.jelly file
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<td>
<f:checkbox name="selected" onclick="${it.itClicked()}" onchange="${it.itClicked()}" />
</td>
</j:jelly>
and the method itClicked() resides in the corresponding java class of this jelly file:
class CheckboxTemplate extends ListViewColumn {
...
public void itClicked() {
System.out.println("it clicked!");
}
...
#Extension
public static class DescriptorImpl extends ListViewColumnDescriptor {
...
}
But this apparently is not working...
I've made another plugin before which called a method in the java class from the predefined object "it" from the jelly file and it worked fine, so having the method defined in the working place is not the problem (I assume).
Anyone who has any idea of why itClicked() is not executed when the checkbox is checked/changed?
If there is information that I missted posting, tell me, and I'll come back with it asap!
I managed to solve this by adding
<st:bind var="myItem" value="${it}"/>
in my jelly file and changing #clicked to
onclick="myItem.mark('${job.fullName}')"
where mark() was defined in the backend with the particular annotation
#JavaScriptMethod
public void mark(String job) {
// do what you need to do
}
job if of course a predefined variable in the column.jelly file which is not required for this to work, I only passed it to map the checkbox with the corresponding job name.
Hope this is useful for others who struggle with the documentation (and with the nonexisting complete examples) on these topics.
I currently have a problem with setting a CheckBoxTableCell from the FXML. I tried to convert this code to FXML:
tableCol.setCellValueFactory(new PropertyValueFactory<Product, Boolean>("property"));
tableCol.setCellFactory(CheckBoxTableCell.forTableColumn(toStockCol));
where 'property' is just some attribute of the 'Product' Class (from type 'boolean'). This code works fine. I now try to set this in the FXML, like this:
<TableColumn text="Some Col">
<cellValueFactory><PropertyValueFactory property="property" /></cellValueFactory>
<cellFactory><CheckBoxTableCell editable="true" /></cellFactory>
</TableColumn>
This doesn't work, I get the following error (which is a FXML LoadExeption):
Caused by: java.lang.IllegalArgumentException: Unable to coerce CheckBoxTableCell#24d62d1e[styleClass=cell indexed-cell table-cell check-box-table-cell]'null' to interface javafx.util.Callback.
at com.sun.javafx.fxml.BeanAdapter.coerce(BeanAdapter.java:495)
at com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:258)
at com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:54)
at javafx.fxml.FXMLLoader$PropertyElement.set(FXMLLoader.java:1409)
at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:786)
at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2827)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2536)
... 42 more
I can not figure out what I am doing wrong. Also, in my opinion there is little to none documentation about how to set a CheckBox in a TableView with FXML.
Note: I would like to set this from the FXML, because it seems to be the spot for this. I know this can be done with the FXML controller. Also, I am just curious.
Any help is greatly appreciated!
Unfortunately CheckBoxTableCell is not a factory, and there is none available in the JavaFX package. You have to write your own factory.
public class CheckBoxTableCellFactory<S, T> implements Callback<TableColumn<S, T>, TableCell<S, T>> {
public TableCell<S, T> call(TableColumn<S, T> param) {
return new CheckBoxTableCell<S,T>();
}
}
Then you can define your table column in the FXML file as:
<TableColumn text="Some Col">
<cellValueFactory><PropertyValueFactory property="property" /> </cellValueFactory>
<cellFactory><CheckBoxTableCellFactory /></cellFactory>
</TableColumn>
DonĀ“t forget to include the CheckBoxTableCellFactory or else to declare the full path like org.my.CheckBoxTableCellFactory or the loader will give you a not found exception.
If you like to manage all in FXML here is how to do it.
Don't forget to add <?language javascript?> to FXML header, but keep in mind that JavaScript engine Nashorn is deprecated since Java 11.
<TableColumn text="Married" fx:id="married">
<cellValueFactory>
<PropertyValueFactory property="married" />
</cellValueFactory>
</TableColumn>
<fx:script>
var myCellValue =
javafx.scene.control.cell.CheckBoxTableCell.forTableColumn( married );
married.setCellFactory(myCellValue);
</fx:script>
Your data model should be exposed as below.
private final SimpleBooleanProperty married = new SimpleBooleanProperty( false );
public SimpleBooleanProperty marriedProperty(){
return married;
}
I am trying to use the Nancy addin Nancy.LightningCache
According to the docs I should be able to set up my caching easily, like this:
Bootstrapper
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
{
base.ApplicationStartup(container, pipelines);
this.EnableLightningCache(
container.Resolve<IRouteResolver>(),
ApplicationPipelines,
new[] {"id", "claim", "query", "take", "skip"});
}
Route
Get["/profile"] = _ =>
View["UserProfileView", Model].AsCacheable(DateTime.Now.AddSeconds(30));
When this route is called I get the following exception.
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:
'Nancy.Responses.Negotiation.Negotiator' does not contain a definition for 'AsCacheable'
Any ideas?
I just hacked this https://gist.github.com/4191120 together and it worked. All using 0.13 nugets
OK, got it.
Working Route
return View["HomeView", (object)Model].AsCacheable(DateTime.Now.AddMinutes(1));
You can see that I have been forced to explicitly cast my Model to an object in order to satisfy the signature of the AsCachable extension method.
The problem only shows up at runtime because my Model is an ExpandoObject and so a dynamic type.
I have a problem with <h:inputText>. In particular I have a series of inputtext, combobox, calendar on an xhtml page.
Each of them has the value attribute like follow value="#{myBean.first}", value="#{myBean.second}", and so on.
In this manner myBean must have an enormous number of setter and getter.
I need to use only one setter and only one getter like the following:
public void setValue(String theId, String theValue){}
public String getValue(String theId){}
So in these only two methods I use a Map with key=theId and value=theValue inserted by user.
My question is how can do this in xhtml page?
That's how value-tag would be? Is there a special notice for passing a parameter to setter/getter?
Note that the "parameter" added to the inputText could be an object.
How can I do?
If you want to store the key/value pairs in a Map, you can reference the map directly in your UI components. Say your backing bean has this:
public Map<String, Object> getDataMap() { return dataMap; }
public void setDataMap(Map<String,Object> dataMap) { this.dataMap = dataMap; }
Your xhtml could look like this:
<h:inputText value="#{myBean.dataMap['first']}" />
<h:inputText value="#{myBean.dataMap['second']}" />
I am new to WPF and Prism, but I already learned that you have to register a View in Unity as an object:
Container.RegisterType<Object,MyView>("My.Assembly.MyView");
Still, when I use
var RelativeUriToMyView = new Uri("My.Assembly.MyView",UriKind.Relative);
RegionManager.RequestNavigate(RelativeUriToMyView, RegionName, CallbackResult);
the MyView displays as System.Object, and the CallbackResult contains no Error.
What am I missing? I'm happy to provide more information if needed.
You would want to look at the RegionNavigationContentLoader.cs in the PRISM source code; Here is the code that is loading the view for you.
protected virtual object CreateNewRegionItem(string candidateTargetContract)
{
object newRegionItem;
try
{
newRegionItem = this.serviceLocator.GetInstance<object>(candidateTargetContract);
}
catch (ActivationException e)
{
throw new InvalidOperationException(
string.Format(CultureInfo.CurrentCulture, Resources.CannotCreateNavigationTarget, candidateTargetContract),
e);
}
return newRegionItem;
}
There are several helper methods that take the URI, extract the query string, and create the 'name' used to lookup your view and cast it as an object.
Essentially, the name you are using to associate your concrete class as an object with Unity is the same one you'll need to use when you try to resolve the object with Unity. Here is some pesudocode to explain,
Container.RegisterType<object, ConcreteClass>(typeof(ConcreteClass).FullName);
Locator.GetInstance<object>(UriWithFullName)
If none of this helps, post the RelativeUriToMyView so I can see the contents.
Good luck.
The issue seemed to be caused by registering the view with its FullName (My.Assembly.MyView) instead of its Name (MyView).
Edit:
Changed the question to more accurately reflect the issue.