marcel vieira

Greenhorn
+ Follow
since Apr 27, 2011
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
4
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by marcel vieira

Hello.

I want to validate if a user who logged in a webApp is the same one that appears in the DB table record.

When the user logs in the app, I inject (and can use) the session attributes in my manageb bean through the CDI.

The JPA bean (excerpts of code):



The (CDI) Managed bean (excerpts of code):



The constraint class:



The validator class:



The Exception launched:



Can someone help me ?
3 weeks ago
Hi.

I'm using Primefaces.
I have a button to display an edit dialog form with a selectOneMenu that holds prefix number values in it and,
after selecting one of those prefix values, three selectCheckboxMenu are loaded with employees data. This is workinkg fine.

The Listener:

The methods to load the employees lists:

Native queries to retrieve database:

But when editing a register that already has prefix and employee values (saved earlier by some user),
the 3 selectCheckboxMenu are loaded showing (undesired) id's entity class name on its labels value
and empty dropdowns:

e.g.: in the figure above, when the edit form was loaded, it shows the values saved earlier by some user:
- the prefix 9882 (displayed as expected) and
- the three (empty) dropdowns for employees (displayed with the undesired class names in it).
If I select a different value than 9882, the dropdowns are (ajax) filled as expected and if I select 9882 again,
the employees are displayed as expected (without the class names):

I'm trying to resolve it activating the ajax as below, but I don't know how to call it from inside the function:

Does anyone knows how to trigger ajax to load nested dropdowns after loading a form?

Or if someone has any other solution to display the values in the labels (without the class name) and automattically load the nested dropdowns, I appreciate that.

Thanks in advance.
1 year ago
JSF

Robert Liguori wrote:Simply put, I would like to load default filters into a PrimeFaces datatable.


Note that I do change/set the filters in the backing bean, though all my attempts to get the datatable to refresh with the new filters against a (commandButton press) or futile.

--> dataTable.setFilters(filters); // New HashMap < String, Object >

Any suggestions or working code samples to share?  




///////////////////////////////////////////////////////////////////////////






Thanks,
Robert

Reference:
Default filter values for datatable
https://code.google.com/p/primefaces/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Priority%20TargetVersion%20Reporter%20Owner%20Summary&groupby=&sort=&id=3212

How to load a Primefaces datatable with default filters?
http://forum.primefaces.org/viewtopic.php?f=3&t=42553

How is a p:datatable updated from a managed bean?
http://forum.primefaces.org/viewtopic.php?f=3&t=42518

oncomplete="PF('facilityRecordsTable').filter();" not working
http://forum.primefaces.org/viewtopic.php?f=3&t=42517

setting default value in primefaces datatable Filter
https://stackoverflow.com/questions/15450274/setting-default-value-in-primefaces-datatable-filter



Hi.

I know this question have been made a long time ago, but just in case someone is looking for:



Regards.
1 year ago
JSF

Rob Spoor wrote:Do you need to have getTags and setTags as Lists and not as Strings?

The value that's set by the UI is a String (or some other version of CharSequence), and your setTag method only accepts a List. I'd either change the two methods to return/accept String, or overload setTag to also take a String:



Hi Rob!
I already tried to use the way you showed (setting to Strings), but I got the same exception.
Today I saw the https://www.primefaces.org/docs/guide/primefaces_user_guide_6_1.pdf and they gave the example below when using chips component:



Even like these example, I still got the Exception.
In my case, I'm saving the registries in a database and I don't know how to do that.
Please, help.
2 years ago
JSF
Hi everyone!

I have a CRUD and I want to change the inputTexArea to the new Primefaces chips component

The entity class:


When I click on Save, occurs an Exception:

Does anyone knows how can I resolve it ?
Thanks in advance.
2 years ago
JSF
That is the already tested and well working solution provided by http://stackoverflow.com/users/2125446/paul-morris:

4 years ago
JSF

Tim Holloway wrote:IDE code generators are dangerous things. They allow people who don't know what they're doing to create stuff that's limited to just what the generator knows how to do. In the real world, sooner or later someone is going to say, "but could you just add this one small thing...?" and it all goes to perdition. So much for being able to hire cheap untrained monkeys because the IDE generates their code for them.

While we're nitpicking: You - or the code generator - don't write Controllers in JSF. In JSF Controllers are supplied pre-written, pre-debugged as part of JSF itself. Or, for PrimeFaces elements, as part of PrimeFaces. Backing beans are not Controllers, they are Models.

There is a time and a place for an actionListener, but it's so rare that in nearly a decade of working with JSF, I cannot recall any apps I've got that use them. A regular (POJO) action method is far preferable to an actionListener.

The way JSF works is that the View Template (xhtml) is rendered by JSF to produce and present an HTML web page containing one or more HTML FORMs loaded with JSF context data as well as the rendered template controls and the values that those controls reference in the backing bean(s). When a FORM is submitted, it goes through the JSF lifecycle under the control of the JSF Master Controller (FacesServlet), which causes the form data to be validated (and rejected, if invalid), the backing bean property values to be updated (using the sub-Controllers defined by JSF or PrimeFaces for the individual input controls), and then the action method is called from the FacesServlet. You do not move data to/from the Model to the View via user-written (or IDE-generated) logic. As I said, JSF's Controllers do that automatically. That's what Controllers do. Nothing more, nothing less.

The action method is a simple POJO method. It can then invoke any database code it wishes. JSF is not in the database business, so any database logic or constructs are strictly the business of the backing bean, which is a POJO.

In my webapps, there are generally 2 levels of persistence. The high-level persistence that allows me to combine inter-related table objects into a working transaction and the low-level persistence that does table-at-a-time persistence (DAO). The high-level persistence ("service") methods are equivalent to EJB Session EJBs, but I'm commonly using JPA, so that's the closest equivalent.

The actual GUI Model object (backing bean) may or may not contain the business logic in its action methods. For complex apps, I separate out the business logic into a layer of its own between the GUI Model layer and the Persistence Service layer. In that case, the action methods invoke methods in the business layer and there's typically no persistence logic in the backing bean itself.



I really appreciate all the knowledge you shared here, it will help a lot in many other situations.
Thank you so much!
See the solution below.
4 years ago
JSF

Akaine Harga wrote:Ok. I didn't understand you the first time because I did not see two inputs, just one.

The problem you have is related to how JSF works. The command button by default submits only the form it resides in. So to be able to update the "view model" submitting both values, both inputs have to be inside the form where the command button is. Once you have the managed bean's variables updated the rest is trivial. The correct xhtml code would be:


I see you use Primefaces namespace. In this case you can specify the input fields or the wrapper element that contains the input fields you want to submit by specifying the partialSubmit="true" and process="listOfIdsOfTheElementsToSubmit" (http://www.primefaces.org/showcase/ui/ajax/partialSubmit.xhtml). This ca help you minimize the data sent to the server in case you have more input fields in the same form.

On the other hand it sounds pretty strange to me you want to submit a "hardcoded" value in the first place. By looking at your example I can see it comes from the managed bean. Why don't you just use it as a local variable inside the managed bean itself instead of submitting it, since the hardcoded value won't change anyway.

Btw, what are you trying to do in general? Is this some kind of combo field simulation?



I really appreciate all the knowledge you shared here, it will help a lot in many other situations.
Thank you so much!
See the solution below.
4 years ago
JSF
Sorry if it wasn't clear enough for you, but now it will be.

What I want is very simple:
- there is a form. In this form, there is:
- one inputText, for int values (where the user type through the keyboard a number) and
- another one inputText, for string values (where the user won't type anything, becasue it will be already filled with the value "some foo name" as you saw in the code example which I already provided. That's why I said hard coded or manually setted, which means a value entered through the code itself, where I typed it, and not the user. Again, in this inputText, the mentioned string value should be already filled in that field.
- then, after the user types just the int value and see the hard coded string value, the user clicks on the Save button, which will trigger the SaveNew method, then the persist method.
My goal is to store both of those values (the int typed by the user AND the hard coded string) in database.

Now that it is clear enough, can you resolve this problem?

Another thing: I really appreciate your nit-picking observations, but, sorry, it wasn't me who developed it. In fact, I'm using the Netbeans Primefaces CRUD Generator (developed by Kay Wrobel), which uses the JSF Plugin Generator developed by the Netbeans Dream Team. The Generator always worked pretty fine, but now I need to do this modification.

Thanks.
4 years ago
JSF
Hi everyone!

I have a jsf form in which the user type an int and a string value, which are stored in database after clicking on a Save button.



I'm using EJBs with façade pattern, which does the CRUD actions defined in AbstractController class, which uses the AbstractFacade that 'binds' the entity class.

What I need is to <b>hard code/set manually</b> the string value in the form and store it in database along with the int value informed by the user, in the same operation (the same object).

I've tried to do as below, but no success:



I've created a small netbeans project available to be cloned at: https://github.com/f6750699/webAppTest.git

Below, follows 2 methods defined in the AbstractController class:

The <b>saveNew</b> method:



The <b>persist</b> method:



I really appreciate some help with it, because I got stuck on it for a while already.

Thanks in advance.
4 years ago
JSF
I have a Primefaces 4 DataTable with a combobox to filter its values.

How can I proceed to get the dataSet already filtered with one of its comboBox values as the user enters the webApp?

The idea is not to mix dataSet of other dates, which are in the same dataSet, since there is a summary row accordingly to the filtered data.

How can I do it?

The main xhtml code:

The combo method:

Thanks in advance.
5 years ago
JSF
I have 4 Primefaces bar charts which sometimes renders, sometimes not. In one of them, I inject a http user session attribute and use it to render the chart (the idea is to show only the data that corresponds to the (logged in) user department).

There are 4 session beans which I'm using the javax.enterprise.context.RequestScoped. Sometimes, the Glassfish destroys the instance as expected, but sometimes not.

Based on Exception below, how can I resolve it?

Thanks in advance.

The xhtml below shows the main code for only 2 of the 4 bar charts:



The session bean below shows the main code for only 1 of the 4 session bean:



The Exception:

5 years ago
JSF

Tim Holloway wrote:Just a bit of nit-picking. You do not write Controllers in JSF. The primary Controller in JSF is the FacesServlet and the sub-controllers are pre-supplied in the JSF tag implementations. You only code View Templates and Models. Action methods and such within Models are not Controller code (they don't do the Controller's function of transferring values between Model and View), but are instead additional code outside of the MVC domain.

Also, it's bad practice to use underscores in Java names, even though it's legal. The general convention - for better or worse - is camelCase, and some tools may malfunction if they have to deal with unconventional names.

JSF entities are exactly the same thing as J2EE entities, except that JSF automatically constructs them if they don't exist when needed. So you can inject a servlet-created Session object into a Managed Bean, no problem, and no need to rummage around in JSF internal data structures to locate it.

Other than that, my technical term for user-designed login systems is "hacked", based on experience with many, many systems over the years. Most user-designed security is, in fact, so flimsy that an unskilled person can often bypass them in under 15 minutes. J2EE comes with a professionally-designed security subsystem and associated APIs that can repel a lot of attacks before they can even get near the webapp itself. It has been around for probably over 15 years and thus is well-proven. I recommend using it.



Hi Tim.
I really appreciate all your help and nit-picking (although there were some issues I already was aware of; the problem is that this webApp isn't mine and I'm not allowed to modify it right now).

Well, I've been studying this problem since you answered me, so I could try to have a better understanding on how it works, when and where using it etc.

In the Company where I work, I've already asked for a LDAP user bind, so I could use JEE-Security + Glassfish (JAAS, roles/groups etc -> I've followed Josh Juneau book, the JavaEE 7 Recipes, which would fit like a glove for my needs); but they denied me it! I was looking for some way to have a workaround on it, in the way as I could still use those JEE7 benefits (http://stackoverflow.com/questions/17052744/how-to-delegate-access-control-using-glassfish-roles-groups-indirectly). And now, I have to use this "amazing" Login Resource.

So, as I understood, there's a way to inject the servlet-created Session object into a Managed Bean and use its sesison attributes, right? I really tried to do it (see below), but no success.

Please, can you help me ?

(I've "cleared all the codes" to minimize its size and just focus on the problem. If you prefer, the full (Netbeans) project is available for download at: https://github.com/f6750699/navApp.git)

What I've did: created a Managed Bean where, I've injected the servlet that holds the session attributes:

The HttpServlet that holds the session attributes:

In JSF:

The AbstractController<T>:

The IroController:

The AbstractFacade (interacts with JPA):

The IroFacade:

Storing all data informed by the user in the form is fine, except the session attribute - which is null:
javax.el.PropertyNotFoundException: /WEB-INF/include/viagens/viagens/Create.xhtml @51,230 value="#{userBean.userID}": Target Unreachable, identifier 'userBean' resolved to null
5 years ago
JSF
I have to use the company's login resource, which returns a login page for authentication after a browser/user page request; after successfully authenticated, the session attributes are set in a (remote) valued object (VO) invoked via servlet; then, such values are set in my (local) POJO.

I want to display the current user session attribute (see xChave below) and save it in database. How can I persist http User session attributes through the structure below?

Abstract Controller (just the main code):


IroController (just the main code):


JSF:


I'm thinking to inject the iroController in the POJO and set the desired attribute in the init():


Thanks in advance.
5 years ago
JSF
How can I store in database an user Session attribute along with other informations provided in the same form?


I've already tested with disabled="false", too, but only the Session attribute is saved as NULL, though it appears in the form field. The other fields are saved properly.

Thanks in advance.
5 years ago
JSF