Problem in displaying data from database in JSF - java

i have a problem when i run a page.jsp :
Exception while calling encodeEnd on component : {Component-Path : [Class: javax.faces.component.UIViewRoot,ViewId: /compteListe.jsp][Class: javax.faces.component.html.HtmlDataTable,Id: j_id_jsp_1879226420_1][Class: javax.faces.component.UIColumn,Id: j_id_jsp_1879226420_2][Class: javax.faces.component.html.HtmlOutputText,Id: j_id_jsp_1879226420_4]}
Caused by:
org.apache.jasper.el.JspPropertyNotFoundException - /compteListe.jsp(29,13) '#{l.Identifiant}' Property 'Identifiant' not found on type com.bankonet.bean.Compte
but when i do System.out.println (rs.getString (1));..., it works well and displays data !!

Unless the property name itself actually starts with 2 uppercased characters, the property name in EL needs to start with lowercase, so:
#{l.identifiant}
This requires a public no-arg getter method with name getIdentifiant().

org.apache.jasper.el.JspPropertyNotFoundException - /compteListe.jsp(29,13) '#{l.Identifiant}' Property 'Identifiant' not found on type com.bankonet.bean.Compte
It searches for a Field with name Identifiant in class com.bankonet.bean.Compte with standard setter/getter methods , which it doesn't find and so the error
but when i do System.out.println (rs.getString (1));..., it works well and displays data !!
It doesn't relate to your problem. You need to pass a collection to view to produce view

Related

Matches below in espresso

Since I have several fields on the registration screen and I use the same string resource for empty fields, how can I get around this error?
com.som.android.acceptanceTests.signIn.RegistrationScreenTest > startRegistrationWithEmptyFields[emu_19_WXGA720(AVD) - 5.0.2] FAILED
android.support.test.espresso.AmbiguousViewMatcherException: '(with id: com.fentury.android:id/errorMessage and with text: is "This field cannot be empty")' matches multiple views in the hierarchy.
Problem views are marked with '****MATCHES****' below.
Here's a great resource for Espresso matchers: https://google.github.io/android-testing-support-library/docs/espresso/cheatsheet/
Looks like you need something along the lines of:
onView(allOf(withId(R.id.errorMessage), withSibling(withId(id for particular input))))
or isDescendantOfA() to if it has a unique container view

NullPointerException when iterating over ArrayList in jsp

I am displaying a list which contains objects which store message information. The list is loaded through getting the request as such:
ArrayList<MessageModel> list = (ArrayList<MessageModel>) request.getAttribute("msgList");
I am trying to display information contained in each object as such:
for(MessageModel msg : list){
String messageTo = msg.toAddress;
String messageSub = msg.messageSubject;
out.println(messageTo+ " " +messageSub);
}
I am getting a NullPointerException at the for each statement.
As an aside, I am using this approach to debug as I want to check whether or not I can display the content of the MessageModel object at all. I tried using JSTL forEach tag but I could not access the object attributes.
<c:forEach items="${list}" var="current">
<li><c:out value="${current.toAddress}"/></li>
</c:forEach>
I set the attribute like this :
ArrayList<MessageModel> list =(ArrayList<MessageModel>) request.getAttribute("msgList");
pageContext.setAttribute("messages", list);
This results in the following error message when run :
org.apache.jasper.JasperException: /inbox.jsp (line: 37, column: 12) According to TLD or attribute directive in tag file, attribute items does not accept any expressions
And intelliJ says that it cannot resolve the variable list.
EDIT :
I forward the request from a servlet that handles user login as follows :
ArrayList<MessageModel> msglist = MessageModel.getRecievedMessages(username);
request.setAttribute("msgList", msglist);
I am trying to pass the ArrayList that contains the message objects and then iterate over the list and display it in the jsp.
Is there a possibility for the jsp itself to get the information ? I have a separate java class which handles the messages with a bunch of helper functions. So can I call the method that retrieves all those messages and display them without explicitly setting a request attribute in the servlet ? Because I will be navigating between other pages in the application.
Sorry if my vocabulary was off, this is the first time I am working with jsp's and servlets.
The NullPointerException in the foreach loop is probably due to the list variable being null. You may check for listnot being null before iterating over it.
Regarding the JasperException, can you describe how you forward to the JSP ?
Also, it's probably a typo, but you set an attribute named messages, then you iterate over an attribute named list in the <c:foreach>...
I solved this problem by using creating getter and setter methods to get the class members of MessageModel.
EL tag wiki: this article helped me understand how to interface a java class and a jsp.

Override error messages in BindingResult

I am using Spring MVC 2.5 .
I have fields where numbers should only be the allowed in put. And I get the exact error message on my UI I was looking for . Something like
Failed to convert property value of type [java.lang.String] to required type [java.math.BigDecimal] for property executionThresholdAmount; nested exception is java.lang.NumberFormatException
I don't want to display that kind of message to the user. I do use message.properties file to organize texts to be displayed.
The only thing I need is I wanted to overwrite the error message for specific fields. I couldn't do that but here is the trick I was using for
if(result.hasFieldErrors()){
List<FieldError> bindingErrors=( List<FieldError>)result.getFieldErrors();
BindingResult fieldErrors=new BeanPropertyBindingResult (offerSetting, "offerSetting");
for(FieldError error :bindingErrors ){
String field=error.getField();
fieldErrors.rejectValue(field, "invalid.amount."+field);
}
result=fieldErrors;
#more code
What I am doing is I created BeanPropertyBindingResult which is an implementation of BindingResult and populated the error fields with the message I want and pass the reference to result object so it gets displayed. However, I am now getting both the default messages
like
Failed to convert property value of type [java.lang.String] to required type [java.math.BigDecimal] for property executionThresholdAmount; nested exception is java.lang.NumberFormatException
and also the message I wanted. Something like
"The amount for field price you entered is invalid"
Any better ideas?
Try adding to your messages properties file somethig like this:
typeMismatch.objectClassName.field=Your custom message
In your case:
typeMismatch.offerSetting.amount=The amount for field price you entered is invalid
Works for me :)

vaadin localization for enums

Im currently working on a project using vaadin.. so far everything is working except for localizing abstract select components (option group ,combobox, dropdowns etc) wherein the select items are from enum types. I used the approach of using Containers:
private Container buildFundTransferTypeContainer() {
Container container = new IndexedContainer();
container.addContainerProperty("label", String.class, "");
container.addContainerProperty("value", FundTransferType.class, null);
for (FundTransferType type : FundTransferType.values()) {
Object id = container.addItem();
container.getContainerProperty(id, "label").setValue(
MessageResource.getLocalizedString(type.name()));
container.getContainerProperty(id, "value").setValue(type);
}
return container;
}
then the field is set by:
fundTransferTypeField.setContainerDataSource(buildFundTransferTypeContainer());
fundTransferTypeField.setItemCaptionPropertyId("label");
so that the property "label" will be used for display. so far this is working in terms of displaying the localized values in the browser, however i get a
com.vaadin.data.Buffered$SourceException
...
Caused by: com.vaadin.data.Buffered$SourceException
at com.vaadin.ui.AbstractField.commit(AbstractField.java:261)
at com.vaadin.ui.Form.commit(Form.java:339)
... 34 more
Caused by: com.vaadin.data.Property$ConversionException: java.lang.NoSuchMethodException: net.novenix.tgsmango.core.enums.FundTransferType.<init>(java.lang.String)
at com.vaadin.data.util.MethodProperty.convertValue(MethodProperty.java:697)
at com.vaadin.data.util.MethodProperty.setValue(MethodProperty.java:666)
at com.vaadin.ui.AbstractField.commit(AbstractField.java:256)
... 35 more
Caused by: java.lang.NoSuchMethodException: com.sample.project.core.enums.FundTransferType.<init>(java.lang.String)
at java.lang.Class.getConstructor0(Class.java:2706)
at java.lang.Class.getConstructor(Class.java:1657)
at com.vaadin.data.util.MethodProperty.convertValue(MethodProperty.java:690)
... 37 more
when the commit is called on the form. How should localized values be handled on these vaadin components. Thanks for the replies
Here is the solution that i used.
on the field factory or when whenever you create the field,
ComboBox accountStatusChoice = new ComboBox();
accountStatusChoice.setCaption(MessageResource.getLocalizedString("caption.accountStatus"));
accountStatusChoice.setRequired(true);
accountStatusChoice.setRequiredError(MessageResource.getLocalizedString("error.required.accountStatus"));
accountStatusChoice.setImmediate(true);
for (AccountStatus accountStatus : AccountStatus.values()) {
accountStatusChoice.addItem(accountStatus);
accountStatusChoice.setItemCaption(accountStatus, MessageResource.getLocalizedString(accountStatus.name()));
}
return accountStatusChoice;
in this code, the MessageResource.getLocalizedString("resourceKey") is my util class to retrieve the localized strings via resource bundle. when adding the contents of the combo box (or whichever abstractSelect component you want to use), use the addItem to add the object value you wish to use, and use the setItemCaption(itemId, captionString) to set the caption visible to the user.
The beanItem that you will use for your form will simply need to have a property of the Enum (in this case a AccountStatus instance variable). when the commit is called in the form, it will no longer throw the com.vaadin.data.Buffered$SourceException.

Bean Validation + Resource Bundle ideas?

Here is what i want to be able to do with bean validation in my JPA entities :
Instead of #NotNull, i would like to do #NotNull(message="keyInMyResourceBundleFile")
I would like also to parameterize the resourceBundle, and i dont know the syntax for it, because it seems to me the message attribute contains only a string.
The parameter itself could be i18n-ed. For example, assuming there's a param attribute for the resourcebundle parameters, in English, #NotNull(message="missing.value", params={"credit card"}) String creditCard; It will be displayed something like this : "Missing required value for field credit card. In Indonesia, it'll be something like "Nilai harus di isi untuk Kartu Kredit. In this example, i cant hardcode the "credit card" because in Indonesia, it's "Kartu Kredit"
Displays the error message defined in the resource bundle on the log file or UI. Im not sure the way on how to do it, should i catch the ConstraintViolationException, get the message, and process the resource bundle by my own code ?
Please share your thoughts on this ?
Thank you !
Regarding 1 + 2
#NotNull(message="{keyInMyResourceBundleFile}")
Curly brackets are the indicator of a parameter substitution
Regarding 3
No idea what you are after. There is no params attribute for #NotNull. I guess you would do
#NotNull(message="{missing.credit.card}")
And of if you place it on another property you would call the key {missing.name}
Regarding 4
The ConstraintViolationException contains the set of *ConstraintViolation*s. Each ConstraintViolation contains the interpolated message as well as the message template. If you want to log it, do it ...

Categories

Resources