I want to show some data inside infoWindow of Gmap. the code is as follow:
<p:gmap center="#{mybean.latitude}, #{mybean.longitude}" zoom="15"
type="ROADMAP" model="#{mybean.mymapModel}" >
<p:ajax event="overlaySelect" listener="#{mybean.onMarkerSelect}" />
<p:gmapInfoWindow >
<div class="popup_title prem">Address:</div>
<div class="popup_address">#{mybean.markerAll.street}, #{mybean.markerAll.zipcode} #{mybean.markerAll.city}</div>
</p:gmapInfoWindow>
</p:gmap>
and My ManagedBean
public void onMarkerSelect(OverlaySelectEvent event) {
marker = (Marker) event.getOverlay();
markerAll = (myHelperClass) marker.getData();
}
Everything is working fine in development on my local computer. When the marker is clicked, the data (address) shows up in the infoWindow.
On production I see a lot of ClassCastException like:
FullAjaxExceptionHandler: An exception occurred during processing JSF ajax request. Error page '/error.jsf' will be shown.
java.lang.ClassCastException: java.lang.String cannot be cast
to com.mypackage.util.myHelperClass
at com.mypackage.myBean.onMarkerSelect(myBean.java:416)
...
...
The property data of the org.primefaces.model.map.Marker is of type Object and not String!
What am I doing wrong? And why this works sometime and sometimes not?
I'm using Primefaces 5.3.7
I think it's missing the uppercase letter m - myHelperClass by MyHelperClass
public void onMarkerSelect(OverlaySelectEvent event) {
marker = (Marker) event.getOverlay();
markerAll = (MyHelperClass) marker.getData();
}
Related
I am trying to use the fileUpload component of PrimeFaces and everything is working BUT an empty error message is displayed when the component appeared with no content and i do not understand why.
And if i add a file to the component is disappeared well but it is still not pretty to have it when the component loads.
// View
<h:form>
<p:fileUpload fileUploadListener="#{bean.handleFileUpload}" />
</h:form>
// ManagedBean
public void handleFileUpload(FileUploadEvent event) {
UploadedFile file = event.getFile();
System.out.println("handleFileUpload : " + file);
}
The managed bean function is well called when I click on the upload button.
Hope some could understand my problem !
Thanks in advance
I want to show exception message in xhtml. Execption is generated in interceptor.
Interceptor class :
#Logable
#Interceptor
public class LoggingInterceptor
{
#AroundInvoke
public Object log(InvocationContext ctx)
throws Exception {
if (some logic)
FacesContext.getCurrentInstance().addMessage("newBandForm:ABCD", new FacesMessage(FacesMessage.SEVERITY_ERROR, "hklfhfhsf", "hklfhfhsf"));
throw new Exception("MNOP");
return ctx.proceed();
}
Action Bean Class
#Named("bcontroller")
#RequestScoped
public class BandListController
{
#Logable
public void save()
{
}
}
I want to show exception in xhtml p:message
<h:form id="newBandForm">
<p:messages id="ABCD" autoUpdate="false" closable="true" showDetail="false" escape="false"/>
</h:form>
If I write following line in Action "save()" itself, and remove Interceptor, then message i getting displayed.
FacesContext.getCurrentInstance().addMessage("newBandForm:ABCD", new FacesMessage(FacesMessage.SEVERITY_ERROR, "hklfhfhsf", "hklfhfhsf"));
It seems that exception thrown is interrupting life-cycle of JSF components also.
thanks
Detail Requirement:
I have one xhtml page which contain one field (say : F1 )and two commandButton (say : C1 and C2). For C1 button, F1 is mandatory and For C2, it is not. This is completely configurable and at bean initialization, I fetch data from database for which button, what fields are mandatory.
Now on finding #Logable annotation, I am invoking interceptor method for checking data consistency based on action. In case validation failed, I have to set p:message (for which I am accessing FaceContext).
Why am i doing like this? So that a single annotation can enable security without changing code of main action.
I end up with in javax "interceptor" after searching "aop in JSF". I do not have option of implementing spring-aop in project.
My lack of understanding about "ctx.proceed()" lead me to this problems.What it do is "Proceed to the next interceptor in the interceptor chain." and if there is non, flow will resume as usual.
(Workaround) Changing code like this solve my issue:
#AroundInvok
public Object log(InvocationContext ctx)
throws Exception {
if (!(some logic))
{
return ctx.proceed();
}
else
{
FacesContext.getCurrentInstance().addMessage("newBandForm:ABCD", new FacesMessage(FacesMessage.SEVERITY_ERROR, "hklfhfhsf", "hklfhfhsf"));
return null;
}
}
Now I am not throwing any exception from it.
I'm programmatically creating the PrimeFaces <p:column>s for a <p:dataTable> using a so-called BaseColumnHandler. There's one column here that shows an icon or not, depending on some condition given by the row's entity (here 'event').
In JSF this would look something like this (inside a <p:dataTable ... var="event" ...>):
<p:column ...>
<p:graphicImage value="/resources/somePath/to/icon/whatever.png"
title="#{of:format1('{0} conflicts available', event.results.size())}"
style="#{event.whatEverVisibleCondition ? '' : 'visibility: hidden;'}"
... />
<p:graphicImage value="/resources/somePath/to/icon/whatsoever.png"
title="What so ever available"
style="#{event.whatSoEverVisibleCondition ? '' : 'visibility: hidden;'}"
... />
</p:column>
This simply shows a single info column where each row (event entity) displays an icon for an available feature or not (CSS visibility: hidden; replaces the JSF rendered attribute, because we need the icon space to be used in case of invisiblity so that icons will align).
Please assume the icon paths to be correct.
In the class building the icon column, I have the following lines:
#Named
#ViewScoped
public class MyColumnHandler
{
// get necessary instances to handle value expressions
FacesContext facesContext = FacesContext.getCurrentInstance();
ELContext elContext = facesContext.getELContext();
ExpressionFactory factory = facesContext.getApplication().getExpressionFactory();
#PostConstruct
public void buildColumns()
{
...
UIGraphic graphicImage = new GraphicImage();
this.setTitleExpressionToComponent(graphicImage, "#{of:format1('{0} conflicts available', event.results.size())}");
...
}
private void setTitleExpressionToComponent(UIComponent component, String expression)
{
// expression goes to "title" attribute and is of type String
component.setValueExpression("title", this.factory.createValueExpression(this.elContext, expression, String.class));
}
...
}
When I render the page however, I get something like this:
javax.el.ELException: Function 'of:format1' not found
at com.sun.el.lang.ExpressionBuilder.visit(ExpressionBuilder.java:254)
at com.sun.el.parser.SimpleNode.accept(SimpleNode.java:172)
at com.sun.el.lang.ExpressionBuilder.prepare(ExpressionBuilder.java:219)
at com.sun.el.lang.ExpressionBuilder.build(ExpressionBuilder.java:230)
at com.sun.el.lang.ExpressionBuilder.createValueExpression(ExpressionBuilder.java:273)
at com.sun.el.ExpressionFactoryImpl.createValueExpression(ExpressionFactoryImpl.java:98)
at org.jboss.weld.util.el.ForwardingExpressionFactory.createValueExpression(ForwardingExpressionFactory.java:49)
at org.jboss.weld.el.WeldExpressionFactory.createValueExpression(WeldExpressionFactory.java:50)
at com.company.ci.common.view.framework.columnhandling.MyColumnHandler.setTitleExpressionToComponent(MyColumnHandler.java:121)
Obviously, the EL cannot find the OmniFaces function format1.
I have however added xmlns:of="http://omnifaces.org/functions" to every file that I can think of that is being used on the page that causes the exception.
Q:
What do I have to do to make the OmniFaces of:format1 function available, so that the exception isn't thrown? (hopefully a solution that doesn't require me to replace some ELContext with a custom class... if possible at all)
Thanks
I'm trying to implement a mechanism for global exception handling in JSF through specialization of the abstract classes ExceptionHandlerWrapper and ExceptionHandlerFactory. However, when an exception is thrown in the render response phase of the JSF lifecycle, it is not stacked (Phase.queueException is never called) and hence is not captured in the handle method of the class that specializes ExceptionHandlerWrapper.
The following code fragments summarize the situation where the mentioned problem occurs.
JSF:
<h:form id="formManterLider">
<h:selectOneMenu>
...
<p:ajax update=":formManterLider" listener="#{MB.atualizarListaLideresInstituicao}" />
...
</h:selectOneMenu>
<p:dataTable value="#{MB.lazyModel}" ... />
</h:form>
Java:
#ManagedBean
#ViewScoped
public class MB {
...
private LazyDataModel<LiderVO> lazyModel = new LazyDataModel<LiderVO>() {
#Override
public List<LiderVO> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, String> filters) {
...
List<LiderVO> lista = consultarLideresCandidatos(getInstituicaoSelecionada(), first, pageSize); // throws a RuntimeException
return lista;
}
};
}
Changing the selection value in the h:selectOneMenu component through an AJAX request triggers the problem, because the statement update=":formManterLider" causes the method load to be invoked during the render response phase, and the method consultarLideresCandidatos, which is invoked within the load method, throws a RuntimeException.
I would like to know how to detect an exception thrown in the render response phase using a class that specializes ExceptionHandlerWrapper.
Note: I'm using Mojarra 2.1.12 and Primefaces 3.2.
I had exactly the same issue (LazyDataModel + exception in the render phase). Try Mojarra 2.1.16 or greater.
See http://java.net/jira/browse/JAVASERVERFACES-2179
I would like to know how to detect an exception thrown in the render response phase using a class that specializes ExceptionHandlerWrapper.
Don't have a clue, but doesn't the server's log suffice as this is where stack traces are dumped?
To prevent the exception being thrown (and you want to update the data table only) you can update the data table directly:
<h:form id="formManterLider">
<h:selectOneMenu>
...
<p:ajax update=":formManterLider:datatable" listener="#{MB.atualizarListaLideresInstituicao}" />
...
</h:selectOneMenu>
<p:dataTable id="datatable" value="#{MB.lazyModel}" ... />
</h:form>
I've been trying a lot of different things that I would think would work like expected. However, they are causing me some frustration. Here's the scoop:
I am using ICEFaces 1.8 components in a Java EE web application. My goal is to render a bunch of ice:commandButtons on the page based on a query to my database. I want these buttons to be able to toggle selections that I will later use for parameters to another query to the database (basically a query front end of sorts for a set of users). I would like the output to look like so:
When I click on a button, I would like the following update to my page:
When I created the buttons on my page statically, as such:
<ice:commandButton id="seasonSEP09" style="background-color: #FFFFFF;" partialSubmit="true" actionListener="#{bean.updateSeasons}" value="2009-2010" />
<ice:commandButton id="seasonSEP08" style="background-color: #FFFFFF;" partialSubmit="true" actionListener="#{bean.updateSeasons}" value="2008-2009" />
<ice:commandButton id="seasonSEP07" style="background-color: #FFFFFF;" partialSubmit="true" actionListener="#{bean.updateSeasons}" value="2007-2008" />
<ice:commandButton id="seasonSEP06" style="background-color: #FFFFFF;" partialSubmit="true" actionListener="#{bean.updateSeasons}" value="2006-2007" />
this works great, and each button works individually as I would expect. My backing bean is updated, the parameters are correctly added in updateSeasons() method, and my output at the end yields the correct records.
However, I know this is not what I want. I don't want to update these anytime another season is entered in the system. Maintainance nightmare, right?
So what I want to do is dynamically generate these ice:commandButton components based on my database table full of Season objects. Here is the Season class I am using:
public class Season
{
String StartMonth;
String Season;
public String getStartMonth()
{
return StartMonth;
}
public void setStartMonth(String startMonth)
{
StartMonth = sweep;
}
public void setSeason(String season)
{
Season = season;
}
public String getSeason()
{
return Season;
}
}
Very straightforward. Two properties, which I'm guaranteed to be unique in the database.
Here is the backing bean I am using:
public class Bean
{
public Bean()
{
defineSeasonsList();
}
public List<HtmlCommandButton> seasonsList;
// seasonsList getter & setter omitted
public List<String> selectedSeasons;
// selectedSeasons getter & setter omitted
private void defineSeasonsList()
{
seasonsList = new ArrayList<HtmlCommandButton>();
selectedSeasons = new ArrayList<String>();
try
{
hibernate.openTransaction();
for(Season season:defineSeasonsListFromDataSource()))
{
HtmlCommandButton button = new HtmlCommandButton();
button.setId("season" + season.getStartMonth());
button.setValue(season.getSeason);
button.setStyle("background-color: #FFFFFF;");
button.setPartialSubmit(true);
seasonsList.add(button);
}
}
catch (Exception e)
{
System.out.println("Error defining seasons list: " + e.getMessage());
}
finally
{
hibernate.commitTransaction();
}
}
public void updateSeasons(ActionEvent ae)
{
HtmlCommandButton selected = (HtmlCommandButton) ae.getComponent();
if(selectedSeasons.contains(selected.getValue().toString()))
{
selectedSeasons.remove(selected.getValue().toString());
selected.setStyle("background: #FFFFFF;");
}
else
{
selectedSeasons.add(selected.getValue().toString());
selected.setStyle("background: #009DD9; color: #FFFFFF;");
}
}
}
OK, so here comes my dilemma(s).
First, I tried to render this markup:
<p>
<ice:panelGroup>
<ice:panelSeries id="seasonsList" value="#{bean.seasonsList}" var="season">
<ice:commandButton binding="#{season}"/>
</ice:panelSeries>
</ice:panelGroup>
</p>
And I get this output:
So, being frustrated and adventurous, I tried to render this markup to achieve my goal:
<p>
<ice:panelGroup>
<ice:panelSeries id="seasonsList" value="#{bean.seasonsList}" var="season">
<ice:commandButton id="#{season.id}" partialSubmit="true" style="background-color: #FFFFFF" value="#{season.value}" actionListener="#{bean.updateSeasons}"/>
</ice:panelSeries>
</ice:panelGroup>
</p>
Which yielded the following stacktrace:
Aug 4, 2009 2:28:11 PM com.sun.faces.lifecycle.Phase doPhase
SEVERE: JSF1054: (Phase ID: RENDER_RESPONSE 6, View ID: /phase1.jspx) Exception thrown during phase execution: javax.faces.event.PhaseEvent[source=com.sun.faces.lifecycle.LifecycleImpl#1a477b7]
Aug 4, 2009 2:28:11 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet Persistent Faces Servlet threw exception
java.lang.IllegalArgumentException: #{season.id}
at javax.faces.component.UIComponentBase.validateId(UIComponentBase.java:549)
at javax.faces.component.UIComponentBase.setId(UIComponentBase.java:351)
at javax.faces.webapp.UIComponentTag.createComponent(UIComponentTag.java:219)
at javax.faces.webapp.UIComponentClassicTagBase.createChild(UIComponentClassicTagBase.java:486)
at javax.faces.webapp.UIComponentClassicTagBase.findComponent(UIComponentClassicTagBase.java:670)
at javax.faces.webapp.UIComponentClassicTagBase.doStartTag(UIComponentClassicTagBase.java:1142)
at com.icesoft.faces.component.CommandButtonTag.doStartTag(CommandButtonTag.java:741)
at com.icesoft.faces.webapp.parser.Parser.executeJspLifecycle(Parser.java:204)
at com.icesoft.faces.webapp.parser.Parser.executeJspLifecycle(Parser.java:229)
at com.icesoft.faces.webapp.parser.Parser.executeJspLifecycle(Parser.java:229)
at com.icesoft.faces.webapp.parser.Parser.executeJspLifecycle(Parser.java:229)
at com.icesoft.faces.webapp.parser.Parser.executeJspLifecycle(Parser.java:229)
at com.icesoft.faces.webapp.parser.Parser.executeJspLifecycle(Parser.java:229)
at com.icesoft.faces.webapp.parser.Parser.executeJspLifecycle(Parser.java:229)
at com.icesoft.faces.webapp.parser.Parser.executeJspLifecycle(Parser.java:229)
at com.icesoft.faces.webapp.parser.Parser.executeJspLifecycle(Parser.java:229)
at com.icesoft.faces.webapp.parser.Parser.executeJspLifecycle(Parser.java:229)
at com.icesoft.faces.webapp.parser.Parser.executeJspLifecycle(Parser.java:229)
at com.icesoft.faces.webapp.parser.Parser.executeJspLifecycle(Parser.java:229)
at com.icesoft.faces.webapp.parser.Parser.parse(Parser.java:162)
at com.icesoft.faces.application.D2DViewHandler.renderResponse(D2DViewHandler.java:464)
at com.icesoft.faces.application.D2DViewHandler.renderView(D2DViewHandler.java:153)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at com.icesoft.faces.webapp.http.core.JsfLifecycleExecutor.apply(JsfLifecycleExecutor.java:17)
at com.icesoft.faces.context.View$2$1.respond(View.java:47)
at com.icesoft.faces.webapp.http.servlet.ServletRequestResponse.respondWith(ServletRequestResponse.java:197)
at com.icesoft.faces.webapp.http.servlet.ThreadBlockingAdaptingServlet$ThreadBlockingRequestResponse.respondWith(ThreadBlockingAdaptingServlet.java:36)
at com.icesoft.faces.context.View$2.serve(View.java:72)
at com.icesoft.faces.context.View.servePage(View.java:133)
at com.icesoft.faces.webapp.http.core.SingleViewServer.service(SingleViewServer.java:52)
at com.icesoft.faces.webapp.http.common.ServerProxy.service(ServerProxy.java:11)
at com.icesoft.faces.webapp.http.servlet.MainSessionBoundServlet$4.service(MainSessionBoundServlet.java:114)
at com.icesoft.faces.webapp.http.common.standard.PathDispatcherServer.service(PathDispatcherServer.java:24)
at com.icesoft.faces.webapp.http.servlet.MainSessionBoundServlet.service(MainSessionBoundServlet.java:160)
at com.icesoft.faces.webapp.http.servlet.SessionDispatcher$1.service(SessionDispatcher.java:42)
at com.icesoft.faces.webapp.http.servlet.ThreadBlockingAdaptingServlet.service(ThreadBlockingAdaptingServlet.java:19)
at com.icesoft.faces.webapp.http.servlet.EnvironmentAdaptingServlet.service(EnvironmentAdaptingServlet.java:63)
at com.icesoft.faces.webapp.http.servlet.SessionDispatcher.service(SessionDispatcher.java:62)
at com.icesoft.faces.webapp.http.servlet.PathDispatcher.service(PathDispatcher.java:23)
at com.icesoft.faces.webapp.http.servlet.MainServlet.service(MainServlet.java:153)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Am I trying to do something that I shouldn't be doing?
Is there a better way to accomplish this goal?
If more information is necessary I'd be happy to provide it.
Thanks in advance, my friends.
UPDATE:
So I tried changing the seasonsList collection from List to List and rendering some different markup, like so:
<p>
<ice:panelGroup>
<ice:panelSeries value="#{bean.seasonsList}" var="season">
<ice:commandButton partialSubmit="true" style="background-color: #FFFFFF" value="#{season}" actionListener="#{Phase1EventBean.updateSeasons}"/>
</ice:panelSeries>
</ice:panelGroup>
</p>
And changing the defineSeasonsList() method to:
public void defineNationalSeasonsList()
{
try
{
seasonsList = new ArrayList<String>();
selectedSeasonsList = new ArrayList<String>();
hibernate.openTransaction();
for(UedaNationalDates season:hibernate.getList(new UedaNationalDates(), QueryFactory.getUedaNationalSeasons(hibernate.getHibSession())))
{
nationalSeasonsList.add(season.getSeason());
}
}
catch (Exception e)
{
System.out.println("Error defining nationalMeasurementPeriods: " + e.getMessage());
}
finally
{
hibernate.commitTransaction();
}
}
This actually renders all the buttons I would like to see, and adds them correctly to the selectedSeasonsList in my backing bean when I click on them, and removes them from it when I click again.
However, on the UI, every button appears to be toggled when I click just the one button. For example, when I click on 2009-2010, this is what I see:
<ice:commandButton binding="#{season}"/>
The binding attribute must be bound to a bean property of type UIComponent. It is used where you want the framework to give you a reference to the component in a backing bean or to provide an instance from the backing bean). See section 3.1.5 of the JSF 1.2 spec for more details.
<ice:commandButton id="#{season.id}"
partialSubmit="true"
style="background-color: #FFFFFF"
value="#{season.value}"
actionListener="#{Phase1EventBean.updateSeasons}"/>
The id attribute cannot be dynamic - JSF will take care of ensuring its uniqueness on the client using the clientId (read this for more detail).
EDIT:
However, on the UI, every button appears to be toggled when I click just the one button.
I am guessing that ice:panelSeries does not store the component state of every row as some repeating controls do (e.g. dataTable). Remember, there is only one button instance, even if it is encoded/decoded once per "row".
I've never used ICEfaces, but I suggest binding to beans similar to this:
public class Bean {
private final List<SelectionBean> seasonsList = Arrays.asList(
new SelectionBean("Spring"), new SelectionBean("Summer"),
new SelectionBean("Autumn"), new SelectionBean("Winter"));
public List<SelectionBean> getSeasonsList() { return seasonsList; }
public static class SelectionBean {
private String season;
private boolean selected;
public SelectionBean() {}
public SelectionBean(String season) { this.season = season; }
public String getSeason() { return season; }
public void setSeason(String season) { this.season = season; }
public String toggle() {
System.out.println("toggle " + season);
selected = !selected;
return null;
}
public String getStyle() {
return selected ? "background-color: yellow" : "background-color: blue";
}
}
}
I've pared the logic down to the bare minimum, but hopefully you get how to modify the logic to put the hibernate support back in. Your component would then become something like this:
<ice:panelSeries value="#{bean.seasonsList}" var="item">
<ice:commandButton partialSubmit="true"
style="#{item.style}"
value="#{item.season}"
action="#{item.toggle}"/>
</ice:panelSeries>
So, for each item in your list, all the binding goes back to the one piece of state (a SelectionBean instance) and you don't try to store any non-declarative state on the component itself.
I try to use action over actionListener when I can - it keeps JSF stuff out of the POJOs.