JSF :: Get Data From Managed Bean Method After Servlet Filter
Feb 15, 2015
I have a situation to load data while JSF page loads. Also have a filter which populates user information from http request.
I was expecting the filter first to populate the user information and in the managed bean get method to verify the user information and get the data (from database). But in this case i see the managed bean get method is invoked before filter populates user information and i get null pointer exception because the user information is null.
I had to work around to get the user information from FacesContext in the managed bean get method because the user information wasn't available. Is there a way to make sure the filter is invoked first?
View Replies
ADVERTISEMENT
Nov 13, 2014
I have a requirement where in my primefaces datatable ,the filterMatchMode attribute(like any part of field,whole field) needs to be selected by the user by select menu .
To achieve this i have declared a variable in my viewscoped managed bean as filterCriteria and set the filterMatchMode attribute as filterMatchMode="#{beanName.filterCriteria}".The bean variable is getting set in the managed bean on submit but the filtering is not happening,i am getting empty message.
Also when i remove the keyed in value from filter box the data table is not restored which otherwise must be restored in normal situations. I have used and modified the example code given in primefaces showcase here.The code snippet is as below
<h:form id="tblFrm">
<h:selectOneMenu id="filterOptions"
value="#{dtFilterView.filterOption}" required="true"
requiredMessage="You must select an option!">
<f:selectItem id="hd1" itemLabel="Select" itemValue="#{null}" />
[code]....
View Replies
View Related
Jun 5, 2014
I have a JSF bean which is request scope and corresponding JSF UI page. when user tries to open this page, we are getting exception 'Cannot instantiate user.java class <default constructor>'. This does not come always. It comes very rarely. JSF version is 1.2
View Replies
View Related
Jun 11, 2014
About creating views,
1. When we have a view and this uses two or three managed beans and not only one, is this ok? is a good design?
2 If we have two views and both of them only share one functionality (they need to display datatable with clients) , for the second view and for the shared functionality, should I in the managed bean for the second view create the same method that gets the clients or reuse the method in the managed bean created for the first view?
View Replies
View Related
Jan 30, 2014
I am trying to restrict the number of views in JSF 2.0.2 using
<context-param>
<param-name>org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION</param-name>
<param-value>5</param-value>
</context-param>
In my case my managed bean is View Scoped and it supports a UI page which has multiple forms and each form is submitted as AJAX POST request.
As per the statndard, setting restriction to 5 should create 5 views and after that based on LRU algorithm the oldest views should get deleted if 6th views is created.
Therefore any action on the oldest view will throw the ViewExpiredException and i simply redirect the user to view expired page.
1) When i set the restriction to 5 views, i open 4 tabs with 3 forms each.
2) I submit the 3 forms on first tab everything works fine.
3) As soon as I go to 2nd tab and submit the first form thr, i get view expired exception
4) It seems I am exceeding the number of views I mentioned in web.xml
I want to know :
1) Does every AJAX POST submit itself creates a view ?
2) How I can count the number of views created in a session ?
3)Can i force expiry of a view in JSF 2.0.2 while the session is still alive ?
4) Normally JSF 2.0.2 session cachces the views. Lets assume session is alive the entire day but a view was created in morning at 9:00 AM and is not used again the entire day. Assuming that session doesn't reaches the max number of views it can save in entire day, will the view created in morning expire on its own after certain interval of time ? If not , can we still force its expiry while keeping the session alive ?
View Replies
View Related
Jan 10, 2015
I'm using a PrimeFaces UploadedFile xhtml page to select a csv file to read and write using a managed bean (SuperCSVParser.java). The file is read and written to an entity class which then persists the data to a database. The application works fine if I specify a file path on the physical server and select a csv file on that file path. But for the production version I want the user to select ANY file name from ANY directory on their local system.
I know about the FacesContext methods and I've looked at some methods from the java.io File class. Most of these methods are about getting the path from the server, where I want to 'pass' the path String from the client machine to allow the uploaded file to go through. When I try with the below code I get:
java.io.FileNotFoundException: data.csv (The system cannot find the file specified)
I'd like to know what I'm doing as I prefer not to explicitly declare a path in the final app. I'm almost sure that's possible.
<h:form enctype="multipart/form-data">
<p:fileUpload value="#{SuperCsvParser.file}"
mode="simple"
auto="true"
[Code].....
View Replies
View Related
Feb 7, 2014
i want to list files from resources folder like this:
@ManagedBean
public class galley implements Serializable {
private List<String> list;
@PostConstruct
public void init() {
list = new ArrayList<String>();
[Code] ....
but it give me a null pointer exception on fList .... The directory of resources is :
How is this caused and how can I solve it?
View Replies
View Related
May 8, 2014
I read JEE6 doc and confused with : Does container managed entity manager (injected by PersistenceContext annotation) is thread-safe in stateless session bean in multiple-thread env?
See code below, if there are 2 requests to stateless sesion bean in 2 concurrent threads , is it using same Entity Manager Instance or not?
@Stateless(name = "HRFacade", mappedName = "HR_FACES_EJB_JPA-HRFacade-HRFacade")
public class HRFacadeBean implements HRFacade, HRFacadeLocal {
@Resource
SessionContext sessionContext;
@PersistenceContext(unitName = "HRFacade")
private EntityManager em;
[Code] .....
View Replies
View Related
Jul 11, 2014
I have a scenario here where the JSF lifecycle is not getting invoked. I have a filter, whose responsibility is to filter only authorized requests.the code of the filter is given below
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest)request;
HttpServletResponse httpResponse = (HttpServletResponse)response;
[code]....
now in the else block i am filtering the unauthorized requests, and sending them back to the Login.xhtml page of the application.The problem i am encountering here is that, the images and styles associated with the page are not getting loaded, what i am thinking is that when i am using redirect or forward, the FacesServlet is not getting called, and it is directly going to Login page i.e. no Lifecyle is being called.how to Filter the requests and at same time not lose the styles?
View Replies
View Related
Jul 11, 2014
I have a scenario here where the JSF lifecycle is not getting invoked. I have a filter, whose responsibility is to filter only authorized requests. The code of the filter is given below
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest)request;
HttpServletResponse httpResponse = (HttpServletResponse)response;
[Code] ....
Now in the else block I am filtering the unauthorized requests, and sending them back to the Login.xhtml page of the application.
The problem I am encountering here is that, the images and styles associated with the page are not getting loaded, what i am thinking is that when i am using redirect or forward, the FacesServlet is not getting called, and it is directly going to Login page i.e. no Lifecyle is being called.
Am I right on this?, if so how to Filter the requests and at same time not lose the style?
View Replies
View Related
Jul 27, 2014
I am developing a web application using JSF-2.0 on weblogic 10.3.6. I am using Facelets as VDL. I have 5 different machine. They are different according to their OS and their geographical location. On my first xhtml page server (machine) is decided. Then on next page file upload and rest of processing takes place. My restriction is that SSO configuration can be done on only one machine.
So I am restricted to using xhtml files from only my primary server where SSO configuration is done. But I have to connect to servlets or managed-bean of different machine as requests are machine specific and file needs to be uploaded to those machines for processing. So I cannot use redirectUrl as I need to be only on one machine. Is it possible that xhtml on one server can talk to managed-bean on other server(different machine)?.
View Replies
View Related
Dec 1, 2012
Is it possible to get data directly from request object in service method of servlet than why it is not possible to write directly into response object through service method instead of this we have to take PrintWriter or ServletOutputStream class object....
View Replies
View Related
Jun 1, 2014
In stateful session bean client servlet we are explicitly setting shoppingCart to session attribute. I do not remember doing similar step withStatelessSession bean.
request.getSession(true).setAttribute("cart",shoppingCart);
I do have have annotation as well
@EJB
ShoppingCart shoppingCart
View Replies
View Related
Feb 21, 2015
I'm using jsoup to parse a calendar page.
I want to use a switch or if/else statement to filter out the data I don't need for the app. This is by no means anything more than a draft because java is easier to work with than android.
Element table = doc.getElementById("launch_calendar");
Iterator<Element> iterate = table.select("td").iterator();
if(iterate.hasNext()){
for(iterate.hasNext();;){
counter++;
[Code] ....
View Replies
View Related
Jun 13, 2014
Here I am taking response data from JSON using jackson API.I found a feature like using Jackson the properties can be set to bean properties.
private static String readUrl(String urlString) throws Exception {
BufferedReader reader = null;
try {
URL url = new URL(urlString);
reader = new BufferedReader(new InputStreamReader(url.openStream()));
[Code] ....
I got the correct output here. But now I want to generalize my method into a utility class so that I can reuse the same method for setting response data directly to respective beans as given below:-
My question is how will I pass the bean object in my utility class?
public static Object getResponseData(String response,[b]String bean[/b]) throws Exception {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
JsonNode root = mapper.readTree(response);
[Code] ....
View Replies
View Related
Apr 21, 2014
In an JEE6 webprofile project, using JBoss EAP 6.1:
I have a CDI Bean:
import javax.faces.bean.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;
import de.dpunkt.myaktion.model.Organisator;
import de.dpunkt.myaktion.services.OrganisatorDAO;
[code]....
When I call doCreate() I get
javax.servlet.ServletException: javax.ejb.EJBAccessException: JBAS014502: Aufruf an Methode: public abstract void de.dpunkt.myaktion.services.OrganisatorDAO.save(de.dpunkt.myaktion.model.Organisator) von Bean: OrganisatorDAOBean ist nicht gestattet
javax.faces.webapp.FacesServlet.service(FacesServlet.java:606)
which translates to: call of method: .... from Bean ... is not allowed
View Replies
View Related
Feb 23, 2013
I am doing this
@Startup
@Singleton
@ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)
@Lock(LockType.READ)
public class ResourceBean {
[Code] ....
And I call this singleton bean from a stateless session bean like this
@Stateless
public class ClientBean {
@EJB
ResourceBean resource;
public String create(String r)
{
String res=resource.returnString(r);
return res;
}
}
But resource.returnString(r); gives a org.apache.jasper.JasperException: java.lang.NullPointerException I started the glassfish server in debug mode and found out that "resource" was null. but @PostConstruct in singleton does print which means singleton bean exists.
Can we call singleton beans with no interface in such a way form a session bean? I actually want to acquire instance of singleton bean when a client invokes method in Client bean...
View Replies
View Related
Jan 10, 2010
I've got a CDI bean which is a facade for a JPA entity. Such entity has got a many to one relationship with itself and I've got the following method:
public Set<Account> getChildren() {
return this.children;
}
which is called in a JSF/Facelets page:
<h:commandLink action="#{accountController.destroy}" value="#{bundle.ListAccountDestroyLink}" rendered="#{item.children.size() == 0}"/>I then decided to return an unmodifiable set and changed getChildren() accordingly:
public Set<Account> getChildren() {
return Collections.unmodifiableSet(children);
}
The page now reports this error:
java.lang.IllegalAccessException: Class javax.el.BeanELResolver can not access a member of class java.util.Collections$UnmodifiableCollection with modifiers "public"
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
at java.lang.reflect.Method.invoke(Method.java:588)
[Code] ....
javax.el.BeanELResolver is incorrectly failing because it's trying to invoke the size() method using reflection without correctly taking into account the method visibility (which is indeed invokable programmatically). I'm running NetBeans 6.8, Glassfish 3.0 and jdk1.6.0_17.
Is this a bug in BeanELResolver?
View Replies
View Related
Nov 21, 2013
I'm new to JSP but I've to use it to grab data coming from an external site, pass data to a Bean, write data in a DB and redirect the user to another page. Follow the JSP page.
<%@page import="EJB.getResponse"%>
<%
long paymentID = Long.parseLong(request.getParameter("paymentid"));
String responsecode = "9999";
getResponse g = new getResponse();
[Code] ....
This is the bean:
@ManagedBean
@RequestScoped
public class getResponse implements Serializable {
private Long paymentId;
private String result;
private String auth;
[Code] ....
On the console I see the prints but I receive the NullPointerException
WARNING: StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at EJB.getResponse.printData(getResponse.java:72)
at org.apache.jsp.notify_jsp._jspService(notify_jsp.java from :60)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
[Code] ....
View Replies
View Related
Apr 2, 2014
I'm trying to insert data into an excel sheet with the below Servlet.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.beans.Statement;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
[Code] ....
But it is giving me the below Exception and stacktrace
java.text.ParseException: Unparseable date: "2-Apr"
at java.text.DateFormat.parse(DateFormat.java:357)
at Serv1.doPost(Serv1.java:53)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
[Code] ....
i found that the problem is within the date field(, if the problem is with the date, how i can fix it and where am i going wrong.
View Replies
View Related
Jan 22, 2014
I'm trying to share an hashmap(or any other stuff to share data) between a java class and a servlet. The hashmap has to be filled into the servlet with some data and then I have to get those data from the java class.
What is the best approach? I cannot use a DTO because I have several concurrent requests to my servlet.
View Replies
View Related
Dec 16, 2014
How to get a double data type in order to display in the view through a servlet:
objReferencias.setImprevistos(request.("imprevistos"));
Question:
request.getDouble("imprevistos));? or
request.getDoubleParameter("imprevistos));?
I've been searching but I have not found the appropriate answer.
View Replies
View Related
Jan 31, 2013
I'm creating a web applicaion. for that i want to create a registration page. and this registration details have to be stored in the database.
I'm getting the below error while trying to send the data ...
The requested resource (/cmd/InsertRegtodb) is not available.
Here cmd is project name and InsertRegtodb is servlet name.
Actually the servlet is present is the mentioned address. but it is not connecting to it
There is one more servlet in the same folder and which is accessible from another jsp. But this servlet is not accessible even though i have used same code as it is used for the servlet which worked for me previously...
View Replies
View Related
Oct 19, 2014
If I want to load data in excel file into table. what is the best way to do it?
View Replies
View Related
May 13, 2014
I am trying to assess a method which is public from servlet. but it gives weird error. image has been attached .....
View Replies
View Related
Feb 26, 2014
I have the below piece of code in my jsp page.
<% double randomNum= Math.random(); %>
<%= randomNum%>
Now I am trying to run this jsp, it will be translated into servlet. When i checked the generated servlet I found both the above code snippet(scriplet and expression) came in to _jspService method. But in the internet and in many other book i found that scriplet and expression portions will come in the doGet/doPost method (which will be called from jspservice).
So any specific reason why in this case it went in to jspservice method (though I am getting desired output)? I am using tomcat 6.
View Replies
View Related